function MergeTest::testMergeUpdateWithoutUpdate
Same name in other branches
- 9 core/tests/Drupal/KernelTests/Core/Database/MergeTest.php \Drupal\KernelTests\Core\Database\MergeTest::testMergeUpdateWithoutUpdate()
- 10 core/tests/Drupal/KernelTests/Core/Database/MergeTest.php \Drupal\KernelTests\Core\Database\MergeTest::testMergeUpdateWithoutUpdate()
- 11.x core/tests/Drupal/KernelTests/Core/Database/MergeTest.php \Drupal\KernelTests\Core\Database\MergeTest::testMergeUpdateWithoutUpdate()
Confirms that we can merge-update without any update fields.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Database/ MergeTest.php, line 166
Class
- MergeTest
- Tests the MERGE query builder.
Namespace
Drupal\KernelTests\Core\DatabaseCode
public function testMergeUpdateWithoutUpdate() {
$num_records_before = $this->connection
->query('SELECT COUNT(*) FROM {test_people}')
->fetchField();
$this->connection
->merge('test_people')
->key('job', 'Speaker')
->execute();
$num_records_after = $this->connection
->query('SELECT COUNT(*) FROM {test_people}')
->fetchField();
$this->assertEqual($num_records_before, $num_records_after, 'Merge skipped properly.');
$person = $this->connection
->query('SELECT * FROM {test_people} WHERE job = :job', [
':job' => 'Speaker',
])
->fetch();
$this->assertEqual($person->name, 'Meredith', 'Name skipped correctly.');
$this->assertEqual($person->age, 30, 'Age skipped correctly.');
$this->assertEqual($person->job, 'Speaker', 'Job skipped correctly.');
$this->connection
->merge('test_people')
->key('job', 'Speaker')
->insertFields([
'age' => 31,
])
->execute();
$num_records_after = $this->connection
->query('SELECT COUNT(*) FROM {test_people}')
->fetchField();
$this->assertEqual($num_records_before, $num_records_after, 'Merge skipped properly.');
$person = $this->connection
->query('SELECT * FROM {test_people} WHERE job = :job', [
':job' => 'Speaker',
])
->fetch();
$this->assertEqual($person->name, 'Meredith', 'Name skipped correctly.');
$this->assertEqual($person->age, 30, 'Age skipped correctly.');
$this->assertEqual($person->job, 'Speaker', 'Job skipped correctly.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.