diff --git a/README.md b/README.md index 545e51f..3d66876 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ The Xeed is to generate new model, seed, database seed, factory and migration fi > [!TIP] > It can function as both `php artisan xeed:*` commands for Laravel and `bin/console *` commands for Standalone, providing 100% identical functionality. Therefore, you can use it within your own Laravel project or as a standalone application. -We have provided the API Documentation on the web. For more information, please visit https://www.palgle.com/xeed/ ❤️ +We have provided the API Documentation on the web. For more information, please visit ❤️ ### Features @@ -76,11 +76,17 @@ composer create-project cable8mm/xeed ```shell tab=Laravel php artisan xeed:models # Generate all models from database in `app/Models` folder + +php artisan xeed:models -f -t xeeds +# Force to generate a model from `xeeds` table in `app/Models` folder ``` ```shell tab=Standalone bin/console models # Generate all models from database in `dist/app/Models` folder + +bin/console models -f -t xeeds +# Force to generate a model from `xeeds` table in `app/Models` folder ``` ### Generate `Seeders` @@ -88,11 +94,17 @@ bin/console models ```shell tab=Laravel php artisan xeed:seeders # Generate all seeds from database in `database/seeders` folder + +php artisan xeed:seeders -f -t xeeds +# Force to generate a seeder from `xeeds` table in `database/seeders` folder ``` ```shell tab=Standalone bin/console seeders # Generate all seeds from database in `dist/database/seeders` folder + +bin/console seeders -f -t xeeds +# Force to generate a seeder from `xeeds` table in `dist/database/seeders` folder ``` ### Generate `DatabaseSeeder` @@ -112,11 +124,17 @@ bin/console database ```shell tab=Laravel php artisan xeed:factories # Generate all factories from database in `database/factories' folder + +php artisan xeed:factories -f -t xeeds +# Force to generate a factory from `xeeds` table in `database/factories' folder ``` ```shell tab=Standalone bin/console factories # Generate all factories from database in `dist/database/factories' folder + +bin/console factories -f -t xeeds +# Force to generate a factory from `xeeds` table in `database/factories' folder ``` ### Generate `Migrations` @@ -124,11 +142,17 @@ bin/console factories ```shell tab=Laravel php artisan xeed:migrations # Generate all migrations from database in `database/migrations' folder + +php artisan xeed:migrations -f -t xeeds +# Force to generate a migration from `xeeds` table in `database/migrations' folder ``` ```shell tab=Standalone bin/console migrations # Generate all migrations from database in `dist/database/migrations' folder + +bin/console migrations -f -t xeeds +# Force to generate a migration from `xeeds` table in `database/migrations' folder ``` The generated files are stored in the same folder as your Laravel project. Please check the `dist` folder. diff --git a/src/Command/GenerateFactoriesCommand.php b/src/Command/GenerateFactoriesCommand.php index b0ec6c2..0d9ecbf 100644 --- a/src/Command/GenerateFactoriesCommand.php +++ b/src/Command/GenerateFactoriesCommand.php @@ -20,7 +20,7 @@ name: 'generate-factories', description: 'Generate factories. run `bin/console generate-factories` or `bin/console factories`', hidden: false, - aliases: ['factories'] + aliases: ['factories', 'factory'] )] class GenerateFactoriesCommand extends Command { @@ -39,6 +39,12 @@ protected function configure(): void InputOption::VALUE_OPTIONAL, 'Are files forcibly deleted even if they exist?', false + )->addOption( + 'table', + 't', + InputOption::VALUE_OPTIONAL, + 'Are you generating the specific table with the factory?', + null ); } @@ -49,7 +55,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int { $force = $input->getOption('force') ?? true; - $tables = Xeed::getInstance()->attach()->getTables(); + $table = $input->getOption('table'); + + $tables = is_null($table) + ? Xeed::getInstance()->attach()->getTables() + : Xeed::getInstance()->attach($table)->getTables(); foreach ($tables as $table) { try { diff --git a/src/Command/GenerateMigrationsCommand.php b/src/Command/GenerateMigrationsCommand.php index 8bdea1e..b8cbf8c 100644 --- a/src/Command/GenerateMigrationsCommand.php +++ b/src/Command/GenerateMigrationsCommand.php @@ -21,7 +21,7 @@ name: 'generate-migrations', description: 'Generate migrations. run `bin/console generate-migrations` or `bin/console migrations`', hidden: false, - aliases: ['migrations'] + aliases: ['migrations', 'migration'] )] class GenerateMigrationsCommand extends Command { @@ -40,6 +40,12 @@ protected function configure(): void InputOption::VALUE_OPTIONAL, 'Are files forcibly deleted even if they exist?', false + )->addOption( + 'table', + 't', + InputOption::VALUE_OPTIONAL, + 'Are you generating the specific table with the migration?', + null ); } @@ -50,7 +56,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int { $force = $input->getOption('force') ?? true; - $tables = Xeed::getInstance()->attach()->getTables(); + $table = $input->getOption('table'); + + $tables = is_null($table) + ? Xeed::getInstance()->attach()->getTables() + : Xeed::getInstance()->attach($table)->getTables(); foreach ($tables as $table) { try { diff --git a/src/Command/GenerateModelsCommand.php b/src/Command/GenerateModelsCommand.php index 3975272..329ca8b 100644 --- a/src/Command/GenerateModelsCommand.php +++ b/src/Command/GenerateModelsCommand.php @@ -20,7 +20,7 @@ name: 'generate-models', description: 'Generate models. run `bin/console generate-models` or `bin/console models`', hidden: false, - aliases: ['models'] + aliases: ['models', 'model'] )] class GenerateModelsCommand extends Command { @@ -39,6 +39,12 @@ protected function configure(): void InputOption::VALUE_OPTIONAL, 'Are files forcibly deleted even if they exist?', false + )->addOption( + 'table', + 't', + InputOption::VALUE_OPTIONAL, + 'Are you generating the specific table with the model?', + null ); } @@ -49,7 +55,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int { $force = $input->getOption('force') ?? true; - $tables = Xeed::getInstance()->attach()->getTables(); + $table = $input->getOption('table'); + + $tables = is_null($table) + ? Xeed::getInstance()->attach()->getTables() + : Xeed::getInstance()->attach($table)->getTables(); foreach ($tables as $table) { try { diff --git a/src/Command/GenerateSeedersCommand.php b/src/Command/GenerateSeedersCommand.php index 1780dbd..f30d59c 100644 --- a/src/Command/GenerateSeedersCommand.php +++ b/src/Command/GenerateSeedersCommand.php @@ -20,7 +20,7 @@ name: 'generate-seeders', description: 'Generate seeders. run `bin/console generate-seeders` or `bin/console seeders`', hidden: false, - aliases: ['seeders'] + aliases: ['seeders', 'seeder'] )] class GenerateSeedersCommand extends Command { @@ -39,6 +39,12 @@ protected function configure(): void InputOption::VALUE_OPTIONAL, 'Are files forcibly deleted even if they exist?', false + )->addOption( + 'table', + 't', + InputOption::VALUE_OPTIONAL, + 'Are you generating the specific table with the seed?', + null ); } @@ -49,7 +55,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int { $force = $input->getOption('force') ?? true; - $tables = Xeed::getInstance()->attach()->getTables(); + $table = $input->getOption('table'); + + $tables = is_null($table) + ? Xeed::getInstance()->attach()->getTables() + : Xeed::getInstance()->attach($table)->getTables(); foreach ($tables as $table) { try { diff --git a/src/Interfaces/ProviderInterface.php b/src/Interfaces/ProviderInterface.php index 3774de0..8379cf7 100644 --- a/src/Interfaces/ProviderInterface.php +++ b/src/Interfaces/ProviderInterface.php @@ -13,8 +13,9 @@ interface ProviderInterface * Attach child provider to DB instance. * * @param \Cable8mm\Xeed\Xeed $xeed Xeed instance + * @param string $table The table name to attach child provider */ - public function attach(Xeed $xeed): void; + public function attach(Xeed $xeed, ?string $table = null): void; /** * Do mapping method between another fields for Database. diff --git a/src/Laravel/Commands/GenerateFactoriesCommand.php b/src/Laravel/Commands/GenerateFactoriesCommand.php index 4ebcc98..6942ad3 100644 --- a/src/Laravel/Commands/GenerateFactoriesCommand.php +++ b/src/Laravel/Commands/GenerateFactoriesCommand.php @@ -14,7 +14,9 @@ class GenerateFactoriesCommand extends Command * * @var string */ - protected $signature = 'xeed:factories {force=false}'; + protected $signature = 'xeed:factories + {force=false : Are files forcibly deleted even if they exist?} + {--t|table= : Are you generating the specific table with the factory?}'; /** * The console command description. @@ -30,9 +32,11 @@ public function handle(Xeed $xeed) { $force = $this->argument('force'); - $tables = $xeed->addPdo( - DB::connection()->getPDO() - )->attach()->getTables(); + $table = $this->option('table'); + + $tables = is_null($table) + ? $xeed->addPdo(DB::connection()->getPDO())->attach()->getTables() + : $xeed->addPdo(DB::connection()->getPDO())->attach($table)->getTables(); foreach ($tables as $table) { try { diff --git a/src/Laravel/Commands/GenerateMigrationsCommand.php b/src/Laravel/Commands/GenerateMigrationsCommand.php index dfc57ea..a9cd45e 100644 --- a/src/Laravel/Commands/GenerateMigrationsCommand.php +++ b/src/Laravel/Commands/GenerateMigrationsCommand.php @@ -15,7 +15,9 @@ class GenerateMigrationsCommand extends Command * * @var string */ - protected $signature = 'xeed:migrations {force=false}'; + protected $signature = 'xeed:migrations + {force=false : Are files forcibly deleted even if they exist?} + {--t|table= : Are you generating the specific table with the migration?}'; /** * The console command description. @@ -31,9 +33,11 @@ public function handle(Xeed $xeed) { $force = $this->argument('force'); - $tables = $xeed->addPdo( - DB::connection()->getPDO() - )->attach()->getTables(); + $table = $this->option('table'); + + $tables = is_null($table) + ? $xeed->addPdo(DB::connection()->getPDO())->attach()->getTables() + : $xeed->addPdo(DB::connection()->getPDO())->attach($table)->getTables(); foreach ($tables as $table) { try { diff --git a/src/Laravel/Commands/GenerateModelsCommand.php b/src/Laravel/Commands/GenerateModelsCommand.php index e05881a..d852dc5 100644 --- a/src/Laravel/Commands/GenerateModelsCommand.php +++ b/src/Laravel/Commands/GenerateModelsCommand.php @@ -14,7 +14,9 @@ class GenerateModelsCommand extends Command * * @var string */ - protected $signature = 'xeed:models {force=false}'; + protected $signature = 'xeed:models + {force=false : Are files forcibly deleted even if they exist?} + {--t|table= : Are you generating the specific table with the model?}'; /** * The console command description. @@ -30,9 +32,11 @@ public function handle(Xeed $xeed) { $force = $this->argument('force'); - $tables = $xeed->addPdo( - DB::connection()->getPDO() - )->attach()->getTables(); + $table = $this->option('table'); + + $tables = is_null($table) + ? $xeed->addPdo(DB::connection()->getPDO())->attach()->getTables() + : $xeed->addPdo(DB::connection()->getPDO())->attach($table)->getTables(); foreach ($tables as $table) { try { diff --git a/src/Laravel/Commands/GenerateSeedersCommand.php b/src/Laravel/Commands/GenerateSeedersCommand.php index b97c9ec..55684e9 100644 --- a/src/Laravel/Commands/GenerateSeedersCommand.php +++ b/src/Laravel/Commands/GenerateSeedersCommand.php @@ -14,7 +14,9 @@ class GenerateSeedersCommand extends Command * * @var string */ - protected $signature = 'xeed:seeders {force=false}'; + protected $signature = 'xeed:seeders + {force=false : Are files forcibly deleted even if they exist?} + {--t|table= : Are you generating the specific table with the seeder?}'; /** * The console command description. @@ -30,9 +32,11 @@ public function handle(Xeed $xeed) { $force = $this->argument('force'); - $tables = $xeed->addPdo( - DB::connection()->getPDO() - )->attach()->getTables(); + $table = $this->option('table'); + + $tables = is_null($table) + ? $xeed->addPdo(DB::connection()->getPDO())->attach()->getTables() + : $xeed->addPdo(DB::connection()->getPDO())->attach($table)->getTables(); foreach ($tables as $table) { try { diff --git a/src/Provider/MysqlProvider.php b/src/Provider/MysqlProvider.php index e551963..586417d 100644 --- a/src/Provider/MysqlProvider.php +++ b/src/Provider/MysqlProvider.php @@ -16,9 +16,11 @@ final class MysqlProvider implements ProviderInterface /** * {@inheritDoc} */ - public function attach(Xeed $xeed): void + public function attach(Xeed $xeed, ?string $table = null): void { - $tables = $xeed->pdo->query('SHOW TABLES')->fetchAll(PDO::FETCH_COLUMN); + $tables = is_null($table) + ? $xeed->pdo->query('SHOW TABLES')->fetchAll(PDO::FETCH_COLUMN) + : [$table]; foreach ($tables as $table) { $columns = $xeed->pdo->query('SHOW COLUMNS FROM '.$table)->fetchAll(PDO::FETCH_ASSOC); diff --git a/src/Provider/PgsqlProvider.php b/src/Provider/PgsqlProvider.php index f8d74a6..12307fb 100644 --- a/src/Provider/PgsqlProvider.php +++ b/src/Provider/PgsqlProvider.php @@ -16,9 +16,11 @@ final class PgsqlProvider implements ProviderInterface /** * {@inheritDoc} */ - public function attach(Xeed $xeed): void + public function attach(Xeed $xeed, ?string $table = null): void { - $tables = $xeed->pdo->query('SELECT table_name FROM information_schema.tables WHERE table_schema = \'public\' ORDER BY table_name')->fetchAll(PDO::FETCH_COLUMN); + $tables = is_null($table) + ? $xeed->pdo->query('SELECT table_name FROM information_schema.tables WHERE table_schema = \'public\' ORDER BY table_name')->fetchAll(PDO::FETCH_COLUMN) + : [$table]; $tables = array_diff($tables, [ 'geography_columns', diff --git a/src/Provider/SqliteProvider.php b/src/Provider/SqliteProvider.php index 5895f8d..5850910 100644 --- a/src/Provider/SqliteProvider.php +++ b/src/Provider/SqliteProvider.php @@ -17,17 +17,23 @@ final class SqliteProvider implements ProviderInterface /** * {@inheritDoc} */ - public function attach(Xeed $xeed): void + public function attach(Xeed $xeed, ?string $table = null): void { - $query = $xeed->pdo->query("SELECT name FROM sqlite_master WHERE type='table';"); + if (is_null($table)) { + $query = $xeed->pdo->query("SELECT name FROM sqlite_master WHERE type='table';"); - $tables = array_filter($query->fetchAll(), fn ($item) => $item['name'] !== 'sqlite_sequence'); + $tables = array_filter($query->fetchAll(), fn ($item) => $item['name'] !== 'sqlite_sequence'); - $tables = array_flatten($tables); + $tables = array_flatten($tables); + } else { + $tables = [$table]; + } foreach ($tables as $table) { $columns = $xeed->pdo->query('SELECT * FROM PRAGMA_TABLE_INFO("'.$table.'");')->fetchAll(); + $columnObject = []; + foreach ($columns as $column) { $columnObject[] = new Column(...self::map($column, $table, $xeed)); } diff --git a/src/Support/Path.php b/src/Support/Path.php index 1a77c6c..86dad9d 100644 --- a/src/Support/Path.php +++ b/src/Support/Path.php @@ -16,7 +16,7 @@ final class Path */ public static function stub(): string { - return __DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'stubs'; + return realpath(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'stubs'); } /** @@ -28,7 +28,7 @@ public static function stub(): string */ public static function model(): string { - return __DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'dist'.DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'Models'; + return realpath(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'dist'.DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'Models'); } /** @@ -40,7 +40,7 @@ public static function model(): string */ public static function seeder(): string { - return __DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'dist'.DIRECTORY_SEPARATOR.'database'.DIRECTORY_SEPARATOR.'seeders'; + return realpath(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'dist'.DIRECTORY_SEPARATOR.'database'.DIRECTORY_SEPARATOR.'seeders'); } /** @@ -52,7 +52,7 @@ public static function seeder(): string */ public static function factory(): string { - return __DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'dist'.DIRECTORY_SEPARATOR.'database'.DIRECTORY_SEPARATOR.'factories'; + return realpath(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'dist'.DIRECTORY_SEPARATOR.'database'.DIRECTORY_SEPARATOR.'factories'); } /** @@ -64,7 +64,7 @@ public static function factory(): string */ public static function database(): string { - return __DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'database'; + return realpath(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'database'); } /** @@ -76,7 +76,7 @@ public static function database(): string */ public static function migration(): string { - return __DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'dist'.DIRECTORY_SEPARATOR.'database'.DIRECTORY_SEPARATOR.'migrations'; + return realpath(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'dist'.DIRECTORY_SEPARATOR.'database'.DIRECTORY_SEPARATOR.'migrations'); } /** @@ -88,7 +88,7 @@ public static function migration(): string */ public static function resource(): string { - return __DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'resources'; + return realpath(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'resources'); } /** @@ -98,7 +98,7 @@ public static function resource(): string */ public static function root(): string { - return __DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'; + return realpath(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'); } /** @@ -108,7 +108,7 @@ public static function root(): string */ public static function testBootstrap(): string { - return __DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'tests'.DIRECTORY_SEPARATOR.'Bootstrap'; + return realpath(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'tests'.DIRECTORY_SEPARATOR.'Bootstrap'); } /** @@ -120,6 +120,6 @@ public static function testBootstrap(): string */ public static function testgen(): string { - return __DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'tests'.DIRECTORY_SEPARATOR.'Generate'; + return realpath(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'tests'.DIRECTORY_SEPARATOR.'Generate'); } } diff --git a/src/Table.php b/src/Table.php index a3c76de..7512d97 100644 --- a/src/Table.php +++ b/src/Table.php @@ -3,6 +3,7 @@ namespace Cable8mm\Xeed; use Cable8mm\Xeed\Support\Inflector; +use LogicException; use Stringable; /** @@ -28,8 +29,10 @@ final class Table implements Stringable * @param string $name Table name * @param array<\Cable8mm\Xeed\Table> $columns Column array[Table] */ - public function __construct(string $name, array $columns = []) + public function __construct(string $name, ?array $columns = []) { + assert(! empty($columns), new LogicException('Columns must not be empty')); + $this->name = $name; $this->columns = $columns; diff --git a/src/Xeed.php b/src/Xeed.php index ef08ae5..af9d691 100644 --- a/src/Xeed.php +++ b/src/Xeed.php @@ -185,11 +185,12 @@ public static function getNewInstance(): static /** * Attach tables and columns. * + * @param string $table The table name to attach child provider * @return static The method returns the instance for chaining */ - public function attach(): static + public function attach(?string $table = null): static { - $this->provider->attach($this); + $this->provider->attach($this, $table); return $this; } diff --git a/tests/Laravel/Commands/GenerateFactoriesCommandTest.php b/tests/Laravel/Commands/GenerateFactoriesCommandTest.php index 077a897..95e9f7a 100644 --- a/tests/Laravel/Commands/GenerateFactoriesCommandTest.php +++ b/tests/Laravel/Commands/GenerateFactoriesCommandTest.php @@ -9,6 +9,11 @@ public function test_execute_xeed_database_command() $this->artisan('xeed:factories')->assertSuccessful(); } + public function test_execute_xeed_database_command_with_table() + { + $this->artisan('xeed:factories -t xeeds')->assertSuccessful(); + } + protected function getPackageProviders($app) { return [ diff --git a/tests/Laravel/Commands/GenerateMigrationsCommandTest.php b/tests/Laravel/Commands/GenerateMigrationsCommandTest.php index 9cb75fc..c30ea1e 100644 --- a/tests/Laravel/Commands/GenerateMigrationsCommandTest.php +++ b/tests/Laravel/Commands/GenerateMigrationsCommandTest.php @@ -9,6 +9,11 @@ public function test_execute_xeed_database_command() $this->artisan('xeed:migrations')->assertSuccessful(); } + public function test_execute_xeed_database_command_with_table() + { + $this->artisan('xeed:migrations -t xeeds')->assertSuccessful(); + } + protected function getPackageProviders($app) { return [ diff --git a/tests/Laravel/Commands/GenerateModelsCommandTest.php b/tests/Laravel/Commands/GenerateModelsCommandTest.php index 4fd0f14..2620d19 100644 --- a/tests/Laravel/Commands/GenerateModelsCommandTest.php +++ b/tests/Laravel/Commands/GenerateModelsCommandTest.php @@ -9,6 +9,11 @@ public function test_execute_xeed_database_command() $this->artisan('xeed:models')->assertSuccessful(); } + public function test_execute_xeed_database_command_with_table() + { + $this->artisan('xeed:models -t xeeds')->assertSuccessful(); + } + protected function getPackageProviders($app) { return [ diff --git a/tests/Laravel/Commands/GenerateSeedersCommandTest.php b/tests/Laravel/Commands/GenerateSeedersCommandTest.php index 8f514e8..dca9555 100644 --- a/tests/Laravel/Commands/GenerateSeedersCommandTest.php +++ b/tests/Laravel/Commands/GenerateSeedersCommandTest.php @@ -9,6 +9,11 @@ public function test_execute_xeed_database_command() $this->artisan('xeed:seeders')->assertSuccessful(); } + public function test_execute_xeed_database_command_with_table() + { + $this->artisan('xeed:seeders -t xeeds')->assertSuccessful(); + } + protected function getPackageProviders($app) { return [ diff --git a/tests/Unit/Command/GenerateFactoriesCommandTest.php b/tests/Unit/Command/GenerateFactoriesCommandTest.php index 1f36f42..b220d94 100644 --- a/tests/Unit/Command/GenerateFactoriesCommandTest.php +++ b/tests/Unit/Command/GenerateFactoriesCommandTest.php @@ -25,4 +25,15 @@ public function test_execute(): void $this->assertStringContainsString('generate-factories command executed successfully.', trim($this->commandTester->getDisplay())); } + + public function test_execute_with_a_table(): void + { + $this->commandTester->execute([ + '--force' => true, + ], [ + '--table' => 'xeeds', + ]); + + $this->assertStringContainsString('generate-factories command executed successfully.', trim($this->commandTester->getDisplay())); + } } diff --git a/tests/Unit/Command/GenerateMigrationsCommandTest.php b/tests/Unit/Command/GenerateMigrationsCommandTest.php index 2743a7f..4098789 100644 --- a/tests/Unit/Command/GenerateMigrationsCommandTest.php +++ b/tests/Unit/Command/GenerateMigrationsCommandTest.php @@ -25,4 +25,15 @@ public function test_execute(): void $this->assertStringContainsString('generate-migrations command executed successfully.', trim($this->commandTester->getDisplay())); } + + public function test_execute_with_a_table(): void + { + $this->commandTester->execute([ + '--force' => true, + ], [ + '--table' => 'xeeds', + ]); + + $this->assertStringContainsString('generate-migrations command executed successfully.', trim($this->commandTester->getDisplay())); + } } diff --git a/tests/Unit/Command/GenerateModelsCommandTest.php b/tests/Unit/Command/GenerateModelsCommandTest.php index 5d75be5..2e86c4c 100644 --- a/tests/Unit/Command/GenerateModelsCommandTest.php +++ b/tests/Unit/Command/GenerateModelsCommandTest.php @@ -25,4 +25,15 @@ public function test_execute(): void $this->assertStringContainsString('generate-models command executed successfully.', trim($this->commandTester->getDisplay())); } + + public function test_execute_with_a_table(): void + { + $this->commandTester->execute([ + '--force' => true, + ], [ + '--table' => 'xeeds', + ]); + + $this->assertStringContainsString('generate-models command executed successfully.', trim($this->commandTester->getDisplay())); + } } diff --git a/tests/Unit/Command/GenerateSeedersCommandTest.php b/tests/Unit/Command/GenerateSeedersCommandTest.php index d5cb82a..152d290 100644 --- a/tests/Unit/Command/GenerateSeedersCommandTest.php +++ b/tests/Unit/Command/GenerateSeedersCommandTest.php @@ -21,7 +21,20 @@ protected function setUp(): void public function test_execute(): void { - $this->commandTester->execute([]); + $this->commandTester->execute([ + '--force' => true, + ]); + + $this->assertStringContainsString('generate-seeders command executed successfully.', trim($this->commandTester->getDisplay())); + } + + public function test_execute_with_a_table(): void + { + $this->commandTester->execute([ + '--force' => true, + ], [ + '--table' => 'xeeds', + ]); $this->assertStringContainsString('generate-seeders command executed successfully.', trim($this->commandTester->getDisplay())); } diff --git a/tests/Unit/Generators/DatabaseSeederGeneratorTest.php b/tests/Unit/Generators/DatabaseSeederGeneratorTest.php index eb68801..d3fa431 100644 --- a/tests/Unit/Generators/DatabaseSeederGeneratorTest.php +++ b/tests/Unit/Generators/DatabaseSeederGeneratorTest.php @@ -2,6 +2,7 @@ namespace Cable8mm\Xeed\Tests\Unit\Generators; +use Cable8mm\Xeed\Column; use Cable8mm\Xeed\Generators\DatabaseSeederGenerator; use Cable8mm\Xeed\Support\File; use Cable8mm\Xeed\Support\Path; @@ -14,8 +15,12 @@ protected function setUp(): void { DatabaseSeederGenerator::make( [ - new Table('one_samples'), - new Table('two_samples'), + new Table('one_samples', [ + Column::make('id', 'bigint'), + ]), + new Table('two_samples', [ + Column::make('id', 'bigint'), + ]), ], destination: Path::testgen() )->run(); diff --git a/tests/Unit/Generators/ModelGeneratorTest.php b/tests/Unit/Generators/ModelGeneratorTest.php index 5239e0b..cde261c 100644 --- a/tests/Unit/Generators/ModelGeneratorTest.php +++ b/tests/Unit/Generators/ModelGeneratorTest.php @@ -2,6 +2,7 @@ namespace Cable8mm\Xeed\Tests\Unit\Generators; +use Cable8mm\Xeed\Column; use Cable8mm\Xeed\Generators\ModelGenerator; use Cable8mm\Xeed\Support\File; use Cable8mm\Xeed\Support\Path; @@ -13,7 +14,9 @@ final class ModelGeneratorTest extends TestCase protected function setUp(): void { ModelGenerator::make( - new Table('samples'), + new Table('samples', [ + Column::make('id', 'bigint'), + ]), destination: Path::testgen() )->run(); } diff --git a/tests/Unit/Generators/SeederGeneratorTest.php b/tests/Unit/Generators/SeederGeneratorTest.php index d8cc8d1..0ce6896 100644 --- a/tests/Unit/Generators/SeederGeneratorTest.php +++ b/tests/Unit/Generators/SeederGeneratorTest.php @@ -2,6 +2,7 @@ namespace Cable8mm\Xeed\Tests\Unit\Generators; +use Cable8mm\Xeed\Column; use Cable8mm\Xeed\Generators\SeederGenerator; use Cable8mm\Xeed\Support\File; use Cable8mm\Xeed\Support\Path; @@ -13,7 +14,9 @@ final class SeederGeneratorTest extends TestCase protected function setUp(): void { SeederGenerator::make( - new Table('samples'), + new Table('samples', [ + Column::make('id', 'bigint'), + ]), destination: Path::testgen() )->run(); }