public function MergeTest::testMergeInsertWithoutUpdate in Drupal 8
Same name and namespace in other branches
- 9 core/tests/Drupal/KernelTests/Core/Database/MergeTest.php \Drupal\KernelTests\Core\Database\MergeTest::testMergeInsertWithoutUpdate()
Tests that we can merge-insert without any update fields.
File
- core/
tests/ Drupal/ KernelTests/ Core/ Database/ MergeTest.php, line 147
Class
- MergeTest
- Tests the MERGE query builder.
Namespace
Drupal\KernelTests\Core\DatabaseCode
public function testMergeInsertWithoutUpdate() {
$num_records_before = $this->connection
->query('SELECT COUNT(*) FROM {test_people}')
->fetchField();
$this->connection
->merge('test_people')
->key('job', 'Presenter')
->execute();
$num_records_after = $this->connection
->query('SELECT COUNT(*) FROM {test_people}')
->fetchField();
$this
->assertEqual($num_records_before + 1, $num_records_after, 'Merge inserted properly.');
$person = $this->connection
->query('SELECT * FROM {test_people} WHERE job = :job', [
':job' => 'Presenter',
])
->fetch();
$this
->assertEqual($person->name, '', 'Name set correctly.');
$this
->assertEqual($person->age, 0, 'Age set correctly.');
$this
->assertEqual($person->job, 'Presenter', 'Job set correctly.');
}