20
20
21
21
class DiffGeneratorTest extends TestCase
22
22
{
23
- /** @var DBALConfiguration&MockObject */
24
- private DBALConfiguration $ dbalConfiguration ;
23
+ private DBALConfiguration &MockObject $ dbalConfiguration ;
25
24
26
25
/** @var AbstractSchemaManager<AbstractPlatform>&MockObject */
27
- private AbstractSchemaManager $ schemaManager ;
28
-
29
- /** @var SchemaProvider&MockObject */
30
- private SchemaProvider $ schemaProvider ;
31
-
32
- /** @var AbstractPlatform&MockObject */
33
- private AbstractPlatform $ platform ;
34
-
35
- /** @var Generator&MockObject */
36
- private Generator $ migrationGenerator ;
37
-
38
- /** @var SqlGenerator&MockObject */
39
- private SqlGenerator $ migrationSqlGenerator ;
26
+ private AbstractSchemaManager &MockObject $ schemaManager ;
40
27
28
+ private SchemaProvider &MockObject $ schemaProvider ;
29
+ private AbstractPlatform &MockObject $ platform ;
30
+ private Generator &MockObject $ migrationGenerator ;
31
+ private SqlGenerator &MockObject $ migrationSqlGenerator ;
41
32
private DiffGenerator $ migrationDiffGenerator ;
42
-
43
- /** @var SchemaProvider&MockObject */
44
- private SchemaProvider $ emptySchemaProvider ;
33
+ private SchemaProvider &MockObject $ emptySchemaProvider ;
45
34
46
35
public function testGenerate (): void
47
36
{
@@ -89,7 +78,7 @@ public function testGenerate(): void
89
78
90
79
$ toSchema ->expects (self ::exactly (2 ))
91
80
->method ('dropTable ' )
92
- ->willReturnOnConsecutiveCalls ( ' schema.table_name2 ' , ' schema.table_name3 ' );
81
+ ->willReturnSelf ( );
93
82
94
83
$ schemaDiff = self ::createStub (SchemaDiff::class);
95
84
@@ -102,19 +91,7 @@ public function testGenerate(): void
102
91
return ['UPDATE table SET value = 1 ' ];
103
92
});
104
93
105
- // regular mocks cannot be used here, because the method is static
106
- $ comparator = new class extends Comparator {
107
- public static SchemaDiff $ schemaDiff ;
108
-
109
- public static function compareSchemas (
110
- Schema $ fromSchema ,
111
- Schema $ toSchema ,
112
- ): SchemaDiff {
113
- return self ::$ schemaDiff ;
114
- }
115
- };
116
-
117
- $ comparator ::$ schemaDiff = $ schemaDiff ;
94
+ $ comparator = $ this ->mockComparator ($ schemaDiff );
118
95
119
96
$ this ->schemaManager ->expects (self ::once ())
120
97
->method ('createComparator ' )
@@ -151,10 +128,10 @@ public function testGenerateFromEmptySchema(): void
151
128
152
129
$ this ->dbalConfiguration ->expects (self ::once ())
153
130
->method ('getSchemaAssetsFilter ' )
154
- ->willReturn (null );
131
+ ->willReturn (static fn () => true );
155
132
156
- $ toSchema ->expects ( self :: never () )
157
- ->method ( ' getTables ' );
133
+ $ toSchema ->method ( ' getTables ' )
134
+ ->willReturn ([ new Table ( ' table_name ' )] );
158
135
159
136
$ this ->emptySchemaProvider ->expects (self ::once ())
160
137
->method ('createSchema ' )
@@ -181,18 +158,7 @@ public function testGenerateFromEmptySchema(): void
181
158
});
182
159
183
160
// regular mocks cannot be used here, because the method is static
184
- $ comparator = new class extends Comparator {
185
- public static SchemaDiff $ schemaDiff ;
186
-
187
- public static function compareSchemas (
188
- Schema $ fromSchema ,
189
- Schema $ toSchema ,
190
- ): SchemaDiff {
191
- return self ::$ schemaDiff ;
192
- }
193
- };
194
-
195
- $ comparator ::$ schemaDiff = $ schemaDiff ;
161
+ $ comparator = $ this ->mockComparator ($ schemaDiff );
196
162
197
163
$ this ->schemaManager ->expects (self ::once ())
198
164
->method ('createComparator ' )
@@ -233,4 +199,20 @@ protected function setUp(): void
233
199
$ this ->emptySchemaProvider ,
234
200
);
235
201
}
202
+
203
+ private function mockComparator (SchemaDiff $ schemaDiff ): Comparator
204
+ {
205
+ $ comparator = new class (self ::createStub (AbstractPlatform::class)) extends Comparator {
206
+ public static SchemaDiff $ schemaDiff ;
207
+
208
+ public function compareSchemas (Schema $ oldSchema , Schema $ newSchema ): SchemaDiff
209
+ {
210
+ return self ::$ schemaDiff ;
211
+ }
212
+ };
213
+
214
+ $ comparator ::$ schemaDiff = $ schemaDiff ;
215
+
216
+ return $ comparator ;
217
+ }
236
218
}
0 commit comments