Skip to content

Commit

Permalink
Add force tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Gaal committed Aug 15, 2023
1 parent 99bfeb8 commit 89869a8
Show file tree
Hide file tree
Showing 23 changed files with 622 additions and 13 deletions.
3 changes: 2 additions & 1 deletion src/Commands/MakeModuleCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
17 changes: 17 additions & 0 deletions tests/Commands/MakeActionCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Tests\Commands;

use Illuminate\Testing\PendingCommand;
use Tests\TestCase;

class MakeActionCommandTest extends TestCase
Expand All @@ -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();
}
}
16 changes: 16 additions & 0 deletions tests/Commands/MakeBuilderCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
40 changes: 40 additions & 0 deletions tests/Commands/MakeCollectionCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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();
}
}
31 changes: 31 additions & 0 deletions tests/Commands/MakeCommandCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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();
}
}
54 changes: 54 additions & 0 deletions tests/Commands/MakeControllerCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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');
Expand All @@ -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();
}
}
32 changes: 32 additions & 0 deletions tests/Commands/MakeDataTransferObjectCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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();
}
}
16 changes: 16 additions & 0 deletions tests/Commands/MakeEnumCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
16 changes: 16 additions & 0 deletions tests/Commands/MakeEventCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
34 changes: 34 additions & 0 deletions tests/Commands/MakeJobCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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();
}
}
16 changes: 16 additions & 0 deletions tests/Commands/MakeListenerCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Loading

0 comments on commit 89869a8

Please sign in to comment.