Total Complexity | 13 |
Total Lines | 169 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
14 | class CreateSchemaSqlCollectorTest extends TestCase |
||
15 | { |
||
16 | /** @var AbstractPlatform|PHPUnit_Framework_MockObject_MockObject */ |
||
|
|||
17 | private $platformMock; |
||
18 | |||
19 | /** @var CreateSchemaSqlCollector */ |
||
20 | private $visitor; |
||
21 | |||
22 | /** |
||
23 | * {@inheritdoc} |
||
24 | */ |
||
25 | protected function setUp() |
||
26 | { |
||
27 | parent::setUp(); |
||
28 | |||
29 | $this->platformMock = $this->getMockBuilder(AbstractPlatform::class) |
||
1 ignored issue
–
show
|
|||
30 | ->setMethods( |
||
31 | [ |
||
32 | 'getCreateForeignKeySQL', |
||
33 | 'getCreateSchemaSQL', |
||
34 | 'getCreateSequenceSQL', |
||
35 | 'getCreateTableSQL', |
||
36 | 'supportsForeignKeyConstraints', |
||
37 | 'getCreateViewSQL', |
||
38 | 'supportsSchemas', |
||
39 | ] |
||
40 | ) |
||
41 | ->getMockForAbstractClass(); |
||
42 | $this->visitor = new CreateSchemaSqlCollector($this->platformMock); |
||
43 | |||
44 | foreach (['getCreateSchemaSQL', 'getCreateTableSQL', 'getCreateForeignKeySQL', 'getCreateSequenceSQL', 'getCreateViewSQL'] as $method) { |
||
45 | $this->platformMock->expects($this->any()) |
||
46 | ->method($method) |
||
47 | ->will($this->returnValue('foo')); |
||
48 | } |
||
49 | } |
||
50 | |||
51 | public function testAcceptsNamespace() |
||
52 | { |
||
53 | $this->platformMock->expects($this->at(0)) |
||
54 | ->method('supportsSchemas') |
||
55 | ->will($this->returnValue(false)); |
||
56 | |||
57 | $this->platformMock->expects($this->at(1)) |
||
58 | ->method('supportsSchemas') |
||
59 | ->will($this->returnValue(true)); |
||
60 | |||
61 | $this->visitor->acceptNamespace('foo'); |
||
62 | |||
63 | self::assertEmpty($this->visitor->getQueries()); |
||
64 | |||
65 | $this->visitor->acceptNamespace('foo'); |
||
66 | |||
67 | self::assertSame(['foo'], $this->visitor->getQueries()); |
||
68 | } |
||
69 | |||
70 | public function testAcceptsTable() |
||
71 | { |
||
72 | $table = $this->createTableMock(); |
||
73 | |||
74 | $this->visitor->acceptTable($table); |
||
75 | |||
76 | self::assertSame(['foo'], $this->visitor->getQueries()); |
||
77 | } |
||
78 | |||
79 | public function testAcceptsForeignKey() |
||
80 | { |
||
81 | $this->platformMock->expects($this->at(0)) |
||
82 | ->method('supportsForeignKeyConstraints') |
||
83 | ->will($this->returnValue(false)); |
||
84 | |||
85 | $this->platformMock->expects($this->at(1)) |
||
86 | ->method('supportsForeignKeyConstraints') |
||
87 | ->will($this->returnValue(true)); |
||
88 | |||
89 | $table = $this->createTableMock(); |
||
90 | $foreignKey = $this->createForeignKeyConstraintMock(); |
||
91 | |||
92 | $this->visitor->acceptForeignKey($table, $foreignKey); |
||
93 | |||
94 | self::assertEmpty($this->visitor->getQueries()); |
||
95 | |||
96 | $this->visitor->acceptForeignKey($table, $foreignKey); |
||
97 | |||
98 | self::assertSame(['foo'], $this->visitor->getQueries()); |
||
99 | } |
||
100 | |||
101 | public function testAcceptsSequences() |
||
102 | { |
||
103 | $sequence = $this->createSequenceMock(); |
||
104 | |||
105 | $this->visitor->acceptSequence($sequence); |
||
106 | |||
107 | self::assertSame(['foo'], $this->visitor->getQueries()); |
||
108 | } |
||
109 | |||
110 | public function testAcceptsView() |
||
111 | { |
||
112 | $view = $this->createViewMock(); |
||
113 | |||
114 | $this->visitor->acceptView($view); |
||
115 | |||
116 | $this->assertSame(['foo'], $this->visitor->getQueries()); |
||
117 | } |
||
118 | |||
119 | public function testResetsQueries() |
||
120 | { |
||
121 | foreach (['supportsSchemas', 'supportsForeignKeyConstraints'] as $method) { |
||
122 | $this->platformMock->expects($this->any()) |
||
123 | ->method($method) |
||
124 | ->will($this->returnValue(true)); |
||
125 | } |
||
126 | |||
127 | $table = $this->createTableMock(); |
||
128 | $foreignKey = $this->createForeignKeyConstraintMock(); |
||
129 | $sequence = $this->createSequenceMock(); |
||
130 | $view = $this->createViewMock(); |
||
131 | |||
132 | $this->visitor->acceptNamespace('foo'); |
||
133 | $this->visitor->acceptTable($table); |
||
134 | $this->visitor->acceptForeignKey($table, $foreignKey); |
||
135 | $this->visitor->acceptSequence($sequence); |
||
136 | $this->visitor->acceptView($view); |
||
137 | |||
138 | self::assertNotEmpty($this->visitor->getQueries()); |
||
139 | |||
140 | $this->visitor->resetQueries(); |
||
141 | |||
142 | self::assertEmpty($this->visitor->getQueries()); |
||
143 | } |
||
144 | |||
145 | /** |
||
146 | * @return ForeignKeyConstraint|PHPUnit_Framework_MockObject_MockObject |
||
147 | */ |
||
148 | private function createForeignKeyConstraintMock() |
||
149 | { |
||
150 | return $this->getMockBuilder(ForeignKeyConstraint::class) |
||
1 ignored issue
–
show
|
|||
151 | ->disableOriginalConstructor() |
||
152 | ->getMock(); |
||
153 | } |
||
154 | |||
155 | /** |
||
156 | * @return Sequence|PHPUnit_Framework_MockObject_MockObject |
||
157 | */ |
||
158 | private function createSequenceMock() |
||
159 | { |
||
160 | return $this->getMockBuilder(Sequence::class) |
||
1 ignored issue
–
show
|
|||
161 | ->disableOriginalConstructor() |
||
162 | ->getMock(); |
||
163 | } |
||
164 | |||
165 | /** |
||
166 | * @return Table|PHPUnit_Framework_MockObject_MockObject |
||
167 | */ |
||
168 | private function createTableMock() |
||
173 | } |
||
174 | |||
175 | /** |
||
176 | * @return View|MockObject |
||
177 | */ |
||
178 | private function createViewMock() |
||
179 | { |
||
180 | return $this->getMockBuilder('Doctrine\DBAL\Schema\View') |
||
181 | ->disableOriginalConstructor() |
||
182 | ->getMock(); |
||
185 |