| 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 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |      * @group legacy | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |      * @expectedDeprecation Providing a table name without a schema prefix, i.e. 'some_schema.some_table', (%s given) is deprecated and will cause an error in Doctrine 3.0 | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     public function testListTableFunctions() : void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         $foreignKeys = $this->connection->getSchemaManager()->listTableForeignKeys('test_table'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         $this->assertNotEmpty($foreignKeys); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         $foreignKeys = $this->connection->getSchemaManager()->listTableForeignKeys('test_schema1.test_table'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         $columns     = isset($foreignKeys[0]) ? $foreignKeys[0]->getColumns() : []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         $this->assertContains('test_foreign1_id', $columns); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         $foreignKeys = $this->connection->getSchemaManager()->listTableForeignKeys('test_schema2.test_table'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         $columns     = isset($foreignKeys[0]) ? $foreignKeys[0]->getColumns() : []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |         $this->assertContains('test_foreign2_id', $columns); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         $columns = $this->connection->getSchemaManager()->listTableColumns('test_table'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         $this->assertNotEmpty($columns); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         $columns = $this->connection->getSchemaManager()->listTableColumns('test_schema1.test_table'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         $this->assertArrayHasKey('test_column1', $columns); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         $columns = $this->connection->getSchemaManager()->listTableColumns('test_schema2.test_table'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |         $this->assertArrayHasKey('test_column2', $columns); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |         $indexes = $this->connection->getSchemaManager()->listTableIndexes('test_table'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |         $this->assertNotEmpty($indexes); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |         $indexes = $this->connection->getSchemaManager()->listTableIndexes('test_schema1.test_table'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |         $this->assertArrayHasKey('idx_test_column1', $indexes); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |         $indexes = $this->connection->getSchemaManager()->listTableIndexes('test_schema2.test_table'); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 75 |  |  |         $this->assertArrayHasKey('idx_test_column2', $indexes); | 
            
                                                                        
                                                                
            
                                    
            
            
                | 76 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 77 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 78 |  |  |  |