You are here

function SelectTest::testInvalidSelectCount in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Database/SelectTest.php \Drupal\system\Tests\Database\SelectTest::testInvalidSelectCount()

Tests that an invalid merge query throws an exception.

File

core/modules/system/src/Tests/Database/SelectTest.php, line 474
Contains \Drupal\system\Tests\Database\SelectTest.

Class

SelectTest
Tests the Select query builder.

Namespace

Drupal\system\Tests\Database

Code

function testInvalidSelectCount() {
  try {

    // This query will fail because the table does not exist.
    // Normally it would throw an exception but we are suppressing
    // it with the throw_exception option.
    $options['throw_exception'] = FALSE;
    db_select('some_table_that_doesnt_exist', 't', $options)
      ->fields('t')
      ->countQuery()
      ->execute();
    $this
      ->pass('$options[\'throw_exception\'] is FALSE, no Exception thrown.');
  } catch (\Exception $e) {
    $this
      ->fail('$options[\'throw_exception\'] is FALSE, but Exception thrown for invalid query.');
    return;
  }
  try {

    // This query will fail because the table does not exist.
    db_select('some_table_that_doesnt_exist', 't')
      ->fields('t')
      ->countQuery()
      ->execute();
  } catch (\Exception $e) {
    $this
      ->pass('Exception thrown for invalid query.');
    return;
  }
  $this
    ->fail('No Exception thrown.');
}