From 022c9d74e469a99efe3c134040df28fd38110eed Mon Sep 17 00:00:00 2001 From: SonyPradana Date: Tue, 26 Sep 2023 00:22:58 +0700 Subject: [PATCH 1/6] feat: add integrate seeder - add seeder abstract, to run seeder task - `run`, basic method to run seeder - `call`, call another seeder class - `create`, shorthand to create/insert data to database - add path for seeder path - add command to run seeder - add commnad to make seeder --- src/System/Database/Seeder/Seeder.php | 40 ++++++++ src/System/Integrate/Application.php | 28 +++++- src/System/Integrate/Console/SeedCommand.php | 92 +++++++++++++++++++ src/System/Integrate/helper.php | 9 ++ tests/Integrate/ApplicationTest.php | 3 +- tests/Integrate/Commands/SeedCommandTest.php | 81 ++++++++++++++++ .../Commands/database/seeders/BasicSeeder.php | 13 +++ .../Commands/database/seeders/ChainSeeder.php | 13 +++ .../Commands/database/seeders/UserSeeder.php | 19 ++++ 9 files changed, 296 insertions(+), 2 deletions(-) create mode 100644 src/System/Database/Seeder/Seeder.php create mode 100644 src/System/Integrate/Console/SeedCommand.php create mode 100644 tests/Integrate/Commands/SeedCommandTest.php create mode 100644 tests/Integrate/Commands/database/seeders/BasicSeeder.php create mode 100644 tests/Integrate/Commands/database/seeders/ChainSeeder.php create mode 100644 tests/Integrate/Commands/database/seeders/UserSeeder.php diff --git a/src/System/Database/Seeder/Seeder.php b/src/System/Database/Seeder/Seeder.php new file mode 100644 index 00000000..5b65f5c3 --- /dev/null +++ b/src/System/Database/Seeder/Seeder.php @@ -0,0 +1,40 @@ +app = $app; + } + + /** + * @param class-string $class_name + */ + public function call(string $class_name): void + { + $this->app->call([$class_name, 'run']); + } + + public function create(string $table_name): Insert + { + /** @var MyPDO */ + $pdo = $this->app->get(MyPDO::class); + + return new Insert($table_name, $pdo); + } + + /** + * Run seeder. + */ + abstract public function run(): void; +} diff --git a/src/System/Integrate/Application.php b/src/System/Integrate/Application.php index 8e68dabf..9904d1ac 100644 --- a/src/System/Integrate/Application.php +++ b/src/System/Integrate/Application.php @@ -107,6 +107,11 @@ final class Application extends Container */ private string $migraton_path; + /** + * Seeder path. + */ + private string $seeder_path; + /** * Public path. */ @@ -226,6 +231,7 @@ public function loadConfig(string $base_path) $this->setProviderPath($configs['SERVICE_PROVIDER']); $this->setMigrationPath($configs['MIGRATION_PATH']); $this->setPublicPath($configs['PUBLIC_PATH']); + $this->setSeederPath($configs['SEEDER_PATH']); // pusher config $this->set('config.pusher_id', $configs['PUSHER_APP_ID']); $this->set('config.pusher_key', $configs['PUSHER_APP_KEY']); @@ -262,8 +268,9 @@ private function defaultConfigs() 'CONFIG' => DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR, 'MIDDLEWARE' => DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'middleware' . DIRECTORY_SEPARATOR, 'SERVICE_PROVIDER' => DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'Providers' . DIRECTORY_SEPARATOR, - 'MIGRATION_PATH' => DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'database' . DIRECTORY_SEPARATOR . 'migrations' . DIRECTORY_SEPARATOR, + 'MIGRATION_PATH' => DIRECTORY_SEPARATOR . 'database' . DIRECTORY_SEPARATOR . 'migrations' . DIRECTORY_SEPARATOR, 'PUBLIC_PATH' => DIRECTORY_SEPARATOR . 'public' . DIRECTORY_SEPARATOR, + 'SEEDER_PATH' => DIRECTORY_SEPARATOR . 'database' . DIRECTORY_SEPARATOR . 'seeders' . DIRECTORY_SEPARATOR, 'PROVIDERS' => [ // provider class name @@ -503,6 +510,17 @@ public function setMigrationPath(string $path): self return $this; } + /** + * Set seeder path. + */ + public function setSeederPath(string $path): self + { + $this->seeder_path = $this->base_path . $path; + $this->set('path.seeder', $this->seeder_path); + + return $this; + } + /** * Set public path. */ @@ -644,6 +662,14 @@ public function migration_path(): string return $this->get('path.migration'); } + /** + * Get seeder path. + */ + public function seeder_path(): string + { + return $this->get('path.seeder'); + } + /** * Get public path. */ diff --git a/src/System/Integrate/Console/SeedCommand.php b/src/System/Integrate/Console/SeedCommand.php new file mode 100644 index 00000000..ecb43474 --- /dev/null +++ b/src/System/Integrate/Console/SeedCommand.php @@ -0,0 +1,92 @@ +> + */ + public static array $command = [ + [ + 'cmd' => 'db:seed', + 'mode' => 'full', + 'class' => self::class, + 'fn' => 'main', + ], + [ + 'cmd' => 'make:seed', + 'mode' => 'full', + 'class' => self::class, + 'fn' => 'main', + ], + ]; + + /** + * @return array> + */ + public function printHelp() + { + return [ + 'commands' => [ + 'db:seed' => 'Run seeding', + ], + 'options' => [ + '--class' => 'Target class', + ], + 'relation' => [ + 'db:seed' => ['--class'], + ], + ]; + } + + public function main(): int + { + $exit = 0; + + if (!$this->class) { + warn('command db:seed require --class flag follow by class name.')->out(false); + + return 1; + } + + if (!class_exists($this->class)) { + warn("Class '{$this->class}::class' doest exist.")->out(false); + + return 1; + } + + info('Running seeders...')->out(false); + try { + app()->call([$this->class, 'run']); + + ok('Succes run seeder')->out(false); + } catch (\Throwable $th) { + warn($th->getMessage())->out(false); + $exit = 1; + } + + return $exit; + } + + public function make(): int + { + return 0; + } +} diff --git a/src/System/Integrate/helper.php b/src/System/Integrate/helper.php index dbad211b..da8d1ad1 100644 --- a/src/System/Integrate/helper.php +++ b/src/System/Integrate/helper.php @@ -184,6 +184,15 @@ function migration_path(string $surfix_path = ''): string } } +if (!function_exists('seeder_path')) { + function seeder_path(string $surfix_path = ''): string + { + $path = app()->seeder_path() . $surfix_path; + + return $path; + } +} + if (!function_exists('base_path')) { /** * Get base path. diff --git a/tests/Integrate/ApplicationTest.php b/tests/Integrate/ApplicationTest.php index 9344f78f..59dc6ff1 100644 --- a/tests/Integrate/ApplicationTest.php +++ b/tests/Integrate/ApplicationTest.php @@ -100,8 +100,9 @@ private function defaultConfigs() 'CONFIG' => DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR, 'MIDDLEWARE' => DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'middleware' . DIRECTORY_SEPARATOR, 'SERVICE_PROVIDER' => DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'Providers' . DIRECTORY_SEPARATOR, - 'MIGRATION_PATH' => DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'database' . DIRECTORY_SEPARATOR . 'migrations' . DIRECTORY_SEPARATOR, + 'MIGRATION_PATH' => DIRECTORY_SEPARATOR . 'database' . DIRECTORY_SEPARATOR . 'migrations' . DIRECTORY_SEPARATOR, 'PUBLIC_PATH' => DIRECTORY_SEPARATOR . 'public' . DIRECTORY_SEPARATOR, + 'SEEDER_PATH' => DIRECTORY_SEPARATOR . 'database' . DIRECTORY_SEPARATOR . 'seeders' . DIRECTORY_SEPARATOR, 'PROVIDERS' => [ // provider class name diff --git a/tests/Integrate/Commands/SeedCommandTest.php b/tests/Integrate/Commands/SeedCommandTest.php new file mode 100644 index 00000000..84afd6e5 --- /dev/null +++ b/tests/Integrate/Commands/SeedCommandTest.php @@ -0,0 +1,81 @@ +app = new Application(__DIR__); + $this->app->setSeederPath(__DIR__ . '//database//seeders//'); + $this->app->set('environment', 'dev'); + new Schema($this->app); + new FacadesPDO($this->app); + new DB($this->app); + $this->app->set(\System\Database\MyPDO::class, $this->pdo); + $this->app->set('MySchema', $this->schema); + $this->app->set('dsn.sql', $this->env); + } + + protected function tearDown(): void + { + parent::tearDown(); + $this->app->flush(); + } + + /** + * @test + */ + public function itCanRunSeeder() + { + $seeder = new SeedCommand(['cli', 'db:seed', '--class', 'BasicSeeder']); + ob_start(); + $seeder->main(); + $out = ob_get_clean(); + + $this->assertTrue(Str::contains($out, 'Succes run seeder')); + } + + /** + * @test + * + * @group database + */ + public function itCanRunSeederRunnerWithRealInsertData() + { + $seeder = new SeedCommand(['cli', 'db:seed', '--class', 'UserSeeder']); + ob_start(); + $seeder->main(); + $out = ob_get_clean(); + + $this->assertTrue(Str::contains($out, 'Succes run seeder')); + } + + /** + * @test + */ + public function itCanRunSeederWithCallOther() + { + $seeder = new SeedCommand(['cli', 'db:seed', '--class', 'ChainSeeder']); + ob_start(); + $seeder->main(); + $out = ob_get_clean(); + + $this->assertTrue(Str::contains($out, 'Succes run seeder')); + } +} diff --git a/tests/Integrate/Commands/database/seeders/BasicSeeder.php b/tests/Integrate/Commands/database/seeders/BasicSeeder.php new file mode 100644 index 00000000..d932af9e --- /dev/null +++ b/tests/Integrate/Commands/database/seeders/BasicSeeder.php @@ -0,0 +1,13 @@ +call(BasicSeeder::class); + } +} diff --git a/tests/Integrate/Commands/database/seeders/UserSeeder.php b/tests/Integrate/Commands/database/seeders/UserSeeder.php new file mode 100644 index 00000000..60527f18 --- /dev/null +++ b/tests/Integrate/Commands/database/seeders/UserSeeder.php @@ -0,0 +1,19 @@ +create('users') + ->values([ + 'user' => 'test', + 'pwd' => password_hash('password', PASSWORD_DEFAULT), + 'stat' => 10, + ]) + ->execute(); + } +} From 4e152aea7c7157e00b04f44a0417e39af39420b2 Mon Sep 17 00:00:00 2001 From: Angger Pradana Date: Wed, 27 Sep 2023 07:15:41 +0000 Subject: [PATCH 2/6] change group test for seeder command --- tests/Integrate/Commands/SeedCommandTest.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/Integrate/Commands/SeedCommandTest.php b/tests/Integrate/Commands/SeedCommandTest.php index 84afd6e5..3d34407e 100644 --- a/tests/Integrate/Commands/SeedCommandTest.php +++ b/tests/Integrate/Commands/SeedCommandTest.php @@ -40,6 +40,8 @@ protected function tearDown(): void /** * @test + * + * @group database */ public function itCanRunSeeder() { @@ -68,6 +70,8 @@ public function itCanRunSeederRunnerWithRealInsertData() /** * @test + * + * @group database */ public function itCanRunSeederWithCallOther() { From b3489ff1b738022dcf313e941a0cd831231e17ec Mon Sep 17 00:00:00 2001 From: Angger Pradana Date: Mon, 2 Oct 2023 05:58:12 +0700 Subject: [PATCH 3/6] add make seeder command --- src/System/Integrate/Console/SeedCommand.php | 87 +++++++++++++++++--- 1 file changed, 77 insertions(+), 10 deletions(-) diff --git a/src/System/Integrate/Console/SeedCommand.php b/src/System/Integrate/Console/SeedCommand.php index ecb43474..8e909e10 100644 --- a/src/System/Integrate/Console/SeedCommand.php +++ b/src/System/Integrate/Console/SeedCommand.php @@ -5,14 +5,20 @@ namespace System\Integrate\Console; use System\Console\Command; +use System\Console\Prompt; use System\Console\Traits\PrintHelpTrait; +use System\Template\Generate; +use System\Text\Str; +use function System\Console\fail; use function System\Console\info; use function System\Console\ok; +use function System\Console\style; use function System\Console\warn; /** * @property string $class + * @property bool $force */ class SeedCommand extends Command { @@ -34,18 +40,19 @@ class SeedCommand extends Command 'cmd' => 'make:seed', 'mode' => 'full', 'class' => self::class, - 'fn' => 'main', + 'fn' => 'make', ], ]; /** * @return array> */ - public function printHelp() + public function printHelp(): array { return [ 'commands' => [ - 'db:seed' => 'Run seeding', + 'db:seed' => 'Run seeding', + 'make:seed' => 'Create new seeder class', ], 'options' => [ '--class' => 'Target class', @@ -56,27 +63,54 @@ public function printHelp() ]; } + private function runInDev(): bool + { + if (app()->isDev() || $this->force) { + return true; + } + + /* @var bool */ + return (new Prompt(style('Runing seeder in production?')->textRed(), [ + 'yes' => fn () => true, + 'no' => fn () => false, + ], 'no')) + ->selection([ + style('yes')->textDim(), + ' no', + ]) + ->option(); + } + public function main(): int { - $exit = 0; + $class = $this->class; + $exit = 0; - if (!$this->class) { + if (false === $this->runInDev()) { + return 2; + } + + if (null === $class) { warn('command db:seed require --class flag follow by class name.')->out(false); return 1; } - if (!class_exists($this->class)) { - warn("Class '{$this->class}::class' doest exist.")->out(false); + if (!Str::startsWith($class, 'Database\Seeders')) { + $class = 'Database\\Seeders\\' . $class; + } + + if (false === class_exists($class)) { + warn("Class '{$class}::class' doest exist.")->out(false); return 1; } info('Running seeders...')->out(false); try { - app()->call([$this->class, 'run']); + app()->call([$class, 'run']); - ok('Succes run seeder')->out(false); + ok('Success run seeder')->out(false); } catch (\Throwable $th) { warn($th->getMessage())->out(false); $exit = 1; @@ -87,6 +121,39 @@ public function main(): int public function make(): int { - return 0; + $class = $this->OPTION[0]; + + if (false === $this->runInDev()) { + return 2; + } + + if (null === $class) { + warn('command db:make require --class flag follow by class name.')->out(false); + + return 1; + } + + if (file_exists(seeder_path() . $class . '.php')) { + warn("Class '{$class}::class' already exist.")->out(false); + + return 1; + } + + $make = new Generate($class); + $make->namespace('Database\Seeders'); + $make->use('System\Database\Seeder\Seeder'); + $make->extend('Seeder'); + $make->addMethod('run') + ->setReturnType('void'); + + if (file_put_contents(seeder_path() . $class . '.php', $make->__toString())) { + ok('Success create seeder')->out(); + + return 0; + } + + fail('Fail to create seeder')->out(); + + return 1; } } From 486cdc9c6a171b1c10a5875164f3b25ffb0a96d9 Mon Sep 17 00:00:00 2001 From: Angger Pradana Date: Mon, 2 Oct 2023 06:47:19 +0700 Subject: [PATCH 4/6] add null property type --- src/System/Integrate/Console/SeedCommand.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/System/Integrate/Console/SeedCommand.php b/src/System/Integrate/Console/SeedCommand.php index 8e909e10..4a74be5f 100644 --- a/src/System/Integrate/Console/SeedCommand.php +++ b/src/System/Integrate/Console/SeedCommand.php @@ -17,8 +17,8 @@ use function System\Console\warn; /** - * @property string $class - * @property bool $force + * @property string|null $class + * @property bool|null $force */ class SeedCommand extends Command { @@ -123,10 +123,6 @@ public function make(): int { $class = $this->OPTION[0]; - if (false === $this->runInDev()) { - return 2; - } - if (null === $class) { warn('command db:make require --class flag follow by class name.')->out(false); From 4d3fad7bab39a095f93b57a1b167eb514da6d0c5 Mon Sep 17 00:00:00 2001 From: Angger Pradana Date: Mon, 2 Oct 2023 15:16:26 +0000 Subject: [PATCH 5/6] add test --- src/System/Integrate/Console/SeedCommand.php | 12 +++- tests/Integrate/Commands/CommandTest.php | 1 + tests/Integrate/Commands/SeedCommandsTest.php | 70 +++++++++++++++++++ ...est.php => SeedCommandsWithDabaseTest.php} | 2 +- .../Commands/assets/seeders/.gitignore | 1 + 5 files changed, 82 insertions(+), 4 deletions(-) create mode 100644 tests/Integrate/Commands/SeedCommandsTest.php rename tests/Integrate/Commands/{SeedCommandTest.php => SeedCommandsWithDabaseTest.php} (96%) create mode 100644 tests/Integrate/Commands/assets/seeders/.gitignore diff --git a/src/System/Integrate/Console/SeedCommand.php b/src/System/Integrate/Console/SeedCommand.php index 4a74be5f..5943569b 100644 --- a/src/System/Integrate/Console/SeedCommand.php +++ b/src/System/Integrate/Console/SeedCommand.php @@ -8,6 +8,7 @@ use System\Console\Prompt; use System\Console\Traits\PrintHelpTrait; use System\Template\Generate; +use System\Template\Method; use System\Text\Str; use function System\Console\fail; @@ -121,10 +122,14 @@ public function main(): int public function make(): int { - $class = $this->OPTION[0]; + $class = $this->OPTION[0] ?? null; + + if (false === $this->runInDev()) { + return 2; + } if (null === $class) { - warn('command db:make require --class flag follow by class name.')->out(false); + warn('command make:seed require class name')->out(false); return 1; } @@ -140,7 +145,8 @@ public function make(): int $make->use('System\Database\Seeder\Seeder'); $make->extend('Seeder'); $make->addMethod('run') - ->setReturnType('void'); + ->setReturnType('void') + ->visibility(Method::PUBLIC_); if (file_put_contents(seeder_path() . $class . '.php', $make->__toString())) { ok('Success create seeder')->out(); diff --git a/tests/Integrate/Commands/CommandTest.php b/tests/Integrate/Commands/CommandTest.php index fe5678cc..15e1c7b0 100644 --- a/tests/Integrate/Commands/CommandTest.php +++ b/tests/Integrate/Commands/CommandTest.php @@ -24,6 +24,7 @@ protected function setUp(): void $this->app->setCommandPath(__DIR__ . DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR); $this->app->setConfigPath(__DIR__ . DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR); $this->app->setMigrationPath(__DIR__ . DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR . 'migration' . DIRECTORY_SEPARATOR); + $this->app->setSeederPath(__DIR__ . DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR . 'seeders' . DIRECTORY_SEPARATOR); } protected function tearDown(): void diff --git a/tests/Integrate/Commands/SeedCommandsTest.php b/tests/Integrate/Commands/SeedCommandsTest.php new file mode 100644 index 00000000..8a8f00aa --- /dev/null +++ b/tests/Integrate/Commands/SeedCommandsTest.php @@ -0,0 +1,70 @@ +argv('cli make:seed BaseSeeder')); + ob_start(); + $exit = $makeCommand->make(); + ob_get_clean(); + + $this->assertSuccess($exit); + + $file = __DIR__ . '/assets/seeders/BaseSeeder.php'; + $this->assertTrue(file_exists($file)); + + $class = file_get_contents($file); + $this->assertContain('class BaseSeeder extends Seeder', $class, 'Stub test'); + $this->assertContain('public function run(): void', $class, 'Stub test'); + } + + /** + * @test + */ + public function itCanCallMakeCommandSeedWithFails() + { + $makeCommand = new SeedCommand($this->argv('cli make:seed')); + ob_start(); + $exit = $makeCommand->make(); + ob_get_clean(); + + $this->assertFails($exit); + } + + /** + * @test + */ + public function itCanCallMakeCommandSeedWithFailsFileExist() + { + app()->setSeederPath(__DIR__ . '//database//seeders//'); + $makeCommand = new SeedCommand($this->argv('cli make:seed BasicSeeder')); + ob_start(); + $exit = $makeCommand->make(); + ob_get_clean(); + + $this->assertFails($exit); + } +} diff --git a/tests/Integrate/Commands/SeedCommandTest.php b/tests/Integrate/Commands/SeedCommandsWithDabaseTest.php similarity index 96% rename from tests/Integrate/Commands/SeedCommandTest.php rename to tests/Integrate/Commands/SeedCommandsWithDabaseTest.php index 3d34407e..055a2eae 100644 --- a/tests/Integrate/Commands/SeedCommandTest.php +++ b/tests/Integrate/Commands/SeedCommandsWithDabaseTest.php @@ -11,7 +11,7 @@ use System\Support\Facades\Schema; use System\Text\Str; -final class SeedCommandTest extends \RealDatabaseConnectionTest +final class SeedCommandsWithDabaseTest extends \RealDatabaseConnectionTest { private Application $app; diff --git a/tests/Integrate/Commands/assets/seeders/.gitignore b/tests/Integrate/Commands/assets/seeders/.gitignore new file mode 100644 index 00000000..cde8069e --- /dev/null +++ b/tests/Integrate/Commands/assets/seeders/.gitignore @@ -0,0 +1 @@ +*.php From 781dc78f7eb82eabbcad635823fa8ef696fc8269 Mon Sep 17 00:00:00 2001 From: Angger Pradana Date: Tue, 3 Oct 2023 05:33:57 +0000 Subject: [PATCH 6/6] optional force create exist seeder class --- src/System/Integrate/Console/SeedCommand.php | 12 +++++------ tests/Integrate/Commands/SeedCommandsTest.php | 21 +++++++++++++++++++ .../Commands/database/seeders/BasicSeeder.php | 3 +-- .../Commands/database/seeders/ExistSeeder.php | 13 ++++++++++++ 4 files changed, 41 insertions(+), 8 deletions(-) create mode 100644 tests/Integrate/Commands/database/seeders/ExistSeeder.php diff --git a/src/System/Integrate/Console/SeedCommand.php b/src/System/Integrate/Console/SeedCommand.php index 5943569b..0879d52f 100644 --- a/src/System/Integrate/Console/SeedCommand.php +++ b/src/System/Integrate/Console/SeedCommand.php @@ -124,29 +124,29 @@ public function make(): int { $class = $this->OPTION[0] ?? null; - if (false === $this->runInDev()) { - return 2; - } - if (null === $class) { warn('command make:seed require class name')->out(false); return 1; } - if (file_exists(seeder_path() . $class . '.php')) { + if (file_exists(seeder_path() . $class . '.php') && !$this->force) { warn("Class '{$class}::class' already exist.")->out(false); return 1; } $make = new Generate($class); + $make->tabIndent(' '); + $make->tabSize(4); $make->namespace('Database\Seeders'); $make->use('System\Database\Seeder\Seeder'); $make->extend('Seeder'); + $make->setEndWithNewLine(); $make->addMethod('run') + ->visibility(Method::PUBLIC_) ->setReturnType('void') - ->visibility(Method::PUBLIC_); + ->body('// run some insert db'); if (file_put_contents(seeder_path() . $class . '.php', $make->__toString())) { ok('Success create seeder')->out(); diff --git a/tests/Integrate/Commands/SeedCommandsTest.php b/tests/Integrate/Commands/SeedCommandsTest.php index 8a8f00aa..2cdf946e 100644 --- a/tests/Integrate/Commands/SeedCommandsTest.php +++ b/tests/Integrate/Commands/SeedCommandsTest.php @@ -67,4 +67,25 @@ public function itCanCallMakeCommandSeedWithFailsFileExist() $this->assertFails($exit); } + + /** + * @test + */ + public function itCanCallMakeExistCommandSeeder() + { + app()->setSeederPath(__DIR__ . '//database//seeders//'); + $makeCommand = new SeedCommand($this->argv('cli make:seed ExistSeeder --force')); + ob_start(); + $exit = $makeCommand->make(); + ob_get_clean(); + + $this->assertSuccess($exit); + + $file = __DIR__ . '//database//seeders//ExistSeeder.php'; + $this->assertTrue(file_exists($file)); + + $class = file_get_contents($file); + $this->assertContain('class ExistSeeder extends Seeder', $class, 'Stub test'); + $this->assertContain('public function run(): void', $class, 'Stub test'); + } } diff --git a/tests/Integrate/Commands/database/seeders/BasicSeeder.php b/tests/Integrate/Commands/database/seeders/BasicSeeder.php index d932af9e..465ba895 100644 --- a/tests/Integrate/Commands/database/seeders/BasicSeeder.php +++ b/tests/Integrate/Commands/database/seeders/BasicSeeder.php @@ -1,6 +1,6 @@