Skip to content

Commit 87214e0

Browse files
committed
wip
1 parent baddcb1 commit 87214e0

File tree

4 files changed

+49
-2
lines changed

4 files changed

+49
-2
lines changed

src/Tempest/Framework/Commands/DatabaseSeedCommand.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,14 @@ public function __invoke(
2828
?string $database = null,
2929
#[ConsoleArgument(description: 'Run all database seeders')]
3030
bool $all = false,
31+
#[ConsoleArgument(description: 'Select one specific seeder to run')]
32+
?string $seeder = null,
3133
): void {
34+
if ($seeder !== null) {
35+
$this->runSeeder($seeder, $database);
36+
return;
37+
}
38+
3239
if (count($this->seederConfig->seeders) === 1) {
3340
$this->runSeeder($this->seederConfig->seeders[0], $database);
3441
return;

src/Tempest/Framework/Commands/MigrateFreshCommand.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ public function __invoke(
4040
bool $seed = false,
4141
#[ConsoleArgument(description: 'Run all database seeders after the database has been migrated')]
4242
bool $all = false,
43+
#[ConsoleArgument(description: 'Select one specific seeder to run')]
44+
?string $seeder = null,
4345
): ExitCode {
4446
if ($validate) {
4547
$validationSuccess = $this->console->call(MigrateValidateCommand::class);
@@ -56,11 +58,21 @@ public function __invoke(
5658
$this->console->info('There is no migration to drop.');
5759
}
5860

59-
$this->console->call(MigrateUpCommand::class, ['fresh' => false, 'validate' => false, 'database' => $database]);
61+
$this->console->call(MigrateUpCommand::class, [
62+
'fresh' => false,
63+
'validate' => false,
64+
'database' => $database
65+
]);
66+
67+
$seed = $seed || $seeder !== null;
6068

6169
if ($seed) {
6270
$this->console->header('Seeding database');
63-
$this->console->call(DatabaseSeedCommand::class, ['database' => $database, 'all' => $all]);
71+
$this->console->call(DatabaseSeedCommand::class, [
72+
'database' => $database,
73+
'all' => $all,
74+
'seeder' => $seeder,
75+
]);
6476
}
6577

6678
return ExitCode::SUCCESS;

tests/Fixtures/TestDatabaseSeeder.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Tests\Tempest\Fixtures;
44

55
use Tempest\Database\DatabaseSeeder;
6+
use Tempest\Discovery\SkipDiscovery;
67
use Tests\Tempest\Fixtures\Modules\Books\Models\Book;
78
use UnitEnum;
89

tests/Integration/Framework/Commands/DatabaseSeedCommandTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,33 @@ public function test_seed_with_selected_seeder(): void
3636
$this->assertSame(1, query(Book::class)->count()->execute());
3737
}
3838

39+
public function test_seed_with_manually_selected_seeder(): void
40+
{
41+
$this->migrate(
42+
CreateMigrationsTable::class,
43+
CreateBookTable::class,
44+
);
45+
46+
$this->console
47+
->call(sprintf('db:seed --seeder=%s', SecondTestDatabaseSeeder::class))
48+
->assertSuccess();
49+
50+
$book = Book::get(1);
51+
$this->assertSame('Timeline Taxi 2', $book->title);
52+
$this->assertSame(1, query(Book::class)->count()->execute());
53+
}
54+
55+
public function test_migrate_fresh_seed_with_manually_selected_seeder(): void
56+
{
57+
$this->console
58+
->call(sprintf('migrate:fresh --seeder=%s', SecondTestDatabaseSeeder::class))
59+
->assertSuccess();
60+
61+
$book = Book::get(1);
62+
$this->assertSame('Timeline Taxi 2', $book->title);
63+
$this->assertSame(1, query(Book::class)->count()->execute());
64+
}
65+
3966
public function test_seed_all(): void
4067
{
4168
$this->migrate(

0 commit comments

Comments
 (0)