From 89869a815406dae6709ca3fc2fff1945287e0754 Mon Sep 17 00:00:00 2001 From: Alexander Gaal Date: Tue, 15 Aug 2023 10:47:49 -0700 Subject: [PATCH] Add force tests --- src/Commands/MakeModuleCommand.php | 3 +- tests/Commands/MakeActionCommandTest.php | 17 +++++ tests/Commands/MakeBuilderCommandTest.php | 16 +++++ tests/Commands/MakeCollectionCommandTest.php | 40 ++++++++++++ tests/Commands/MakeCommandCommandTest.php | 31 +++++++++ tests/Commands/MakeControllerCommandTest.php | 54 +++++++++++++++ .../MakeDataTransferObjectCommandTest.php | 32 +++++++++ tests/Commands/MakeEnumCommandTest.php | 16 +++++ tests/Commands/MakeEventCommandTest.php | 16 +++++ tests/Commands/MakeJobCommandTest.php | 34 ++++++++++ tests/Commands/MakeListenerCommandTest.php | 16 +++++ tests/Commands/MakeMiddlewareCommandTest.php | 16 +++++ tests/Commands/MakeMigrationCommandTest.php | 53 +++++++++++++++ tests/Commands/MakeModelCommandTest.php | 65 ++++++++++++++++++- tests/Commands/MakeModuleCommandTest.php | 55 +++++++++++++--- .../Commands/MakeNotificationCommandTest.php | 16 +++++ tests/Commands/MakeObserverCommandTest.php | 16 +++++ tests/Commands/MakePolicyCommandTest.php | 35 ++++++++++ tests/Commands/MakeQueryCommandTest.php | 39 +++++++++++ tests/Commands/MakeRequestCommandTest.php | 16 +++++ tests/Commands/MakeResourceCommandTest.php | 16 +++++ tests/Commands/MakeRuleCommandTest.php | 18 ++++- .../MakeServiceProviderCommandTest.php | 15 +++++ 23 files changed, 622 insertions(+), 13 deletions(-) diff --git a/src/Commands/MakeModuleCommand.php b/src/Commands/MakeModuleCommand.php index 7fb4c6e..ac93fc0 100644 --- a/src/Commands/MakeModuleCommand.php +++ b/src/Commands/MakeModuleCommand.php @@ -30,7 +30,8 @@ public function handle(): void $this->copyDirectoryAction->execute( __DIR__.'/../../stubs/Module', - beyond_modules_path($module) + beyond_modules_path($module), + $force, ); $this->moveAndRefactorModuleFiles($module, $force); diff --git a/tests/Commands/MakeActionCommandTest.php b/tests/Commands/MakeActionCommandTest.php index b928da0..b224ff3 100644 --- a/tests/Commands/MakeActionCommandTest.php +++ b/tests/Commands/MakeActionCommandTest.php @@ -2,6 +2,7 @@ namespace Tests\Commands; +use Illuminate\Testing\PendingCommand; use Tests\TestCase; class MakeActionCommandTest extends TestCase @@ -24,4 +25,20 @@ public function testCanMakeAction(): void $this->assertStringNotContainsString('{{ namespace }}', $contents); $this->assertStringNotContainsString('{{ className }}', $contents); } + + public function testCanMakeActionUsingForce(): void + { + $this->artisan('beyond:make:action User.UserStoreAction'); + + $file = beyond_modules_path('User/Domain/Actions/UserStoreAction.php'); + $contents = file_get_contents($file); + + $this->assertFileExists($file); + $this->assertStringNotContainsString('{{ namespace }}', $contents); + $this->assertStringNotContainsString('{{ className }}', $contents); + + $code = $this->artisan('beyond:make:action User.UserStoreAction --force'); + + $code->assertOk(); + } } diff --git a/tests/Commands/MakeBuilderCommandTest.php b/tests/Commands/MakeBuilderCommandTest.php index 461d1e1..8882273 100644 --- a/tests/Commands/MakeBuilderCommandTest.php +++ b/tests/Commands/MakeBuilderCommandTest.php @@ -24,4 +24,20 @@ public function testCanMakeBuilder(): void $this->assertStringNotContainsString('{{ namespace }}', $contents); $this->assertStringNotContainsString('{{ className }}', $contents); } + + public function testCanMakeBuilderUsingForce(): void + { + $this->artisan('beyond:make:builder User.UserBuilder'); + + $file = beyond_modules_path('User/Domain/Builders/UserBuilder.php'); + $contents = file_get_contents($file); + + $this->assertFileExists($file); + $this->assertStringNotContainsString('{{ namespace }}', $contents); + $this->assertStringNotContainsString('{{ className }}', $contents); + + $code = $this->artisan('beyond:make:builder User.UserBuilder --force'); + + $code->assertOk(); + } } diff --git a/tests/Commands/MakeCollectionCommandTest.php b/tests/Commands/MakeCollectionCommandTest.php index aa92d12..4198cc1 100644 --- a/tests/Commands/MakeCollectionCommandTest.php +++ b/tests/Commands/MakeCollectionCommandTest.php @@ -25,6 +25,24 @@ public function testCanMakeCollection(): void $this->assertStringNotContainsString('{{ className }}', $contents); } + + + public function testCanMakeCollectionUsingForce(): void + { + $this->artisan('beyond:make:collection User.UserCollection'); + + $file = beyond_modules_path('User/Domain/Collections/UserCollection.php'); + $contents = file_get_contents($file); + + $this->assertFileExists($file); + $this->assertStringNotContainsString('{{ namespace }}', $contents); + $this->assertStringNotContainsString('{{ className }}', $contents); + + $code = $this->artisan('beyond:make:collection User.UserCollection --force'); + + $code->assertOk(); + } + public function testCanMakeCollectionWithModel(): void { $this->artisan('beyond:make:collection User.UserCollection --model=User'); @@ -43,4 +61,26 @@ public function testCanMakeCollectionWithModel(): void $this->assertStringNotContainsString('{{ namespace }}', $contents); $this->assertStringNotContainsString('{{ className }}', $contents); } + + public function testCanMakeCollectionWithModelUsingForce(): void + { + $this->artisan('beyond:make:collection User.UserCollection --model=User'); + + $file = beyond_modules_path('User/Domain/Collections/UserCollection.php'); + $contents = file_get_contents($file); + + $this->assertFileExists($file); + $this->assertStringNotContainsString('{{ namespace }}', $contents); + $this->assertStringNotContainsString('{{ className }}', $contents); + + $file = beyond_modules_path('User/Domain/Models/User.php'); + $contents = file_get_contents($file); + + $this->assertFileExists($file); + $this->assertStringNotContainsString('{{ namespace }}', $contents); + $this->assertStringNotContainsString('{{ className }}', $contents); + + $code = $this->artisan('beyond:make:collection User.UserCollection --model=User --force'); + $code->assertOk(); + } } diff --git a/tests/Commands/MakeCommandCommandTest.php b/tests/Commands/MakeCommandCommandTest.php index 0e565a7..2a0a9d6 100644 --- a/tests/Commands/MakeCommandCommandTest.php +++ b/tests/Commands/MakeCommandCommandTest.php @@ -25,6 +25,21 @@ public function testCanMakeCommand(): void $this->assertStringNotContainsString('{{ className }}', $contents); } + public function testCanMakeCommandUsingForce(): void + { + $this->artisan('beyond:make:command User.CreateUser'); + + $file = beyond_modules_path('User/App/Commands/CreateUser.php'); + $contents = file_get_contents($file); + + $this->assertFileExists($file); + $this->assertStringNotContainsString('{{ namespace }}', $contents); + $this->assertStringNotContainsString('{{ className }}', $contents); + + $code = $this->artisan('beyond:make:command User.CreateUser --force'); + $code->assertOk(); + } + public function testCanMakeCommandWithPredefinedSignature(): void { $this->artisan('beyond:make:command User.CreateUser --command=test:execute'); @@ -37,4 +52,20 @@ public function testCanMakeCommandWithPredefinedSignature(): void $this->assertStringNotContainsString('{{ className }}', $contents); $this->assertStringContainsString('test:execute', $contents); } + + public function testCanMakeCommandWithPredefinedSignatureUsingForce(): void + { + $this->artisan('beyond:make:command User.CreateUser --command=test:execute'); + + $file = beyond_modules_path('User/App/Commands/CreateUser.php'); + $contents = file_get_contents($file); + + $this->assertFileExists($file); + $this->assertStringNotContainsString('{{ namespace }}', $contents); + $this->assertStringNotContainsString('{{ className }}', $contents); + $this->assertStringContainsString('test:execute', $contents); + + $code = $this->artisan('beyond:make:command User.CreateUser --command=test:execute --force'); + $code->assertOk(); + } } diff --git a/tests/Commands/MakeControllerCommandTest.php b/tests/Commands/MakeControllerCommandTest.php index ca313e3..6c0ee7a 100644 --- a/tests/Commands/MakeControllerCommandTest.php +++ b/tests/Commands/MakeControllerCommandTest.php @@ -25,6 +25,21 @@ public function testCanMakeController(): void $this->assertStringNotContainsString('{{ className }}', $contents); } + public function testCanMakeControllerUsingForce(): void + { + $this->artisan('beyond:make:controller User.UserController'); + + $file = beyond_modules_path('User/App/Controllers/UserController.php'); + $contents = file_get_contents($file); + + $this->assertFileExists($file); + $this->assertStringNotContainsString('{{ namespace }}', $contents); + $this->assertStringNotContainsString('{{ className }}', $contents); + + $code = $this->artisan('beyond:make:controller User.UserController'); + $code->assertOk(); + } + public function testCanMakeApiController(): void { $this->artisan('beyond:make:controller User.UserController --api'); @@ -43,6 +58,28 @@ public function testCanMakeApiController(): void } } + public function testCanMakeApiControllerUsingForce(): void + { + $this->artisan('beyond:make:controller User.UserController --api'); + + $file = beyond_modules_path('User/App/Controllers/UserController.php'); + $contents = file_get_contents($file); + + $this->assertFileExists($file); + $this->assertStringNotContainsString('{{ namespace }}', $contents); + $this->assertStringNotContainsString('{{ className }}', $contents); + + $methods = ['index()', 'show()', 'store()', 'update()', 'destroy()']; + + foreach ($methods as $method) { + $this->assertStringContainsString($method, $contents); + } + + $code = $this->artisan('beyond:make:controller User.UserController --api --force'); + + $code->assertOk(); + } + public function testCanMakeInvokableController(): void { $this->artisan('beyond:make:controller User.UserController --invokable'); @@ -55,4 +92,21 @@ public function testCanMakeInvokableController(): void $this->assertStringNotContainsString('{{ className }}', $contents); $this->assertStringContainsString('__invoke()', $contents); } + + public function testCanMakeInvokableControllerUsingForce(): void + { + $this->artisan('beyond:make:controller User.UserController --invokable'); + + $file = beyond_modules_path('User/App/Controllers/UserController.php'); + $contents = file_get_contents($file); + + $this->assertFileExists($file); + $this->assertStringNotContainsString('{{ namespace }}', $contents); + $this->assertStringNotContainsString('{{ className }}', $contents); + $this->assertStringContainsString('__invoke()', $contents); + + $code = $this->artisan('beyond:make:controller User.UserController --invokable --force'); + + $code->assertOk(); + } } diff --git a/tests/Commands/MakeDataTransferObjectCommandTest.php b/tests/Commands/MakeDataTransferObjectCommandTest.php index 1a84903..4bc4065 100644 --- a/tests/Commands/MakeDataTransferObjectCommandTest.php +++ b/tests/Commands/MakeDataTransferObjectCommandTest.php @@ -25,6 +25,22 @@ public function testCanMakeDataTransferObject(): void $this->assertStringNotContainsString('{{ className }}', $contents); } + public function testCanMakeDataTransferObjectUsingForce(): void + { + $this->artisan('beyond:make:data User.UserData'); + + $file = beyond_modules_path('User/Domain/DataTransferObjects/UserData.php'); + $contents = file_get_contents($file); + + $this->assertFileExists($file); + $this->assertStringNotContainsString('{{ namespace }}', $contents); + $this->assertStringNotContainsString('{{ className }}', $contents); + + $code = $this->artisan('beyond:make:data User.UserData --force'); + + $code->assertOk(); + } + public function testCanMakeDataTransferWithAliasObject(): void { $this->artisan('beyond:make:dto User.UserData'); @@ -36,4 +52,20 @@ public function testCanMakeDataTransferWithAliasObject(): void $this->assertStringNotContainsString('{{ namespace }}', $contents); $this->assertStringNotContainsString('{{ className }}', $contents); } + + public function testCanMakeDataTransferWithAliasObjectUsingForce(): void + { + $this->artisan('beyond:make:dto User.UserData'); + + $file = beyond_modules_path('User/Domain/DataTransferObjects/UserData.php'); + $contents = file_get_contents($file); + + $this->assertFileExists($file); + $this->assertStringNotContainsString('{{ namespace }}', $contents); + $this->assertStringNotContainsString('{{ className }}', $contents); + + $code = $this->artisan('beyond:make:dto User.UserData --force'); + + $code->assertOk(); + } } diff --git a/tests/Commands/MakeEnumCommandTest.php b/tests/Commands/MakeEnumCommandTest.php index 19ef9cf..e6e00dd 100644 --- a/tests/Commands/MakeEnumCommandTest.php +++ b/tests/Commands/MakeEnumCommandTest.php @@ -24,4 +24,20 @@ public function testCanMakeEnum(): void $this->assertStringNotContainsString('{{ namespace }}', $contents); $this->assertStringNotContainsString('{{ className }}', $contents); } + + public function testCanMakeEnumUsingForce(): void + { + $this->artisan('beyond:make:enum User.UserType'); + + $file = beyond_modules_path('User/Domain/Enums/UserType.php'); + $contents = file_get_contents($file); + + $this->assertFileExists($file); + $this->assertStringNotContainsString('{{ namespace }}', $contents); + $this->assertStringNotContainsString('{{ className }}', $contents); + + $code = $this->artisan('beyond:make:enum User.UserType --force'); + + $code->assertOk(); + } } diff --git a/tests/Commands/MakeEventCommandTest.php b/tests/Commands/MakeEventCommandTest.php index 0278526..e217938 100644 --- a/tests/Commands/MakeEventCommandTest.php +++ b/tests/Commands/MakeEventCommandTest.php @@ -24,4 +24,20 @@ public function testCanMakeEvent(): void $this->assertStringNotContainsString('{{ namespace }}', $contents); $this->assertStringNotContainsString('{{ className }}', $contents); } + + public function testCanMakeEventUsingForce(): void + { + $this->artisan('beyond:make:event User.UserCreated'); + + $file = beyond_modules_path('User/Domain/Events/UserCreated.php'); + $contents = file_get_contents($file); + + $this->assertFileExists($file); + $this->assertStringNotContainsString('{{ namespace }}', $contents); + $this->assertStringNotContainsString('{{ className }}', $contents); + + $code = $this->artisan('beyond:make:event User.UserCreated --force'); + + $code->assertOk(); + } } diff --git a/tests/Commands/MakeJobCommandTest.php b/tests/Commands/MakeJobCommandTest.php index e7db00d..de24887 100644 --- a/tests/Commands/MakeJobCommandTest.php +++ b/tests/Commands/MakeJobCommandTest.php @@ -26,6 +26,23 @@ public function testCanMakeJob(): void $this->assertStringContainsString('use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;', $contents); } + public function testCanMakeJobUsingForce(): void + { + $this->artisan('beyond:make:job User.CancelTrials'); + + $file = beyond_modules_path('User/App/Jobs/CancelTrials.php'); + $contents = file_get_contents($file); + + $this->assertFileExists($file); + $this->assertStringNotContainsString('{{ namespace }}', $contents); + $this->assertStringNotContainsString('{{ className }}', $contents); + $this->assertStringContainsString('use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;', $contents); + + $code = $this->artisan('beyond:make:job User.CancelTrials --force'); + + $code->assertOk(); + } + public function testCanMakeSyncedJob(): void { $this->artisan('beyond:make:job User.CancelTrials --sync'); @@ -38,4 +55,21 @@ public function testCanMakeSyncedJob(): void $this->assertStringNotContainsString('{{ className }}', $contents); $this->assertStringContainsString('use Dispatchable;', $contents); } + + public function testCanMakeSyncedJobUsingForce(): void + { + $this->artisan('beyond:make:job User.CancelTrials --sync'); + + $file = beyond_modules_path('User/App/Jobs/CancelTrials.php'); + $contents = file_get_contents($file); + + $this->assertFileExists($file); + $this->assertStringNotContainsString('{{ namespace }}', $contents); + $this->assertStringNotContainsString('{{ className }}', $contents); + $this->assertStringContainsString('use Dispatchable;', $contents); + + $code = $this->artisan('beyond:make:job User.CancelTrials --sync --force'); + + $code->assertOk(); + } } diff --git a/tests/Commands/MakeListenerCommandTest.php b/tests/Commands/MakeListenerCommandTest.php index 9292780..c927ec1 100644 --- a/tests/Commands/MakeListenerCommandTest.php +++ b/tests/Commands/MakeListenerCommandTest.php @@ -24,4 +24,20 @@ public function testCanMakeListener(): void $this->assertStringNotContainsString('{{ namespace }}', $contents); $this->assertStringNotContainsString('{{ className }}', $contents); } + + public function testCanMakeListenerUsingForce(): void + { + $this->artisan('beyond:make:listener User.SendShipmentNotification'); + + $file = beyond_modules_path('User/Domain/Listeners/SendShipmentNotification.php'); + $contents = file_get_contents($file); + + $this->assertFileExists($file); + $this->assertStringNotContainsString('{{ namespace }}', $contents); + $this->assertStringNotContainsString('{{ className }}', $contents); + + $code = $this->artisan('beyond:make:listener User.SendShipmentNotification --force'); + + $code->assertOk(); + } } diff --git a/tests/Commands/MakeMiddlewareCommandTest.php b/tests/Commands/MakeMiddlewareCommandTest.php index bd38dfc..d0284e9 100644 --- a/tests/Commands/MakeMiddlewareCommandTest.php +++ b/tests/Commands/MakeMiddlewareCommandTest.php @@ -24,4 +24,20 @@ public function testCanMakeMiddleware(): void $this->assertStringNotContainsString('{{ namespace }}', $contents); $this->assertStringNotContainsString('{{ className }}', $contents); } + + public function testCanMakeMiddlewareUsingForce(): void + { + $this->artisan('beyond:make:middleware User.SetLocale'); + + $file = beyond_modules_path('User/App/Middleware/SetLocale.php'); + $contents = file_get_contents($file); + + $this->assertFileExists($file); + $this->assertStringNotContainsString('{{ namespace }}', $contents); + $this->assertStringNotContainsString('{{ className }}', $contents); + + $code = $this->artisan('beyond:make:middleware User.SetLocale --force'); + + $code->assertOk(); + } } diff --git a/tests/Commands/MakeMigrationCommandTest.php b/tests/Commands/MakeMigrationCommandTest.php index c1b0aa6..8a29615 100644 --- a/tests/Commands/MakeMigrationCommandTest.php +++ b/tests/Commands/MakeMigrationCommandTest.php @@ -27,6 +27,24 @@ public function testCanMakeMigration(): void $this->assertStringNotContainsString('Schema::', $contents); } + public function testCanMakeMigrationUsingForce(): void + { + $this->artisan('beyond:make:migration User.SimpleMigration'); + + $now = new \DateTime(); + + $file = beyond_modules_path('User/Infrastructure/Database/Migrations/'.$now->format('Y_m_d_His').'_SimpleMigration.php'); + $contents = file_get_contents($file); + + $this->assertFileExists($file); + $this->assertStringNotContainsString('{{ table }}', $contents); + $this->assertStringNotContainsString('Schema::', $contents); + + $code = $this->artisan('beyond:make:migration User.SimpleMigration --force'); + + $code->assertOk(); + } + public function testCanMakeCreateMigration(): void { $this->artisan('beyond:make:migration User.CreateUsersTable'); @@ -40,6 +58,23 @@ public function testCanMakeCreateMigration(): void $this->assertStringContainsString('Schema::create', $contents); } + public function testCanMakeCreateMigrationUsingForce(): void + { + $this->artisan('beyond:make:migration User.CreateUsersTable'); + + $now = new \DateTime(); + + $file = beyond_modules_path('User/Infrastructure/Database/Migrations/'.$now->format('Y_m_d_His').'_CreateUsersTable.php'); + $contents = file_get_contents($file); + + $this->assertFileExists($file); + $this->assertStringContainsString('Schema::create', $contents); + + $code = $this->artisan('beyond:make:migration User.CreateUsersTable --force'); + + $code->assertOk(); + } + public function testCanMakeUpdateMigration(): void { $this->artisan('beyond:make:migration User.AddStatusToUsersTable'); @@ -53,4 +88,22 @@ public function testCanMakeUpdateMigration(): void $this->assertStringNotContainsString('{{ table }}', $contents); $this->assertStringContainsString('Schema::table', $contents); } + + public function testCanMakeUpdateMigrationUsingForce(): void + { + $this->artisan('beyond:make:migration User.AddStatusToUsersTable'); + + $now = new \DateTime(); + + $file = beyond_modules_path('User/Infrastructure/Database/Migrations/'.$now->format('Y_m_d_His').'_AddStatusToUsersTable.php'); + $contents = file_get_contents($file); + + $this->assertFileExists($file); + $this->assertStringNotContainsString('{{ table }}', $contents); + $this->assertStringContainsString('Schema::table', $contents); + + $code = $this->artisan('beyond:make:migration User.AddStatusToUsersTable --force'); + + $code->assertOk(); + } } diff --git a/tests/Commands/MakeModelCommandTest.php b/tests/Commands/MakeModelCommandTest.php index 682573f..cff0cfe 100644 --- a/tests/Commands/MakeModelCommandTest.php +++ b/tests/Commands/MakeModelCommandTest.php @@ -2,8 +2,6 @@ namespace Tests\Commands; -use Carbon\Carbon; -use Illuminate\Filesystem\Filesystem; use Tests\TestCase; class MakeModelCommandTest extends TestCase @@ -27,6 +25,22 @@ public function testCanMakeModel(): void $this->assertStringNotContainsString('{{ className }}', $contents); } + public function testCanMakeModelUsingForce(): void + { + $this->artisan('beyond:make:model User.User'); + + $file = beyond_modules_path('User/Domain/Models/User.php'); + $contents = file_get_contents($file); + + $this->assertFileExists($file); + $this->assertStringNotContainsString('{{ namespace }}', $contents); + $this->assertStringNotContainsString('{{ className }}', $contents); + + $code = $this->artisan('beyond:make:model User.User --force'); + + $code->assertOk(); + } + public function testCanMakeModelWithFactory(): void { $this->artisan('beyond:make:model User.User --factory'); @@ -46,6 +60,29 @@ public function testCanMakeModelWithFactory(): void $this->assertStringNotContainsString('{{ model }}', $contents); } + public function testCanMakeModelWithFactoryUsingForce(): void + { + $this->artisan('beyond:make:model User.User --factory'); + + $file = beyond_modules_path('User/Domain/Models/User.php'); + $contents = file_get_contents($file); + + $this->assertFileExists($file); + $this->assertStringNotContainsString('{{ namespace }}', $contents); + $this->assertStringNotContainsString('{{ className }}', $contents); + + $file = beyond_modules_path('User/Infrastructure/factories/UserFactory.php'); + $contents = file_get_contents($file); + + $this->assertFileExists($file); + $this->assertStringNotContainsString('{{ namespace }}', $contents); + $this->assertStringNotContainsString('{{ model }}', $contents); + + $code = $this->artisan('beyond:make:model User.User --factory --force'); + + $code->assertOk(); + } + public function testCanMakeModelWithMigration(): void { $this->artisan('beyond:make:model User.User --migration'); @@ -65,4 +102,28 @@ public function testCanMakeModelWithMigration(): void $this->assertFileExists($file); $this->assertStringContainsString('Schema::create', $contents); } + + public function testCanMakeModelWithMigrationUsingForce(): void + { + $this->artisan('beyond:make:model User.User --migration'); + + $now = new \DateTime(); + + $file = beyond_modules_path('User/Domain/Models/User.php'); + $contents = file_get_contents($file); + + $this->assertFileExists($file); + $this->assertStringNotContainsString('{{ namespace }}', $contents); + $this->assertStringNotContainsString('{{ className }}', $contents); + + $file = beyond_modules_path('User/Infrastructure/Database/Migrations/'.$now->format('Y_m_d_His').'_create_users_table.php'); + $contents = file_get_contents($file); + + $this->assertFileExists($file); + $this->assertStringContainsString('Schema::create', $contents); + + $code = $this->artisan('beyond:make:model User.User --migration --force'); + + $code->assertOk(); + } } diff --git a/tests/Commands/MakeModuleCommandTest.php b/tests/Commands/MakeModuleCommandTest.php index 2b927e8..2e7e948 100644 --- a/tests/Commands/MakeModuleCommandTest.php +++ b/tests/Commands/MakeModuleCommandTest.php @@ -2,7 +2,6 @@ namespace Tests\Commands; -use Illuminate\Filesystem\Filesystem; use Illuminate\Support\Str; use Tests\TestCase; @@ -19,11 +18,56 @@ public function testCanMakeModule(): void $this->assertStringNotContainsString('{{ module }}', $contents); } + public function testCanMakeModuleUsingForce(): void + { + $this->artisan('beyond:make:module User'); + + $file = beyond_modules_path('User/Providers/UserServiceProvider.php'); + $contents = file_get_contents($file); + + $this->assertFileExists($file); + $this->assertStringNotContainsString('{{ module }}', $contents); + + $code = $this->artisan('beyond:make:module User --force'); + + $code->assertOk(); + } + public function testCanMakeFullModule(): void { $this->artisan('beyond:make:module User --full'); - $files = [ + $files = $this->getPaths(); + + foreach ($files as $file) { + match (Str::contains($file, '.')) { + true => $this->assertFileExists($file), + false => $this->assertDirectoryExists($file), + }; + } + } + + public function testCanMakeFullModuleUsingForce(): void + { + $this->artisan('beyond:make:module User --full'); + + $files = $this->getPaths(); + + foreach ($files as $file) { + match (Str::contains($file, '.')) { + true => $this->assertFileExists($file), + false => $this->assertDirectoryExists($file), + }; + } + + $code = $this->artisan('beyond:make:module User --full --force'); + + $code->assertOk(); + } + + protected function getPaths(): array + { + return [ beyond_modules_path('User/App/Commands'), beyond_modules_path('User/App/Controllers'), beyond_modules_path('User/App/Filters'), @@ -55,12 +99,5 @@ public function testCanMakeFullModule(): void beyond_modules_path('User/Tests/Feature'), beyond_modules_path('User/Tests/Unit'), ]; - - foreach ($files as $file) { - match (Str::contains($file, '.')) { - true => $this->assertFileExists($file), - false => $this->assertDirectoryExists($file), - }; - } } } diff --git a/tests/Commands/MakeNotificationCommandTest.php b/tests/Commands/MakeNotificationCommandTest.php index 63079e3..5af51f2 100644 --- a/tests/Commands/MakeNotificationCommandTest.php +++ b/tests/Commands/MakeNotificationCommandTest.php @@ -24,4 +24,20 @@ public function testCanMakeNotification(): void $this->assertStringNotContainsString('{{ namespace }}', $contents); $this->assertStringNotContainsString('{{ className }}', $contents); } + + public function testCanMakeNotificationUsingForce(): void + { + $this->artisan('beyond:make:notification User.UserCreated'); + + $file = beyond_modules_path('User/Domain/Notifications/UserCreated.php'); + $contents = file_get_contents($file); + + $this->assertFileExists($file); + $this->assertStringNotContainsString('{{ namespace }}', $contents); + $this->assertStringNotContainsString('{{ className }}', $contents); + + $code = $this->artisan('beyond:make:notification User.UserCreated'); + + $code->assertOk(); + } } diff --git a/tests/Commands/MakeObserverCommandTest.php b/tests/Commands/MakeObserverCommandTest.php index 5ddb406..f48e1e6 100644 --- a/tests/Commands/MakeObserverCommandTest.php +++ b/tests/Commands/MakeObserverCommandTest.php @@ -24,4 +24,20 @@ public function testCanMakeObserver(): void $this->assertStringNotContainsString('{{ namespace }}', $contents); $this->assertStringNotContainsString('{{ className }}', $contents); } + + public function testCanMakeObserverUsingForce(): void + { + $this->artisan('beyond:make:observer User.UserObserver'); + + $file = beyond_modules_path('User/Domain/Observers/UserObserver.php'); + $contents = file_get_contents($file); + + $this->assertFileExists($file); + $this->assertStringNotContainsString('{{ namespace }}', $contents); + $this->assertStringNotContainsString('{{ className }}', $contents); + + $code = $this->artisan('beyond:make:observer User.UserObserver'); + + $code->assertOk(); + } } diff --git a/tests/Commands/MakePolicyCommandTest.php b/tests/Commands/MakePolicyCommandTest.php index 5da3c88..14f7523 100644 --- a/tests/Commands/MakePolicyCommandTest.php +++ b/tests/Commands/MakePolicyCommandTest.php @@ -25,6 +25,22 @@ public function testCanMakePolicy(): void $this->assertStringNotContainsString('{{ className }}', $contents); } + public function testCanMakePolicyUsingForce(): void + { + $this->artisan('beyond:make:policy User.UserPolicy'); + + $file = beyond_modules_path('User/Domain/Policies/UserPolicy.php'); + $contents = file_get_contents($file); + + $this->assertFileExists($file); + $this->assertStringNotContainsString('{{ namespace }}', $contents); + $this->assertStringNotContainsString('{{ className }}', $contents); + + $code = $this->artisan('beyond:make:policy User.UserPolicy --force'); + + $code->assertOk(); + } + public function testCanMakePolicyWithModel(): void { $this->artisan('beyond:make:policy User.UserPolicy --model=User'); @@ -39,4 +55,23 @@ public function testCanMakePolicyWithModel(): void $this->assertStringNotContainsString('{{ modelClassName }}', $contents); $this->assertStringNotContainsString('{{ modelVariable }}', $contents); } + + public function testCanMakePolicyWithModelUsingForce(): void + { + $this->artisan('beyond:make:policy User.UserPolicy --model=User'); + + $file = beyond_modules_path('User/Domain/Policies/UserPolicy.php'); + $contents = file_get_contents($file); + + $this->assertFileExists($file); + $this->assertStringNotContainsString('{{ namespace }}', $contents); + $this->assertStringNotContainsString('{{ className }}', $contents); + $this->assertStringNotContainsString('{{ modelNamespace }}', $contents); + $this->assertStringNotContainsString('{{ modelClassName }}', $contents); + $this->assertStringNotContainsString('{{ modelVariable }}', $contents); + + $code = $this->artisan('beyond:make:policy User.UserPolicy --model=User --force'); + + $code->assertOk(); + } } diff --git a/tests/Commands/MakeQueryCommandTest.php b/tests/Commands/MakeQueryCommandTest.php index 7b299c6..e48a2f6 100644 --- a/tests/Commands/MakeQueryCommandTest.php +++ b/tests/Commands/MakeQueryCommandTest.php @@ -25,6 +25,22 @@ public function testCanMakeQuery(): void $this->assertStringNotContainsString('{{ className }}', $contents); } + public function testCanMakeQueryUsingForce(): void + { + $this->artisan('beyond:make:query User.UserIndexQuery'); + + $file = beyond_modules_path('User/App/Queries/UserIndexQuery.php'); + $contents = file_get_contents($file); + + $this->assertFileExists($file); + $this->assertStringNotContainsString('{{ namespace }}', $contents); + $this->assertStringNotContainsString('{{ className }}', $contents); + + $code = $this->artisan('beyond:make:query User.UserIndexQuery --force'); + + $code->assertOk(); + } + public function testCanMakeQueryWithModel(): void { $this->artisan('beyond:make:query User.UserIndexQuery --model=User'); @@ -43,4 +59,27 @@ public function testCanMakeQueryWithModel(): void $this->assertStringNotContainsString('{{ namespace }}', $contents); $this->assertStringNotContainsString('{{ className }}', $contents); } + + public function testCanMakeQueryWithModelUsingForce(): void + { + $this->artisan('beyond:make:query User.UserIndexQuery --model=User'); + + $file = beyond_modules_path('User/App/Queries/UserIndexQuery.php'); + $contents = file_get_contents($file); + + $this->assertFileExists($file); + $this->assertStringNotContainsString('{{ namespace }}', $contents); + $this->assertStringNotContainsString('{{ className }}', $contents); + + $file = beyond_modules_path('User/Domain/Models/User.php'); + $contents = file_get_contents($file); + + $this->assertFileExists($file); + $this->assertStringNotContainsString('{{ namespace }}', $contents); + $this->assertStringNotContainsString('{{ className }}', $contents); + + $code = $this->artisan('beyond:make:query User.UserIndexQuery --model=User --force'); + + $code->assertOk(); + } } diff --git a/tests/Commands/MakeRequestCommandTest.php b/tests/Commands/MakeRequestCommandTest.php index 2e6efe8..edb4242 100644 --- a/tests/Commands/MakeRequestCommandTest.php +++ b/tests/Commands/MakeRequestCommandTest.php @@ -24,4 +24,20 @@ public function testCanMakeRequest(): void $this->assertStringNotContainsString('{{ namespace }}', $contents); $this->assertStringNotContainsString('{{ className }}', $contents); } + + public function testCanMakeRequestUsingForce(): void + { + $this->artisan('beyond:make:request User.StoreUserRequest'); + + $file = beyond_modules_path('User/App/Requests/StoreUserRequest.php'); + $contents = file_get_contents($file); + + $this->assertFileExists($file); + $this->assertStringNotContainsString('{{ namespace }}', $contents); + $this->assertStringNotContainsString('{{ className }}', $contents); + + $code = $this->artisan('beyond:make:request User.StoreUserRequest --force'); + + $code->assertOk(); + } } diff --git a/tests/Commands/MakeResourceCommandTest.php b/tests/Commands/MakeResourceCommandTest.php index 0db0e8b..095bc57 100644 --- a/tests/Commands/MakeResourceCommandTest.php +++ b/tests/Commands/MakeResourceCommandTest.php @@ -24,4 +24,20 @@ public function testCanMakeResource(): void $this->assertStringNotContainsString('{{ namespace }}', $contents); $this->assertStringNotContainsString('{{ className }}', $contents); } + + public function testCanMakeResourceUsingForce(): void + { + $this->artisan('beyond:make:resource User.UserResource'); + + $file = beyond_modules_path('User/App/Resources/UserResource.php'); + $contents = file_get_contents($file); + + $this->assertFileExists($file); + $this->assertStringNotContainsString('{{ namespace }}', $contents); + $this->assertStringNotContainsString('{{ className }}', $contents); + + $code = $this->artisan('beyond:make:resource User.UserResource --force'); + + $code->assertOk(); + } } diff --git a/tests/Commands/MakeRuleCommandTest.php b/tests/Commands/MakeRuleCommandTest.php index 5a49b8d..fca60fe 100644 --- a/tests/Commands/MakeRuleCommandTest.php +++ b/tests/Commands/MakeRuleCommandTest.php @@ -13,7 +13,7 @@ protected function setUp(): void $this->artisan('beyond:make:module User'); } - public function testCanMakeResource(): void + public function testCanMakeRule(): void { $this->artisan('beyond:make:rule User.UniqueUser'); @@ -24,4 +24,20 @@ public function testCanMakeResource(): void $this->assertStringNotContainsString('{{ namespace }}', $contents); $this->assertStringNotContainsString('{{ className }}', $contents); } + + public function testCanMakeRuleUsingForce(): void + { + $this->artisan('beyond:make:rule User.UniqueUser'); + + $file = beyond_modules_path('User/App/Rules/UniqueUser.php'); + $contents = file_get_contents($file); + + $this->assertFileExists($file); + $this->assertStringNotContainsString('{{ namespace }}', $contents); + $this->assertStringNotContainsString('{{ className }}', $contents); + + $code = $this->artisan('beyond:make:rule User.UniqueUser --force'); + + $code->assertOk(); + } } diff --git a/tests/Commands/MakeServiceProviderCommandTest.php b/tests/Commands/MakeServiceProviderCommandTest.php index cda5767..466ce41 100644 --- a/tests/Commands/MakeServiceProviderCommandTest.php +++ b/tests/Commands/MakeServiceProviderCommandTest.php @@ -23,4 +23,19 @@ public function testCanMakeProvider(): void $this->assertFileExists($file); $this->assertStringNotContainsString('{{ module }}', $contents); } + + public function testCanMakeProviderUsingForce(): void + { + $this->artisan('beyond:make:provider User.UserServiceProvider'); + + $file = beyond_modules_path('User/Providers/UserServiceProvider.php'); + $contents = file_get_contents($file); + + $this->assertFileExists($file); + $this->assertStringNotContainsString('{{ module }}', $contents); + + $code = $this->artisan('beyond:make:provider User.UserServiceProvider --force'); + + $code->assertOk(); + } }