function MergeTest::testMergeMatchedWithoutUpdate

Tests a merge that matches a row but has nothing to update.

File

core/modules/pgsql/tests/src/Kernel/pgsql/MergeTest.php, line 91

Class

MergeTest
Tests the native MERGE implementation of the PostgreSQL driver.

Namespace

Drupal\Tests\pgsql\Kernel\pgsql

Code

public function testMergeMatchedWithoutUpdate() : void {
  $result = FALSE;
  $queries = $this->getLoggedQueries(function () use (&$result) {
    $result = $this->connection
      ->merge('test_people')
      ->key('job', 'Speaker')
      ->execute();
  });
  // Without update fields the MERGE has no WHEN MATCHED clause, so no
  // action is performed and no status is returned.
  $this->assertNull($result);
  $this->assertCount(1, $queries);
  $this->assertStringContainsString('MERGE INTO', $queries[0]);
  $person = $this->connection
    ->query('SELECT * FROM {test_people} WHERE [job] = :job', [
    ':job' => 'Speaker',
  ])
    ->fetch();
  $this->assertEquals('Meredith', $person->name);
  $this->assertEquals(30, $person->age);
}

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