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