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() : void |
18
|
|
|
{ |
19
|
|
|
$tableOne = $this->createMock(Table::class); |
20
|
|
|
$tableTwo = $this->createMock(Table::class); |
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 getStubKeyConstraint(string $name) : ForeignKeyConstraint |
49
|
|
|
{ |
50
|
|
|
$constraint = $this->createMock(ForeignKeyConstraint::class); |
51
|
|
|
|
52
|
|
|
$constraint->expects($this->any()) |
53
|
|
|
->method('getName') |
54
|
|
|
->will($this->returnValue($name)); |
55
|
|
|
|
56
|
|
|
$constraint->expects($this->any()) |
57
|
|
|
->method('getForeignColumns') |
58
|
|
|
->will($this->returnValue([])); |
59
|
|
|
|
60
|
|
|
$constraint->expects($this->any()) |
61
|
|
|
->method('getColumns') |
62
|
|
|
->will($this->returnValue([])); |
63
|
|
|
|
64
|
|
|
return $constraint; |
|
|
|
|
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function testGivenForeignKeyWithZeroLengthAcceptForeignKeyThrowsException() : void |
68
|
|
|
{ |
69
|
|
|
$collector = new DropSchemaSqlCollector( |
70
|
|
|
$this->getMockForAbstractClass(AbstractPlatform::class) |
71
|
|
|
); |
72
|
|
|
|
73
|
|
|
$this->expectException(SchemaException::class); |
74
|
|
|
$collector->acceptForeignKey( |
75
|
|
|
$this->createMock(Table::class), |
76
|
|
|
$this->getStubKeyConstraint('') |
77
|
|
|
); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|