| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Doctrine\Tests\DBAL\Schema\Visitor; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Doctrine\DBAL\Platforms\AbstractPlatform; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Doctrine\DBAL\Schema\ForeignKeyConstraint; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Doctrine\DBAL\Schema\Table; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Doctrine\DBAL\Schema\Visitor\DropSchemaSqlCollector; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use PHPUnit\Framework\TestCase; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * @covers \Doctrine\DBAL\Schema\Visitor\DropSchemaSqlCollector | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | class DropSchemaSqlCollectorTest extends TestCase | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     public function testGetQueriesUsesAcceptedForeignKeys() : void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |         $tableOne = $this->createMock(Table::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |         $tableTwo = $this->createMock(Table::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |         $keyConstraintOne = $this->getStubKeyConstraint('first'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |         $keyConstraintTwo = $this->getStubKeyConstraint('second'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |         $platform = $this->getMockBuilder(AbstractPlatform::class) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |             ->setMethods(['getDropForeignKeySQL']) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |             ->getMockForAbstractClass(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |         $collector = new DropSchemaSqlCollector($platform); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |         $platform->expects($this->exactly(2)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |             ->method('getDropForeignKeySQL'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |         $platform->expects($this->at(0)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |             ->method('getDropForeignKeySQL') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |             ->with($keyConstraintOne, $tableOne); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         $platform->expects($this->at(1)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |             ->method('getDropForeignKeySQL') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |             ->with($keyConstraintTwo, $tableTwo); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         $collector->acceptForeignKey($tableOne, $keyConstraintOne); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         $collector->acceptForeignKey($tableTwo, $keyConstraintTwo); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         $collector->getQueries(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 47 |  |  |     private function getStubKeyConstraint(string $name) : ForeignKeyConstraint | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |         $constraint = $this->createMock(ForeignKeyConstraint::class); | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         $constraint->expects($this->any()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |             ->method('getName') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |             ->will($this->returnValue($name)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         $constraint->expects($this->any()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |             ->method('getForeignColumns') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |             ->will($this->returnValue([])); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         $constraint->expects($this->any()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |             ->method('getColumns') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |             ->will($this->returnValue([])); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         return $constraint; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 65 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 66 |  |  |  |