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\SchemaException; |
8
|
|
|
use Doctrine\DBAL\Schema\Table; |
9
|
|
|
use Doctrine\DBAL\Schema\Visitor\DropSchemaSqlCollector; |
10
|
|
|
use PHPUnit\Framework\TestCase; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @covers Doctrine\DBAL\Schema\Visitor\DropSchemaSqlCollector |
14
|
|
|
*/ |
15
|
|
|
class DropSchemaSqlCollectorTest extends TestCase |
16
|
|
|
{ |
17
|
|
|
public function testGetQueriesUsesAcceptedForeignKeys() |
18
|
|
|
{ |
19
|
|
|
$tableOne = $this->getTableMock(); |
20
|
|
|
$tableTwo = $this->getTableMock(); |
21
|
|
|
|
22
|
|
|
$keyConstraintOne = $this->getStubKeyConstraint('first'); |
23
|
|
|
$keyConstraintTwo = $this->getStubKeyConstraint('second'); |
24
|
|
|
|
25
|
|
|
$platform = $this->getMockBuilder(AbstractPlatform::class) |
26
|
|
|
->setMethods(['getDropForeignKeySQL']) |
27
|
|
|
->getMockForAbstractClass(); |
28
|
|
|
|
29
|
|
|
$collector = new DropSchemaSqlCollector($platform); |
30
|
|
|
|
31
|
|
|
$platform->expects($this->exactly(2)) |
32
|
|
|
->method('getDropForeignKeySQL'); |
33
|
|
|
|
34
|
|
|
$platform->expects($this->at(0)) |
35
|
|
|
->method('getDropForeignKeySQL') |
36
|
|
|
->with($keyConstraintOne, $tableOne); |
37
|
|
|
|
38
|
|
|
$platform->expects($this->at(1)) |
39
|
|
|
->method('getDropForeignKeySQL') |
40
|
|
|
->with($keyConstraintTwo, $tableTwo); |
41
|
|
|
|
42
|
|
|
$collector->acceptForeignKey($tableOne, $keyConstraintOne); |
43
|
|
|
$collector->acceptForeignKey($tableTwo, $keyConstraintTwo); |
44
|
|
|
|
45
|
|
|
$collector->getQueries(); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
private function getTableMock() |
49
|
|
|
{ |
50
|
|
|
return $this->getMockWithoutArguments(Table::class); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
private function getMockWithoutArguments($className) |
54
|
|
|
{ |
55
|
|
|
return $this->getMockBuilder($className)->disableOriginalConstructor()->getMock(); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
private function getStubKeyConstraint($name) |
59
|
|
|
{ |
60
|
|
|
$constraint = $this->getMockWithoutArguments(ForeignKeyConstraint::class); |
61
|
|
|
|
62
|
|
|
$constraint->expects($this->any()) |
63
|
|
|
->method('getName') |
64
|
|
|
->will($this->returnValue($name)); |
65
|
|
|
|
66
|
|
|
$constraint->expects($this->any()) |
67
|
|
|
->method('getForeignColumns') |
68
|
|
|
->will($this->returnValue([])); |
69
|
|
|
|
70
|
|
|
$constraint->expects($this->any()) |
71
|
|
|
->method('getColumns') |
72
|
|
|
->will($this->returnValue([])); |
73
|
|
|
|
74
|
|
|
return $constraint; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function testGivenForeignKeyWithZeroLengthAcceptForeignKeyThrowsException() |
78
|
|
|
{ |
79
|
|
|
$collector = new DropSchemaSqlCollector( |
80
|
|
|
$this->getMockForAbstractClass(AbstractPlatform::class) |
81
|
|
|
); |
82
|
|
|
|
83
|
|
|
$this->expectException(SchemaException::class); |
84
|
|
|
$collector->acceptForeignKey($this->getTableMock(), $this->getStubKeyConstraint('')); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|