diff --git a/composer.json b/composer.json index 65707fd..37d1cbc 100644 --- a/composer.json +++ b/composer.json @@ -43,7 +43,7 @@ }, "require-dev": { "phpunit/phpunit": "^10.3", - "orchestra/testbench": "^8.5|^9.0", + "orchestra/testbench": "^8.23|^9.1", "laravel/pint": "^1.10|^2.0", "spatie/laravel-query-builder": "^5.2", "spatie/laravel-data": "^3.7|^4.0", diff --git a/docs/README.md b/docs/README.md index a176cc9..67de164 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,5 +1,4 @@ # Documentation - ## Commands ### Application - [`beyond:make:command`](commands/make-command.md) @@ -21,7 +20,9 @@ - `beyond:make:listener` - `beyond:make:model` - `beyond:make:observer` +- [`beyond:make:scope`](commands/make-scope.md) ### Support +- [`beyond:make:cast`](commands/make-cast.md) - [`beyond:make:provider`](commands/make-provider.md) - [`beyond:make:rule`](commands/make-rule.md) diff --git a/docs/commands/make-cast.md b/docs/commands/make-cast.md new file mode 100644 index 0000000..d05c5b9 --- /dev/null +++ b/docs/commands/make-cast.md @@ -0,0 +1,13 @@ +# `beyond:make:cast` +Creates a new cast. + +## Signature +`beyond:make:cast {name} {--force}` + +| Parameters | Description | +|------------|-----------------------| +| name | The name of your cast | + +| Flags | Description | +|----------|-------------------------| +| --force | Overwrite existing file | diff --git a/docs/commands/make-provider.md b/docs/commands/make-provider.md index 48d424e..9b37475 100644 --- a/docs/commands/make-provider.md +++ b/docs/commands/make-provider.md @@ -3,7 +3,7 @@ Creates a new service provider. > [!NOTE] > Within the register method, you should **only bind things into the service container**. -> Because of this, service containers are **not** created under `Application/{App}/Providers` +> Because of this, service providers are **not** created under `Application/{App}/Providers`. > We want to avoid the feeling of registering things per application. You always register things > for your entire Laravel project. diff --git a/docs/commands/make-scope.md b/docs/commands/make-scope.md new file mode 100644 index 0000000..f3ce038 --- /dev/null +++ b/docs/commands/make-scope.md @@ -0,0 +1,14 @@ +# `beyond:make:scope` +Creates a new scope. + +## Signature +`beyond:make:scope {name} {--g|global} {--force}` + +| Parameters | Description | +|------------|------------------------| +| name | The name of your scope | + +| Flags | Description | +|----------|-------------------------------------------| +| --global | Creates the scope inside `Support\Scopes` | +| --force | Overwrite existing file | diff --git a/src/Commands/MakeCastCommand.php b/src/Commands/MakeCastCommand.php new file mode 100644 index 0000000..5a109a3 --- /dev/null +++ b/src/Commands/MakeCastCommand.php @@ -0,0 +1,23 @@ + $attributes + */ + public function get(Model $model, string $key, mixed $value, array $attributes): mixed + { + return $value; + } + + /** + * Prepare the given value for storage. + * + * @param array $attributes + */ + public function set(Model $model, string $key, mixed $value, array $attributes): mixed + { + return $value; + } +} diff --git a/stubs/scope.stub b/stubs/scope.stub new file mode 100644 index 0000000..d1aac80 --- /dev/null +++ b/stubs/scope.stub @@ -0,0 +1,18 @@ +assertEquals(base_path('src'), beyond_path()); + $this->assertEquals(beyond_path('Application'), beyond_app_path()); + $this->assertEquals(beyond_path('Domain'), beyond_domain_path()); + $this->assertEquals(beyond_path('Support'), beyond_support_path()); + } + public function testCanMakeClassWithDirectory(): void { $this->artisan('beyond:make:action User.Admin/UserStoreAction'); diff --git a/tests/Commands/MakeCastCommandTest.php b/tests/Commands/MakeCastCommandTest.php new file mode 100644 index 0000000..17149c8 --- /dev/null +++ b/tests/Commands/MakeCastCommandTest.php @@ -0,0 +1,36 @@ +artisan('beyond:make:cast TimezoneCast'); + + $file = beyond_support_path('Casts/TimezoneCast.php'); + $contents = file_get_contents($file); + + $this->assertFileExists($file); + $this->assertStringNotContainsString('{{ namespace }}', $contents); + $this->assertStringNotContainsString('{{ className }}', $contents); + } + + public function testCanMakeCastUsingForce(): void + { + $this->artisan('beyond:make:cast TimezoneCast'); + + $file = beyond_support_path('Casts/TimezoneCast.php'); + $contents = file_get_contents($file); + + $this->assertFileExists($file); + $this->assertStringNotContainsString('{{ namespace }}', $contents); + $this->assertStringNotContainsString('{{ className }}', $contents); + + $code = $this->artisan('beyond:make:cast TimezoneCast --force'); + + $code->assertOk(); + } +} diff --git a/tests/Commands/MakeScopeCommandTest.php b/tests/Commands/MakeScopeCommandTest.php new file mode 100644 index 0000000..8c79ba7 --- /dev/null +++ b/tests/Commands/MakeScopeCommandTest.php @@ -0,0 +1,36 @@ +artisan('beyond:make:scope User.ActiveScope'); + + $file = beyond_domain_path('User/Scopes/ActiveScope.php'); + $contents = file_get_contents($file); + + $this->assertFileExists($file); + $this->assertStringNotContainsString('{{ namespace }}', $contents); + $this->assertStringNotContainsString('{{ className }}', $contents); + } + + public function testCanMakeScopeUsingForce(): void + { + $this->artisan('beyond:make:scope User.ActiveScope'); + + $file = beyond_domain_path('User/Scopes/ActiveScope.php'); + $contents = file_get_contents($file); + + $this->assertFileExists($file); + $this->assertStringNotContainsString('{{ namespace }}', $contents); + $this->assertStringNotContainsString('{{ className }}', $contents); + + $code = $this->artisan('beyond:make:scope User.ActiveScope --force'); + + $code->assertOk(); + } +}