1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Doctrine\Tests\DBAL\Schema; |
6
|
|
|
|
7
|
|
|
use Doctrine\DBAL\DriverManager; |
8
|
|
|
use Doctrine\DBAL\Platforms\PostgreSqlPlatform; |
9
|
|
|
use Doctrine\Tests\DbalFunctionalTestCase; |
10
|
|
|
use function extension_loaded; |
11
|
|
|
use function in_array; |
12
|
|
|
|
13
|
|
|
class PostgreSqlListTableFunctionsTest extends DbalFunctionalTestCase |
14
|
|
|
{ |
15
|
|
|
protected function setUp() : void |
16
|
|
|
{ |
17
|
|
|
if (! extension_loaded('pdo_pgsql')) { |
18
|
|
|
$this->markTestSkipped('pdo_pgsql is not loaded.'); |
19
|
|
|
|
20
|
|
|
return; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
parent::setUp(); |
24
|
|
|
|
25
|
|
|
if (! in_array('pdo_pgsql', DriverManager::getAvailableDrivers())) { |
26
|
|
|
$this->markTestSkipped('PostgreSQL driver not available'); |
27
|
|
|
|
28
|
|
|
return; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
if (! $this->connection->getDatabasePlatform() instanceof PostgreSqlPlatform) { |
32
|
|
|
$this->markTestSkipped('PostgreSQL Only test.'); |
33
|
|
|
|
34
|
|
|
return; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
$this->connection->executeQuery('CREATE SCHEMA test_schema1;'); |
38
|
|
|
$this->connection->executeQuery('CREATE SCHEMA test_schema2;'); |
39
|
|
|
$this->connection->executeQuery('set search_path = "test_schema1", "test_schema2";'); |
40
|
|
|
$this->connection->executeQuery('CREATE TABLE test_schema1.test_foreign1 ( id integer PRIMARY KEY );'); |
41
|
|
|
$this->connection->executeQuery('CREATE TABLE test_schema1.test_table ( test_column1 varchar(5), test_foreign1_id integer constraint fk_test_foreign1 references test_schema1.test_foreign1 (id) );'); |
42
|
|
|
$this->connection->executeQuery('CREATE INDEX idx_test_column1 ON test_schema1.test_table (test_column1);'); |
43
|
|
|
$this->connection->executeQuery('CREATE TABLE test_schema2.test_foreign2 ( id integer PRIMARY KEY );'); |
44
|
|
|
$this->connection->executeQuery('CREATE TABLE test_schema2.test_table ( test_column2 varchar(5), test_foreign2_id integer constraint fk_test_foreign2 references test_schema2.test_foreign2 (id) );'); |
45
|
|
|
$this->connection->executeQuery('CREATE INDEX idx_test_column2 ON test_schema2.test_table (test_column2);'); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function testListTableFunctions() : void |
49
|
|
|
{ |
50
|
|
|
$foreignKeys = $this->connection->getSchemaManager()->listTableForeignKeys('test_table'); |
51
|
|
|
$this->assertNotEmpty($foreignKeys); |
52
|
|
|
$foreignKeys = $this->connection->getSchemaManager()->listTableForeignKeys('test_schema1.test_table'); |
53
|
|
|
$columns = isset($foreignKeys[0]) ? $foreignKeys[0]->getColumns() : []; |
54
|
|
|
$this->assertContains('test_foreign1_id', $columns); |
55
|
|
|
$foreignKeys = $this->connection->getSchemaManager()->listTableForeignKeys('test_schema2.test_table'); |
56
|
|
|
$columns = isset($foreignKeys[0]) ? $foreignKeys[0]->getColumns() : []; |
57
|
|
|
$this->assertContains('test_foreign2_id', $columns); |
58
|
|
|
|
59
|
|
|
$columns = $this->connection->getSchemaManager()->listTableColumns('test_table'); |
60
|
|
|
$this->assertNotEmpty($columns); |
61
|
|
|
$columns = $this->connection->getSchemaManager()->listTableColumns('test_schema1.test_table'); |
62
|
|
|
$this->assertArrayHasKey('test_column1', $columns); |
63
|
|
|
$columns = $this->connection->getSchemaManager()->listTableColumns('test_schema2.test_table'); |
64
|
|
|
$this->assertArrayHasKey('test_column2', $columns); |
65
|
|
|
|
66
|
|
|
$indexes = $this->connection->getSchemaManager()->listTableIndexes('test_table'); |
67
|
|
|
$this->assertNotEmpty($indexes); |
68
|
|
|
$indexes = $this->connection->getSchemaManager()->listTableIndexes('test_schema1.test_table'); |
69
|
|
|
$this->assertArrayHasKey('idx_test_column1', $indexes); |
70
|
|
|
$indexes = $this->connection->getSchemaManager()->listTableIndexes('test_schema2.test_table'); |
71
|
|
|
$this->assertArrayHasKey('idx_test_column2', $indexes); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|