function NonPublicSchemaTest::testPrimaryKey

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

@covers ::addPrimaryKey @covers ::dropPrimaryKey

File

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

Class

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

Namespace

Drupal\Tests\pgsql\Kernel\pgsql

Code

public function testPrimaryKey() : void {
    $this->testingFakeConnection
        ->schema()
        ->dropPrimaryKey('faking_table');
    $results = $this->testingFakeConnection
        ->query("SELECT * FROM pg_indexes WHERE schemaname = 'testing_fake'")
        ->fetchAll();
    $this->assertCount(0, $results);
    $this->testingFakeConnection
        ->schema()
        ->addPrimaryKey('faking_table', [
        'id',
    ]);
    $results = $this->testingFakeConnection
        ->query("SELECT * FROM pg_indexes WHERE schemaname = 'testing_fake'")
        ->fetchAll();
    $this->assertCount(1, $results);
    $this->assertSame('testing_fake', $results[0]->schemaname);
    $this->assertSame($this->testingFakeConnection
        ->getPrefix() . 'faking_table', $results[0]->tablename);
    $this->assertStringContainsString('USING btree (id)', $results[0]->indexdef);
    $find_primary_keys_columns = new \ReflectionMethod(get_class($this->testingFakeConnection
        ->schema()), 'findPrimaryKeyColumns');
    $results = $find_primary_keys_columns->invoke($this->testingFakeConnection
        ->schema(), 'faking_table');
    $this->assertCount(1, $results);
    $this->assertSame('id', $results[0]);
}

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