function UpsertTest::testDegeneratedSingleValueUpsert
Same name and namespace in other branches
- 11.x core/tests/Drupal/KernelTests/Core/Database/UpsertTest.php \Drupal\KernelTests\Core\Database\UpsertTest::testDegeneratedSingleValueUpsert()
Tests a single-value upsert that has no columns to update.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Database/ UpsertTest.php, line 216
Class
- UpsertTest
- Tests the Upsert query builder.
Namespace
Drupal\KernelTests\Core\DatabaseCode
public function testDegeneratedSingleValueUpsert() : void {
$this->assertSame('1', $this->connection
->query('SELECT COUNT(*) FROM {test_people}')
->fetchField());
// An upsert that only adds a record.
$this->connection
->upsert('test_people')
->key('job')
->fields([
'job',
])
->values([
'Plumber',
])
->execute();
$this->assertSame('2', $this->connection
->query('SELECT COUNT(*) FROM {test_people}')
->fetchField());
// Do the same upsert, should be a no-op.
$this->connection
->upsert('test_people')
->key('job')
->fields([
'job',
])
->values([
'Plumber',
])
->execute();
// No records added.
$this->assertSame('2', $this->connection
->query('SELECT COUNT(*) FROM {test_people}')
->fetchField());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.