function MergeTest::testMergeWithReservedWords

Same name in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Database/MergeTest.php \Drupal\KernelTests\Core\Database\MergeTest::testMergeWithReservedWords()
  2. 10 core/tests/Drupal/KernelTests/Core/Database/MergeTest.php \Drupal\KernelTests\Core\Database\MergeTest::testMergeWithReservedWords()

Tests that we can merge-insert with reserved keywords.

File

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

Class

MergeTest
Tests the MERGE query builder.

Namespace

Drupal\KernelTests\Core\Database

Code

public function testMergeWithReservedWords() : void {
    $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);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.