function MergeTest::testMergeSerialFieldFallback
Tests that inserting into a serial field uses the generic emulation.
File
-
core/
modules/ pgsql/ tests/ src/ Kernel/ pgsql/ MergeTest.php, line 182
Class
- MergeTest
- Tests the native MERGE implementation of the PostgreSQL driver.
Namespace
Drupal\Tests\pgsql\Kernel\pgsqlCode
public function testMergeSerialFieldFallback() : void {
$result = NULL;
$queries = $this->getLoggedQueries(function () use (&$result) {
$result = $this->connection
->merge('test')
->key('id', 999)
->fields([
'name' => 'David',
'age' => 40,
'job' => 'Developer',
])
->execute();
});
$this->assertSame(Merge::STATUS_INSERT, $result);
// The generic emulation issues a SELECT followed by an INSERT.
$this->assertGreaterThan(1, count($queries));
foreach ($queries as $query) {
$this->assertStringNotContainsString('MERGE INTO', $query);
}
// The insert path of the generic emulation has synchronized the sequence
// of the serial field, so a regular insert does not collide with the
// explicitly inserted id.
$id = $this->connection
->insert('test')
->fields([
'name' => 'Sylvia',
'age' => 41,
'job' => 'Editor',
])
->execute();
$this->assertEquals(1000, $id);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.