function NonPublicSchemaTest::testMerge

Same name in other branches
  1. 10 core/modules/pgsql/tests/src/Kernel/pgsql/NonPublicSchemaTest.php \Drupal\Tests\pgsql\Kernel\pgsql\NonPublicSchemaTest::testMerge()

@covers \Drupal\Core\Database\Connection::merge

File

core/modules/pgsql/tests/src/Kernel/pgsql/NonPublicSchemaTest.php, line 224

Class

NonPublicSchemaTest
Tests schema API for non-public schema for the PostgreSQL driver.

Namespace

Drupal\Tests\pgsql\Kernel\pgsql

Code

public function testMerge() : void {
    $num_records_before = $this->testingFakeConnection
        ->query('SELECT COUNT(*) FROM {faking_table}')
        ->fetchField();
    $this->testingFakeConnection
        ->merge('faking_table')
        ->key('id', '789')
        ->fields([
        'test_field' => 343,
    ])
        ->execute();
    $num_records_after = $this->testingFakeConnection
        ->query('SELECT COUNT(*) FROM {faking_table}')
        ->fetchField();
    $this->assertEquals($num_records_before + 1, $num_records_after, 'Merge inserted properly.');
    $merge_results = $this->testingFakeConnection
        ->select('faking_table')
        ->fields('faking_table')
        ->condition('id', '789')
        ->execute()
        ->fetchAll();
    $this->assertSame('789', $merge_results[0]->id);
    $this->assertSame('343', $merge_results[0]->test_field);
}

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