44
55use Tempest \Core \AppConfig ;
66use Tempest \Core \Environment ;
7+ use Tempest \Database \Config \SeederConfig ;
78use Tempest \Database \Migrations \CreateMigrationsTable ;
89use Tests \Tempest \Fixtures \Migrations \CreateBookTable ;
910use Tests \Tempest \Fixtures \Modules \Books \Models \Book ;
11+ use Tests \Tempest \Fixtures \SecondTestDatabaseSeeder ;
12+ use Tests \Tempest \Fixtures \TestDatabaseSeeder ;
1013use Tests \Tempest \Integration \FrameworkIntegrationTestCase ;
1114
15+ use function Tempest \Database \query ;
16+
1217final class DatabaseSeedCommandTest extends FrameworkIntegrationTestCase
1318{
14- public function test_seed (): void
19+ public function test_seed_with_selected_seeder (): void
1520 {
1621 $ this ->migrate (
1722 CreateMigrationsTable::class,
@@ -20,17 +25,60 @@ public function test_seed(): void
2025
2126 $ this ->console
2227 ->call ('db:seed ' )
28+ ->assertSee (TestDatabaseSeeder::class)
29+ ->assertSee (SecondTestDatabaseSeeder::class)
30+ ->submit ('1 ' )
31+ ->submit ()
32+ ->assertSuccess ();
33+
34+ $ book = Book::get (1 );
35+ $ this ->assertSame ('Timeline Taxi 2 ' , $ book ->title );
36+ $ this ->assertSame (1 , query (Book::class)->count ()->execute ());
37+ }
38+
39+ public function test_seed_all (): void
40+ {
41+ $ this ->migrate (
42+ CreateMigrationsTable::class,
43+ CreateBookTable::class,
44+ );
45+
46+ $ this ->console
47+ ->call ('db:seed --all ' )
2348 ->assertSuccess ();
2449
2550 $ book = Book::get (1 );
51+ $ this ->assertSame ('Timeline Taxi ' , $ book ->title );
2652
53+ $ book = Book::get (2 );
54+ $ this ->assertSame ('Timeline Taxi 2 ' , $ book ->title );
55+
56+ $ this ->assertSame (2 , query (Book::class)->count ()->execute ());
57+ }
58+
59+ public function test_seed_when_only_one_seeder_is_available (): void
60+ {
61+ $ seederConfig = $ this ->container ->get (SeederConfig::class);
62+ unset($ seederConfig ->seeders [1 ]);
63+
64+ $ this ->migrate (
65+ CreateMigrationsTable::class,
66+ CreateBookTable::class,
67+ );
68+
69+ $ this ->console
70+ ->call ('db:seed ' )
71+ ->print ();
72+
73+ $ book = Book::get (1 );
2774 $ this ->assertSame ('Timeline Taxi ' , $ book ->title );
75+ $ this ->assertSame (1 , query (Book::class)->count ()->execute ());
2876 }
2977
3078 public function test_seed_via_migrate_fresh (): void
3179 {
3280 $ this ->console
33- ->call ('migrate:fresh --seed ' )
81+ ->call ('migrate:fresh --seed --all ' )
3482 ->assertSuccess ();
3583
3684 $ book = Book::get (1 );
@@ -44,7 +92,7 @@ public function test_db_seed_caution(): void
4492 $ appConfig ->environment = Environment::PRODUCTION ;
4593
4694 $ this ->console
47- ->call ('migrate:fresh --seed ' )
95+ ->call ('migrate:fresh --seed --all ' )
4896 ->assertSee ('Do you wish to continue ' );
4997 }
50- }
98+ }
0 commit comments