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