Skip to content

Commit f2730bd

Browse files
committed
Consildate test cases into data provider
1 parent 716e3e9 commit f2730bd

File tree

1 file changed

+5
-120
lines changed

1 file changed

+5
-120
lines changed

tests/Feature/Generators/MigrationGeneratorTest.php

Lines changed: 5 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -70,29 +70,6 @@ public function output_generates_migrations($definition, $path, $model): void
7070
$this->assertEquals(['created' => [$timestamp_path]], $this->subject->output($tree));
7171
}
7272

73-
#[Test]
74-
public function output_writes_migration_for_foreign_shorthand(): void
75-
{
76-
$this->filesystem->expects('stub')
77-
->with('migration.stub')
78-
->andReturn($this->stub('migration.stub'));
79-
80-
$now = Carbon::now();
81-
Carbon::setTestNow($now);
82-
83-
$timestamp_path = str_replace('timestamp', $now->format('Y_m_d_His'), 'database/migrations/timestamp_create_comments_table.php');
84-
85-
$this->filesystem->expects('exists')->andReturn(false);
86-
87-
$this->filesystem->expects('put')
88-
->with($timestamp_path, $this->fixture('migrations/foreign-key-shorthand.php'));
89-
90-
$tokens = $this->blueprint->parse($this->fixture('drafts/foreign-key-shorthand.yaml'));
91-
$tree = $this->blueprint->analyze($tokens);
92-
93-
$this->assertEquals(['created' => [$timestamp_path]], $this->subject->output($tree));
94-
}
95-
9673
#[Test]
9774
public function output_uses_past_timestamp_for_multiple_migrations(): void
9875
{
@@ -396,55 +373,6 @@ public function output_creates_foreign_keys_with_nullable_chained_correctly(): v
396373
$this->assertEquals(['created' => [$model_migration]], $this->subject->output($tree));
397374
}
398375

399-
#[Test]
400-
public function output_creates_nullable_foreign_key_without_column_type_beeing_id(): void
401-
{
402-
$this->filesystem->expects('stub')
403-
->with('migration.stub')
404-
->andReturn($this->stub('migration.stub'));
405-
406-
$now = Carbon::now();
407-
Carbon::setTestNow($now);
408-
409-
$model_migration = str_replace('timestamp', $now->format('Y_m_d_His'), 'database/migrations/timestamp_create_comments_table.php');
410-
411-
$this->filesystem->expects('exists')->with($model_migration)->andReturn(false);
412-
413-
$this->files
414-
->expects('put')
415-
->with($model_migration, $this->fixture('migrations/nullable-columns-with-foreign.php'));
416-
417-
$tokens = $this->blueprint->parse($this->fixture('drafts/nullable-columns-with-foreign.yaml'));
418-
419-
$tree = $this->blueprint->analyze($tokens);
420-
421-
$this->assertEquals(['created' => [$model_migration]], $this->subject->output($tree));
422-
}
423-
424-
#[Test]
425-
public function output_creates_foreign_keys_with_on_delete(): void
426-
{
427-
$this->filesystem->expects('stub')
428-
->with('migration.stub')
429-
->andReturn($this->stub('migration.stub'));
430-
431-
$now = Carbon::now();
432-
Carbon::setTestNow($now);
433-
434-
$model_migration = str_replace('timestamp', $now->format('Y_m_d_His'), 'database/migrations/timestamp_create_comments_table.php');
435-
436-
$this->filesystem->expects('exists')->andReturn(false);
437-
438-
$this->files
439-
->expects('put')
440-
->with($model_migration, $this->fixture('migrations/foreign-key-on-delete.php'));
441-
442-
$tokens = $this->blueprint->parse($this->fixture('drafts/foreign-key-on-delete.yaml'));
443-
$tree = $this->blueprint->analyze($tokens);
444-
445-
$this->assertEquals(['created' => [$model_migration]], $this->subject->output($tree));
446-
}
447-
448376
#[Test]
449377
public function output_works_with_polymorphic_relationships(): void
450378
{
@@ -474,29 +402,6 @@ public function output_works_with_polymorphic_relationships(): void
474402
$this->assertEquals(['created' => [$post_migration, $user_migration, $image_migration]], $this->subject->output($tree));
475403
}
476404

477-
#[Test]
478-
public function output_works_with_multiple_morphto_statements_in_polymorphic_relationship(): void
479-
{
480-
$this->filesystem->expects('stub')
481-
->with('migration.stub')
482-
->andReturn($this->stub('migration.stub'));
483-
484-
$now = Carbon::now();
485-
Carbon::setTestNow($now);
486-
487-
$image_migration = str_replace('timestamp', $now->format('Y_m_d_His'), 'database/migrations/timestamp_create_images_table.php');
488-
489-
$this->filesystem->expects('exists')->andReturn(false);
490-
491-
$this->filesystem->expects('put')
492-
->with($image_migration, $this->fixture('migrations/polymorphic_relationships_images_table_multiple_morphto.php'));
493-
494-
$tokens = $this->blueprint->parse($this->fixture('drafts/polymorphic-relationships-multiple-morphto.yaml'));
495-
$tree = $this->blueprint->analyze($tokens);
496-
497-
$this->assertEquals(['created' => [$image_migration]], $this->subject->output($tree));
498-
}
499-
500405
#[Test]
501406
public function output_does_not_generate_relationship_for_uuid(): void
502407
{
@@ -606,31 +511,6 @@ public function output_generates_custom_pivot_tables(): void
606511
$this->assertEquals(['created' => [$user_migration, $team_migration, $pivot_migration]], $this->subject->output($tree));
607512
}
608513

609-
#[Test]
610-
public function output_omits_length_for_integers(): void
611-
{
612-
$this->filesystem->expects('stub')
613-
->with('migration.stub')
614-
->andReturn($this->stub('migration.stub'));
615-
616-
$now = Carbon::now();
617-
Carbon::setTestNow($now);
618-
619-
$timestamp_path = 'database/migrations/' . $now->format('Y_m_d_His') . '_create_omits_table.php';
620-
621-
$this->filesystem->expects('exists')
622-
->with($timestamp_path)
623-
->andReturn(false);
624-
625-
$this->filesystem->expects('put')
626-
->with($timestamp_path, $this->fixture('migrations/omits-length-for-integers.php'));
627-
628-
$tokens = $this->blueprint->parse($this->fixture('drafts/omits-length-for-integers.yaml'));
629-
$tree = $this->blueprint->analyze($tokens);
630-
631-
$this->assertEquals(['created' => [$timestamp_path]], $this->subject->output($tree));
632-
}
633-
634514
public static function modelTreeDataProvider()
635515
{
636516
return [
@@ -659,6 +539,11 @@ public static function modelTreeDataProvider()
659539
['drafts/full-text.yaml', 'database/migrations/timestamp_create_posts_table.php', 'migrations/full-text.php'],
660540
['drafts/model-with-meta.yaml', 'database/migrations/timestamp_create_post_table.php', 'migrations/model-with-meta.php'],
661541
['drafts/infer-belongsto.yaml', 'database/migrations/timestamp_create_conferences_table.php', 'migrations/infer-belongsto.php'],
542+
['drafts/foreign-key-shorthand.yaml', 'database/migrations/timestamp_create_comments_table.php', 'migrations/foreign-key-shorthand.php'],
543+
['drafts/polymorphic-relationships-multiple-morphto.yaml', 'database/migrations/timestamp_create_images_table.php', 'migrations/polymorphic_relationships_images_table_multiple_morphto.php'],
544+
['drafts/foreign-key-on-delete.yaml', 'database/migrations/timestamp_create_comments_table.php', 'migrations/foreign-key-on-delete.php'],
545+
['drafts/nullable-columns-with-foreign.yaml', 'database/migrations/timestamp_create_comments_table.php', 'migrations/nullable-columns-with-foreign.php'],
546+
['drafts/omits-length-for-integers.yaml', 'database/migrations/timestamp_create_omits_table.php', 'migrations/omits-length-for-integers.php'],
662547
];
663548
}
664549
}

0 commit comments

Comments
 (0)