/**
* @covers ::addPrimaryKey
* @covers ::dropPrimaryKey
*/
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);