You are here

function MergeTest::testInvalidMerge in Zircon Profile 8

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

Tests that an invalid merge query throws an exception.

File

core/modules/system/src/Tests/Database/MergeTest.php, line 203
Contains \Drupal\system\Tests\Database\MergeTest.

Class

MergeTest
Tests the MERGE query builder.

Namespace

Drupal\system\Tests\Database

Code

function testInvalidMerge() {
  try {

    // This query will fail because there is no key field specified.
    // Normally it would throw an exception but we are suppressing it with
    // the throw_exception option.
    $options['throw_exception'] = FALSE;
    db_merge('test_people', $options)
      ->fields(array(
      'age' => 31,
      'name' => 'Tiffany',
    ))
      ->execute();
    $this
      ->pass('$options[\'throw_exception\'] is FALSE, no InvalidMergeQueryException thrown.');
  } catch (InvalidMergeQueryException $e) {
    $this
      ->fail('$options[\'throw_exception\'] is FALSE, but InvalidMergeQueryException thrown for invalid query.');
    return;
  }
  try {

    // This query will fail because there is no key field specified.
    db_merge('test_people')
      ->fields(array(
      'age' => 31,
      'name' => 'Tiffany',
    ))
      ->execute();
  } catch (InvalidMergeQueryException $e) {
    $this
      ->pass('InvalidMergeQueryException thrown for invalid query.');
    return;
  }
  $this
    ->fail('No InvalidMergeQueryException thrown');
}