@@ -266,9 +266,56 @@ private function createTimestampColumn($name, Table $table)
266
266
* @param array $references
267
267
* @param array $constraints
268
268
* @param array $indexes
269
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
270
269
*/
271
270
public function testBuild (array $ columns , array $ references , array $ constraints , array $ indexes )
271
+ {
272
+ $ this ->prepareSchemaMocks ($ columns , $ references , $ constraints , $ indexes );
273
+ $ resourceConnectionMock = $ this ->getMockBuilder (ResourceConnection::class)
274
+ ->disableOriginalConstructor ()
275
+ ->getMock ();
276
+ /** @var Schema $schema */
277
+ $ schema = $ this ->objectManagerHelper ->getObject (
278
+ Schema::class,
279
+ ['resourceConnection ' => $ resourceConnectionMock ]
280
+ );
281
+ $ this ->model ->build ($ schema );
282
+ }
283
+
284
+ /**
285
+ * @dataProvider dataProvider
286
+ * @param array $columns
287
+ * @param array $references
288
+ * @param array $constraints
289
+ * @param array $indexes
290
+ * @expectedException \PHPUnit\Framework\Exception
291
+ * @expectedExceptionMessage
292
+ * User Warning: Column unknown_column does not exist for index/constraint FIRST_INDEX in table second_table
293
+ */
294
+ public function testBuildUnknownIndexColumn (array $ columns , array $ references , array $ constraints , array $ indexes )
295
+ {
296
+ $ indexes ['second_table ' ]['FIRST_INDEX ' ]['column ' ][] = 'unknown_column ' ;
297
+ $ this ->prepareSchemaMocks ($ columns , $ references , $ constraints , $ indexes );
298
+ $ resourceConnectionMock = $ this ->getMockBuilder (ResourceConnection::class)
299
+ ->disableOriginalConstructor ()
300
+ ->getMock ();
301
+ /** @var Schema $schema */
302
+ $ schema = $ this ->objectManagerHelper ->getObject (
303
+ Schema::class,
304
+ ['resourceConnection ' => $ resourceConnectionMock ]
305
+ );
306
+ $ this ->model ->build ($ schema );
307
+ }
308
+
309
+ /**
310
+ * Prepare mocks for test.
311
+ *
312
+ * @param array $columns
313
+ * @param array $references
314
+ * @param array $constraints
315
+ * @param array $indexes
316
+ * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
317
+ */
318
+ private function prepareSchemaMocks (array $ columns , array $ references , array $ constraints , array $ indexes )
272
319
{
273
320
$ withContext = [['first_table ' , 'default ' ], ['second_table ' , 'default ' ]];
274
321
$ this ->shardingMock ->expects (self ::once ())
@@ -278,26 +325,26 @@ public function testBuild(array $columns, array $references, array $constraints,
278
325
->method ('readTables ' )
279
326
->with ('default ' )
280
327
->willReturn (['first_table ' , 'second_table ' ]);
281
- $ this ->dbSchemaReaderMock ->expects (self :: exactly ( 2 ))
328
+ $ this ->dbSchemaReaderMock ->expects ($ this -> any ( ))
282
329
->method ('getTableOptions ' )
283
330
->withConsecutive (...array_values ($ withContext ))
284
331
->willReturnOnConsecutiveCalls (
285
332
['Engine ' => 'innodb ' , 'Comment ' => '' ],
286
333
['Engine ' => 'innodb ' , 'Comment ' => 'Not null comment ' ]
287
334
);
288
- $ this ->dbSchemaReaderMock ->expects (self :: exactly ( 2 ))
335
+ $ this ->dbSchemaReaderMock ->expects ($ this -> any ( ))
289
336
->method ('readColumns ' )
290
337
->withConsecutive (...array_values ($ withContext ))
291
338
->willReturnOnConsecutiveCalls ($ columns ['first_table ' ], $ columns ['second_table ' ]);
292
- $ this ->dbSchemaReaderMock ->expects (self :: exactly ( 2 ))
339
+ $ this ->dbSchemaReaderMock ->expects ($ this -> any ( ))
293
340
->method ('readIndexes ' )
294
341
->withConsecutive (...array_values ($ withContext ))
295
342
->willReturnOnConsecutiveCalls ([], $ indexes ['second_table ' ]);
296
- $ this ->dbSchemaReaderMock ->expects (self :: exactly ( 2 ))
343
+ $ this ->dbSchemaReaderMock ->expects ($ this -> any ( ))
297
344
->method ('readConstraints ' )
298
345
->withConsecutive (...array_values ($ withContext ))
299
346
->willReturnOnConsecutiveCalls ($ constraints ['first_table ' ], []);
300
- $ this ->dbSchemaReaderMock ->expects (self :: exactly ( 2 ))
347
+ $ this ->dbSchemaReaderMock ->expects ($ this -> any ( ))
301
348
->method ('readReferences ' )
302
349
->withConsecutive (...array_values ($ withContext ))
303
350
->willReturnOnConsecutiveCalls ($ references ['first_table ' ], []);
@@ -322,7 +369,7 @@ public function testBuild(array $columns, array $references, array $constraints,
322
369
);
323
370
$ table ->addColumns ([$ firstColumn , $ foreignColumn , $ timestampColumn ]);
324
371
$ table ->addConstraints ([$ foreignKey , $ primaryKey ]);
325
- $ this ->elementFactoryMock ->expects (self :: exactly ( 9 ))
372
+ $ this ->elementFactoryMock ->expects ($ this -> any ( ))
326
373
->method ('create ' )
327
374
->withConsecutive (
328
375
[
@@ -426,14 +473,6 @@ public function testBuild(array $columns, array $references, array $constraints,
426
473
$ index ,
427
474
$ foreignKey
428
475
);
429
- $ resourceConnectionMock = $ this ->getMockBuilder (ResourceConnection::class)
430
- ->disableOriginalConstructor ()
431
- ->getMock ();
432
- /** @var Schema $schema */
433
- $ schema = $ this ->objectManagerHelper ->getObject (
434
- Schema::class,
435
- ['resourceConnection ' => $ resourceConnectionMock ]
436
- );
437
- $ this ->model ->build ($ schema );
476
+
438
477
}
439
478
}
0 commit comments