You are here

public function MergeTest::testMergeWithReservedWords in Drupal 9

Tests that we can merge-insert with reserved keywords.

File

core/tests/Drupal/KernelTests/Core/Database/MergeTest.php, line 225

Class

MergeTest
Tests the MERGE query builder.

Namespace

Drupal\KernelTests\Core\Database

Code

public function testMergeWithReservedWords() {
  $num_records_before = $this->connection
    ->query('SELECT COUNT(*) FROM {select}')
    ->fetchField();
  $this->connection
    ->merge('select')
    ->key('id', 2)
    ->execute();
  $num_records_after = $this->connection
    ->query('SELECT COUNT(*) FROM {select}')
    ->fetchField();
  $this
    ->assertEquals($num_records_before + 1, $num_records_after, 'Merge inserted properly.');
  $person = $this->connection
    ->query('SELECT * FROM {select} WHERE [id] = :id', [
    ':id' => 2,
  ])
    ->fetch();
  $this
    ->assertEquals('', $person->update);
  $this
    ->assertEquals('2', $person->id);
}