@@ -305,8 +305,8 @@ public function output_also_creates_constraints_for_pivot_table_migration_larave
305
305
}
306
306
307
307
/**
308
- * @test
309
- */
308
+ * @test
309
+ */
310
310
public function output_does_not_duplicate_pivot_table_migration ()
311
311
{
312
312
$ this ->files ->expects ('stub ' )
@@ -334,8 +334,8 @@ public function output_does_not_duplicate_pivot_table_migration()
334
334
}
335
335
336
336
/**
337
- * @test
338
- */
337
+ * @test
338
+ */
339
339
public function output_does_not_duplicate_pivot_table_migration_laravel6 ()
340
340
{
341
341
$ app = \Mockery::mock ();
@@ -422,6 +422,70 @@ public function output_creates_foreign_keys_with_nullable_chained_correctly_lara
422
422
$ this ->assertEquals (['created ' => [$ model_migration ]], $ this ->subject ->output ($ tree ));
423
423
}
424
424
425
+ /**
426
+ * @test
427
+ */
428
+ public function output_works_with_polymorphic_relationships ()
429
+ {
430
+ $ this ->files ->expects ('stub ' )
431
+ ->with ('migration.stub ' )
432
+ ->andReturn (file_get_contents ('stubs/migration.stub ' ));
433
+
434
+ $ now = Carbon::now ();
435
+ Carbon::setTestNow ($ now );
436
+
437
+ $ post_migration = str_replace ('timestamp ' , $ now ->copy ()->subSeconds (2 )->format ('Y_m_d_His ' ), 'database/migrations/timestamp_create_posts_table.php ' );
438
+ $ user_migration = str_replace ('timestamp ' , $ now ->copy ()->subSecond ()->format ('Y_m_d_His ' ), 'database/migrations/timestamp_create_users_table.php ' );
439
+ $ image_migration = str_replace ('timestamp ' , $ now ->format ('Y_m_d_His ' ), 'database/migrations/timestamp_create_images_table.php ' );
440
+
441
+ $ this ->files ->expects ('put ' )
442
+ ->with ($ post_migration , $ this ->fixture ('migrations/polymorphic_relationships_posts_table.php ' ));
443
+ $ this ->files ->expects ('put ' )
444
+ ->with ($ user_migration , $ this ->fixture ('migrations/polymorphic_relationships_users_table.php ' ));
445
+ $ this ->files ->expects ('put ' )
446
+ ->with ($ image_migration , $ this ->fixture ('migrations/polymorphic_relationships_images_table.php ' ));
447
+
448
+ $ tokens = $ this ->blueprint ->parse ($ this ->fixture ('definitions/polymorphic-relationships.bp ' ));
449
+ $ tree = $ this ->blueprint ->analyze ($ tokens );
450
+
451
+ $ this ->assertEquals (['created ' => [$ post_migration , $ user_migration , $ image_migration ]], $ this ->subject ->output ($ tree ));
452
+ }
453
+
454
+ /**
455
+ * @test
456
+ */
457
+ public function output_works_with_polymorphic_relationships_laravel6 ()
458
+ {
459
+ $ app = \Mockery::mock ();
460
+ $ app ->shouldReceive ('version ' )
461
+ ->withNoArgs ()
462
+ ->andReturn ('6.0.0 ' );
463
+ App::swap ($ app );
464
+
465
+ $ this ->files ->expects ('stub ' )
466
+ ->with ('migration.stub ' )
467
+ ->andReturn (file_get_contents ('stubs/migration.stub ' ));
468
+
469
+ $ now = Carbon::now ();
470
+ Carbon::setTestNow ($ now );
471
+
472
+ $ post_migration = str_replace ('timestamp ' , $ now ->copy ()->subSeconds (2 )->format ('Y_m_d_His ' ), 'database/migrations/timestamp_create_posts_table.php ' );
473
+ $ user_migration = str_replace ('timestamp ' , $ now ->copy ()->subSecond ()->format ('Y_m_d_His ' ), 'database/migrations/timestamp_create_users_table.php ' );
474
+ $ image_migration = str_replace ('timestamp ' , $ now ->format ('Y_m_d_His ' ), 'database/migrations/timestamp_create_images_table.php ' );
475
+
476
+ $ this ->files ->expects ('put ' )
477
+ ->with ($ post_migration , $ this ->fixture ('migrations/polymorphic_relationships_posts_table_laravel6.php ' ));
478
+ $ this ->files ->expects ('put ' )
479
+ ->with ($ user_migration , $ this ->fixture ('migrations/polymorphic_relationships_users_table_laravel6.php ' ));
480
+ $ this ->files ->expects ('put ' )
481
+ ->with ($ image_migration , $ this ->fixture ('migrations/polymorphic_relationships_images_table_laravel6.php ' ));
482
+
483
+ $ tokens = $ this ->blueprint ->parse ($ this ->fixture ('definitions/polymorphic-relationships.bp ' ));
484
+ $ tree = $ this ->blueprint ->analyze ($ tokens );
485
+
486
+ $ this ->assertEquals (['created ' => [$ post_migration , $ user_migration , $ image_migration ]], $ this ->subject ->output ($ tree ));
487
+ }
488
+
425
489
public function modelTreeDataProvider ()
426
490
{
427
491
return [
0 commit comments