From ae78afa5059170b8e8f2d3ec569a4f532e0ae6c5 Mon Sep 17 00:00:00 2001 From: Mohammad Alavi Date: Sun, 8 Dec 2024 15:28:51 +0330 Subject: [PATCH] fix(generator): outdated generated files --- .../Commands/ControllerGenerator.php | 4 +- src/Generator/Commands/ModelGenerator.php | 1 + .../Commands/RepositoryGenerator.php | 6 +++ src/Generator/Commands/TaskGenerator.php | 1 + .../Commands/TestUnitTestGenerator.php | 5 +- src/Generator/Stubs/composer.stub | 5 +- .../Stubs/controllers/api/create.stub | 9 +--- src/Generator/Stubs/controllers/api/crud.stub | 34 ++++++------- .../Stubs/controllers/api/delete.stub | 9 +--- src/Generator/Stubs/controllers/api/find.stub | 12 ++--- src/Generator/Stubs/controllers/api/list.stub | 9 +--- .../Stubs/controllers/api/update.stub | 9 +--- src/Generator/Stubs/events/delete.stub | 3 +- src/Generator/Stubs/events/list.stub | 1 - src/Generator/Stubs/factory.stub | 6 +-- src/Generator/Stubs/migration.stub | 4 +- src/Generator/Stubs/model.stub | 4 -- src/Generator/Stubs/readme.stub | 2 +- src/Generator/Stubs/repository.stub | 9 +++- src/Generator/Stubs/requests/create.stub | 4 +- src/Generator/Stubs/requests/delete.stub | 4 +- src/Generator/Stubs/requests/edit.stub | 4 +- src/Generator/Stubs/requests/find.stub | 4 +- src/Generator/Stubs/requests/generic.stub | 4 +- src/Generator/Stubs/requests/list.stub | 4 +- src/Generator/Stubs/requests/store.stub | 4 +- src/Generator/Stubs/requests/update.stub | 4 +- src/Generator/Stubs/tasks/create.stub | 2 +- src/Generator/Stubs/tasks/delete.stub | 13 ++--- src/Generator/Stubs/tasks/find.stub | 2 +- src/Generator/Stubs/tasks/list.stub | 2 +- src/Generator/Stubs/tasks/update.stub | 2 +- .../Stubs/tasks/with_event/create.stub | 8 ++-- .../Stubs/tasks/with_event/delete.stub | 17 ++----- .../Stubs/tasks/with_event/find.stub | 8 ++-- .../Stubs/tasks/with_event/list.stub | 2 +- .../Stubs/tasks/with_event/update.stub | 8 ++-- src/Generator/Stubs/tests/functional/api.stub | 12 ++--- src/Generator/Stubs/tests/functional/cli.stub | 4 -- .../Stubs/tests/functional/create.stub | 16 +++---- .../Stubs/tests/functional/delete.stub | 17 +++---- .../Stubs/tests/functional/find.stub | 19 ++++---- .../Stubs/tests/functional/generic.stub | 4 -- .../Stubs/tests/functional/list.stub | 48 +++++++++---------- .../Stubs/tests/functional/update.stub | 17 +++---- src/Generator/Stubs/tests/functional/web.stub | 16 ++----- src/Generator/Stubs/tests/testcase/api.stub | 2 +- src/Generator/Stubs/tests/testcase/cli.stub | 2 +- src/Generator/Stubs/tests/testcase/unit.stub | 2 +- src/Generator/Stubs/tests/testcase/web.stub | 2 +- src/Generator/Stubs/tests/unit/create.stub | 21 +------- src/Generator/Stubs/tests/unit/delete.stub | 16 +------ src/Generator/Stubs/tests/unit/factory.stub | 6 +-- src/Generator/Stubs/tests/unit/find.stub | 16 +------ src/Generator/Stubs/tests/unit/generic.stub | 4 -- src/Generator/Stubs/tests/unit/list.stub | 6 +-- src/Generator/Stubs/tests/unit/migration.stub | 20 +++----- src/Generator/Stubs/tests/unit/update.stub | 17 +------ .../Stubs/tests/unit/with_event/create.stub | 20 +------- .../Stubs/tests/unit/with_event/delete.stub | 16 +------ .../Stubs/tests/unit/with_event/find.stub | 16 +------ .../Stubs/tests/unit/with_event/list.stub | 6 +-- .../Stubs/tests/unit/with_event/update.stub | 18 +------ src/Generator/Stubs/transformer.stub | 17 ++----- src/Generator/Stubs/value.stub | 4 -- 65 files changed, 196 insertions(+), 397 deletions(-) diff --git a/src/Generator/Commands/ControllerGenerator.php b/src/Generator/Commands/ControllerGenerator.php index 2c87ffdb..63907d65 100644 --- a/src/Generator/Commands/ControllerGenerator.php +++ b/src/Generator/Commands/ControllerGenerator.php @@ -70,8 +70,8 @@ public function getUserInputs(): array|null $model = $this->containerName; $models = Pluralizer::plural($model); - $entity = Str::lower($model); - $entities = Pluralizer::plural($entity); + $entity = Str::camel($model); + $entities = Str::of($entity)->pluralStudly()->camel()->toString(); return [ 'path-parameters' => [ diff --git a/src/Generator/Commands/ModelGenerator.php b/src/Generator/Commands/ModelGenerator.php index 51473533..28127fbb 100644 --- a/src/Generator/Commands/ModelGenerator.php +++ b/src/Generator/Commands/ModelGenerator.php @@ -55,6 +55,7 @@ public function getUserInputs(): array|null '--section' => $this->sectionName, '--container' => $this->containerName, '--file' => $this->fileName . 'Repository', + '--model' => $this->fileName, ]); if (0 != $status) { diff --git a/src/Generator/Commands/RepositoryGenerator.php b/src/Generator/Commands/RepositoryGenerator.php index 153e0a64..9c84c165 100644 --- a/src/Generator/Commands/RepositoryGenerator.php +++ b/src/Generator/Commands/RepositoryGenerator.php @@ -5,6 +5,7 @@ use Apiato\Core\Generator\GeneratorCommand; use Apiato\Core\Generator\Interfaces\ComponentsGenerator; use Illuminate\Support\Str; +use Symfony\Component\Console\Input\InputOption; class RepositoryGenerator extends GeneratorCommand implements ComponentsGenerator { @@ -13,6 +14,7 @@ class RepositoryGenerator extends GeneratorCommand implements ComponentsGenerato * This is a replacement of the `getArguments` function "which reads whenever it's called". */ public array $inputs = [ + ['model', null, InputOption::VALUE_OPTIONAL, 'The model to generate this Factory for'], ]; /** * The console command name. @@ -45,6 +47,8 @@ class RepositoryGenerator extends GeneratorCommand implements ComponentsGenerato public function getUserInputs(): array|null { + $model = $this->checkParameterOrAsk('model', 'Enter the name of the Model to generate this Repository for'); + return [ 'path-parameters' => [ 'section-name' => $this->sectionName, @@ -56,6 +60,8 @@ public function getUserInputs(): array|null '_container-name' => Str::lower($this->containerName), 'container-name' => $this->containerName, 'class-name' => $this->fileName, + 'model' => $model, + '_model' => Str::lower($model), ], 'file-parameters' => [ 'file-name' => $this->fileName, diff --git a/src/Generator/Commands/TaskGenerator.php b/src/Generator/Commands/TaskGenerator.php index 48759e2f..a76f0e5c 100644 --- a/src/Generator/Commands/TaskGenerator.php +++ b/src/Generator/Commands/TaskGenerator.php @@ -80,6 +80,7 @@ public function getUserInputs(): array|null 'model' => $model, 'models' => $models, '_model' => Str::lower($model), + 'model_' => Str::camel($model), 'event' => $event, ], 'file-parameters' => [ diff --git a/src/Generator/Commands/TestUnitTestGenerator.php b/src/Generator/Commands/TestUnitTestGenerator.php index dd04daff..31f58800 100644 --- a/src/Generator/Commands/TestUnitTestGenerator.php +++ b/src/Generator/Commands/TestUnitTestGenerator.php @@ -53,7 +53,7 @@ public function getUserInputs(): array|null $model = $this->option('model'); $stub = $this->option('stub'); $event = $this->option('event'); - $tablename = $this->option('tablename'); + $tableName = $this->option('tablename'); if ($stub) { if ($event) { @@ -90,7 +90,8 @@ public function getUserInputs(): array|null 'models' => $models, '_models' => Str::lower($models), 'event' => $event, - 'table-name' => $tablename, + 'table-name' => $tableName, + '_table-name_' => Str::studly($tableName), ], 'file-parameters' => [ 'file-name' => $this->fileName, diff --git a/src/Generator/Stubs/composer.stub b/src/Generator/Stubs/composer.stub index 4bb15db9..f21f640f 100644 --- a/src/Generator/Stubs/composer.stub +++ b/src/Generator/Stubs/composer.stub @@ -1,6 +1,5 @@ { "name": "apiato/{{_container-name}}", - "description": "{{container-name}} Container for apiato.", - "require": { - } + "description": "{{container-name}} Container", + "require": {} } diff --git a/src/Generator/Stubs/controllers/api/create.stub b/src/Generator/Stubs/controllers/api/create.stub index 5076d770..0836b794 100644 --- a/src/Generator/Stubs/controllers/api/create.stub +++ b/src/Generator/Stubs/controllers/api/create.stub @@ -13,19 +13,14 @@ use Illuminate\Http\JsonResponse; class {{class-name}} extends {{base-controller}} { - public function __construct( - private readonly Create{{model}}Action $action, - ) { - } - /** * @throws CreateResourceFailedException * @throws InvalidTransformerException * @throws IncorrectIdException */ - public function __invoke(Create{{model}}Request $request): JsonResponse + public function __invoke(Create{{model}}Request $request, Create{{model}}Action $action): JsonResponse { - ${{entity}} = $this->action->run($request); + ${{entity}} = $action->run($request); return $this->created($this->transform(${{entity}}, {{model}}Transformer::class)); } diff --git a/src/Generator/Stubs/controllers/api/crud.stub b/src/Generator/Stubs/controllers/api/crud.stub index 78a96a35..09c24119 100644 --- a/src/Generator/Stubs/controllers/api/crud.stub +++ b/src/Generator/Stubs/controllers/api/crud.stub @@ -40,22 +40,22 @@ class {{class-name}} extends {{base-controller}} * @throws CreateResourceFailedException * @throws IncorrectIdException */ - public function create{{model}}(Create{{model}}Request $request): JsonResponse + public function create{{model}}(Create{{model}}Request $request, Create{{model}}Action $action): JsonResponse { - ${{entity}} = $this->create{{model}}Action->run($request); + ${{entity}} = $action->run($request); - return $this->created($this->transform(${{entity}}, {{model}}Transformer::class)); + return $this->created($this->transform(${{entity}}, {{model}}Transformer::class)); } /** * @throws InvalidTransformerException * @throws NotFoundException */ - public function find{{model}}ById(Find{{model}}ByIdRequest $request): array + public function find{{model}}ById(Find{{model}}ByIdRequest $request, Find{{model}}ByIdAction $action): array { - ${{entity}} = $this->find{{model}}ByIdAction->run($request); + ${{entity}} = $action->run($request); - return $this->transform(${{entity}}, {{model}}Transformer::class); + return $this->transform(${{entity}}, {{model}}Transformer::class); } /** @@ -63,34 +63,34 @@ class {{class-name}} extends {{base-controller}} * @throws CoreInternalErrorException * @throws RepositoryException */ - public function list{{models}}(List{{models}}Request $request): array + public function list{{models}}(List{{models}}Request $request, List{{models}}Action $action): array { - ${{entities}} = $this->list{{models}}Action->run($request); + ${{entities}} = $action->run($request); - return $this->transform(${{entities}}, {{model}}Transformer::class); + return $this->transform(${{entities}}, {{model}}Transformer::class); } /** - * @throws IncorrectIdException * @throws InvalidTransformerException - * @throws NotFoundException * @throws UpdateResourceFailedException + * @throws IncorrectIdException + * @throws NotFoundException */ - public function update{{model}}(Update{{model}}Request $request): array + public function update{{model}}(Update{{model}}Request $request, Update{{model}}Action $action): array { - ${{entity}} = $this->update{{model}}Action->run($request); + ${{entity}} = $action->run($request); - return $this->transform(${{entity}}, {{model}}Transformer::class); + return $this->transform(${{entity}}, {{model}}Transformer::class); } /** * @throws DeleteResourceFailedException * @throws NotFoundException */ - public function delete{{model}}(Delete{{model}}Request $request): JsonResponse + public function delete{{model}}(Delete{{model}}Request $request, Delete{{model}}Action $action): JsonResponse { - $this->delete{{model}}Action->run($request); + $action->run($request); - return $this->noContent(); + return $this->noContent(); } } diff --git a/src/Generator/Stubs/controllers/api/delete.stub b/src/Generator/Stubs/controllers/api/delete.stub index af50cc28..868e3e74 100644 --- a/src/Generator/Stubs/controllers/api/delete.stub +++ b/src/Generator/Stubs/controllers/api/delete.stub @@ -11,18 +11,13 @@ use Illuminate\Http\JsonResponse; class {{class-name}} extends {{base-controller}} { - public function __construct( - private readonly Delete{{model}}Action $action, - ) { - } - /** * @throws DeleteResourceFailedException * @throws NotFoundException */ - public function __invoke(Delete{{model}}Request $request): JsonResponse + public function __invoke(Delete{{model}}Request $request, Delete{{model}}Action $action): JsonResponse { - $this->action->run($request); + $action->run($request); return $this->noContent(); } diff --git a/src/Generator/Stubs/controllers/api/find.stub b/src/Generator/Stubs/controllers/api/find.stub index 12cef47e..c0fca04b 100644 --- a/src/Generator/Stubs/controllers/api/find.stub +++ b/src/Generator/Stubs/controllers/api/find.stub @@ -11,17 +11,13 @@ use App\Ship\Parents\Controllers\{{base-controller}}; class {{class-name}} extends {{base-controller}} { - public function __construct( - private readonly Find{{model}}ByIdAction $action - ) { - } - /** - * @throws InvalidTransformerException|NotFoundException + * @throws InvalidTransformerException + * @throws NotFoundException */ - public function __invoke(Find{{model}}ByIdRequest $request): array + public function __invoke(Find{{model}}ByIdRequest $request, Find{{model}}ByIdAction $action): array { - ${{entity}} = $this->action->run($request); + ${{entity}} = $action->run($request); return $this->transform(${{entity}}, {{model}}Transformer::class); } diff --git a/src/Generator/Stubs/controllers/api/list.stub b/src/Generator/Stubs/controllers/api/list.stub index 9983330b..908ecffb 100644 --- a/src/Generator/Stubs/controllers/api/list.stub +++ b/src/Generator/Stubs/controllers/api/list.stub @@ -12,19 +12,14 @@ use Prettus\Repository\Exceptions\RepositoryException; class {{class-name}} extends {{base-controller}} { - public function __construct( - private readonly List{{models}}Action $action - ) { - } - /** * @throws InvalidTransformerException * @throws CoreInternalErrorException * @throws RepositoryException */ - public function __invoke(List{{models}}Request $request): array + public function __invoke(List{{models}}Request $request, List{{models}}Action $action): array { - ${{entities}} = $this->action->run($request); + ${{entities}} = $action->run($request); return $this->transform(${{entities}}, {{model}}Transformer::class); } diff --git a/src/Generator/Stubs/controllers/api/update.stub b/src/Generator/Stubs/controllers/api/update.stub index a01bf4bb..fe865c73 100644 --- a/src/Generator/Stubs/controllers/api/update.stub +++ b/src/Generator/Stubs/controllers/api/update.stub @@ -13,20 +13,15 @@ use App\Ship\Parents\Controllers\{{base-controller}}; class {{class-name}} extends {{base-controller}} { - public function __construct( - private readonly Update{{model}}Action $action - ) { - } - /** * @throws InvalidTransformerException * @throws UpdateResourceFailedException * @throws IncorrectIdException * @throws NotFoundException */ - public function __invoke(Update{{model}}Request $request): array + public function __invoke(Update{{model}}Request $request, Update{{model}}Action $action): array { - ${{entity}} = $this->action->run($request); + ${{entity}} = $action->run($request); return $this->transform(${{entity}}, {{model}}Transformer::class); } diff --git a/src/Generator/Stubs/events/delete.stub b/src/Generator/Stubs/events/delete.stub index e87952e4..e0c46a90 100644 --- a/src/Generator/Stubs/events/delete.stub +++ b/src/Generator/Stubs/events/delete.stub @@ -2,7 +2,6 @@ namespace App\Containers\{{section-name}}\{{container-name}}\Events; -use App\Containers\{{section-name}}\{{container-name}}\Models\{{model}}; use App\Ship\Parents\Events\Event as ParentEvent; use Illuminate\Broadcasting\Channel; use Illuminate\Broadcasting\PrivateChannel; @@ -10,7 +9,7 @@ use Illuminate\Broadcasting\PrivateChannel; class {{class-name}} extends ParentEvent { public function __construct( - public readonly int $result, + public readonly bool $result, ) { } diff --git a/src/Generator/Stubs/events/list.stub b/src/Generator/Stubs/events/list.stub index ea812024..1cdc833e 100644 --- a/src/Generator/Stubs/events/list.stub +++ b/src/Generator/Stubs/events/list.stub @@ -2,7 +2,6 @@ namespace App\Containers\{{section-name}}\{{container-name}}\Events; -use App\Containers\{{section-name}}\{{container-name}}\Models\{{model}}; use App\Ship\Parents\Events\Event as ParentEvent; use Illuminate\Broadcasting\Channel; use Illuminate\Broadcasting\PrivateChannel; diff --git a/src/Generator/Stubs/factory.stub b/src/Generator/Stubs/factory.stub index 6b611b31..7cf6dd98 100644 --- a/src/Generator/Stubs/factory.stub +++ b/src/Generator/Stubs/factory.stub @@ -6,7 +6,7 @@ use App\Containers\{{section-name}}\{{container-name}}\Models\{{model}}; use App\Ship\Parents\Factories\Factory as ParentFactory; /** - * @template TModel of {{class-name}} + * @template TModel of {{model}} * * @extends ParentFactory */ @@ -17,8 +17,6 @@ class {{class-name}} extends ParentFactory public function definition(): array { - return [ - // - ]; + return []; } } diff --git a/src/Generator/Stubs/migration.stub b/src/Generator/Stubs/migration.stub index 6d015fcd..d8fd8179 100644 --- a/src/Generator/Stubs/migration.stub +++ b/src/Generator/Stubs/migration.stub @@ -7,11 +7,9 @@ use Illuminate\Support\Facades\Schema; return new class() extends Migration { public function up(): void { - Schema::create('{{table-name}}', function (Blueprint $table) { + Schema::create('{{table-name}}', static function (Blueprint $table) { $table->id(); - $table->timestamps(); - // $table->softDeletes(); }); } diff --git a/src/Generator/Stubs/model.stub b/src/Generator/Stubs/model.stub index 3f719410..ded138d9 100644 --- a/src/Generator/Stubs/model.stub +++ b/src/Generator/Stubs/model.stub @@ -6,8 +6,4 @@ use App\Ship\Parents\Models\Model as ParentModel; class {{class-name}} extends ParentModel { - /** - * A resource key to be used in the serialized responses. - */ - protected $resourceKey = '{{resource-key}}'; } diff --git a/src/Generator/Stubs/readme.stub b/src/Generator/Stubs/readme.stub index 264d279b..36453c13 100644 --- a/src/Generator/Stubs/readme.stub +++ b/src/Generator/Stubs/readme.stub @@ -1,2 +1,2 @@ -### Apiato {{container-name}} Container +### {{container-name}} Container diff --git a/src/Generator/Stubs/repository.stub b/src/Generator/Stubs/repository.stub index 10ae7dfe..ec45f118 100644 --- a/src/Generator/Stubs/repository.stub +++ b/src/Generator/Stubs/repository.stub @@ -2,12 +2,17 @@ namespace App\Containers\{{section-name}}\{{container-name}}\Data\Repositories; +use App\Containers\{{section-name}}\{{container-name}}\Models\{{model}}; use App\Ship\Parents\Repositories\Repository as ParentRepository; +/** + * @template TModel of {{model}} + * + * @extends ParentRepository + */ class {{class-name}} extends ParentRepository { protected $fieldSearchable = [ - 'id' => '=', - // ... + // 'id' => '=', ]; } diff --git a/src/Generator/Stubs/requests/create.stub b/src/Generator/Stubs/requests/create.stub index cfe77c96..2d7bcd20 100644 --- a/src/Generator/Stubs/requests/create.stub +++ b/src/Generator/Stubs/requests/create.stub @@ -7,8 +7,8 @@ use App\Ship\Parents\Requests\Request as ParentRequest; class {{class-name}} extends ParentRequest { protected array $access = [ - 'permissions' => '', - 'roles' => '', + 'permissions' => null, + 'roles' => null, ]; protected array $decode = [ diff --git a/src/Generator/Stubs/requests/delete.stub b/src/Generator/Stubs/requests/delete.stub index 7081bbac..4352f3fc 100644 --- a/src/Generator/Stubs/requests/delete.stub +++ b/src/Generator/Stubs/requests/delete.stub @@ -7,8 +7,8 @@ use App\Ship\Parents\Requests\Request as ParentRequest; class {{class-name}} extends ParentRequest { protected array $access = [ - 'permissions' => '', - 'roles' => '', + 'permissions' => null, + 'roles' => null, ]; protected array $decode = [ diff --git a/src/Generator/Stubs/requests/edit.stub b/src/Generator/Stubs/requests/edit.stub index 7081bbac..4352f3fc 100644 --- a/src/Generator/Stubs/requests/edit.stub +++ b/src/Generator/Stubs/requests/edit.stub @@ -7,8 +7,8 @@ use App\Ship\Parents\Requests\Request as ParentRequest; class {{class-name}} extends ParentRequest { protected array $access = [ - 'permissions' => '', - 'roles' => '', + 'permissions' => null, + 'roles' => null, ]; protected array $decode = [ diff --git a/src/Generator/Stubs/requests/find.stub b/src/Generator/Stubs/requests/find.stub index 7081bbac..4352f3fc 100644 --- a/src/Generator/Stubs/requests/find.stub +++ b/src/Generator/Stubs/requests/find.stub @@ -7,8 +7,8 @@ use App\Ship\Parents\Requests\Request as ParentRequest; class {{class-name}} extends ParentRequest { protected array $access = [ - 'permissions' => '', - 'roles' => '', + 'permissions' => null, + 'roles' => null, ]; protected array $decode = [ diff --git a/src/Generator/Stubs/requests/generic.stub b/src/Generator/Stubs/requests/generic.stub index cfe77c96..2d7bcd20 100644 --- a/src/Generator/Stubs/requests/generic.stub +++ b/src/Generator/Stubs/requests/generic.stub @@ -7,8 +7,8 @@ use App\Ship\Parents\Requests\Request as ParentRequest; class {{class-name}} extends ParentRequest { protected array $access = [ - 'permissions' => '', - 'roles' => '', + 'permissions' => null, + 'roles' => null, ]; protected array $decode = [ diff --git a/src/Generator/Stubs/requests/list.stub b/src/Generator/Stubs/requests/list.stub index cfe77c96..2d7bcd20 100644 --- a/src/Generator/Stubs/requests/list.stub +++ b/src/Generator/Stubs/requests/list.stub @@ -7,8 +7,8 @@ use App\Ship\Parents\Requests\Request as ParentRequest; class {{class-name}} extends ParentRequest { protected array $access = [ - 'permissions' => '', - 'roles' => '', + 'permissions' => null, + 'roles' => null, ]; protected array $decode = [ diff --git a/src/Generator/Stubs/requests/store.stub b/src/Generator/Stubs/requests/store.stub index cfe77c96..2d7bcd20 100644 --- a/src/Generator/Stubs/requests/store.stub +++ b/src/Generator/Stubs/requests/store.stub @@ -7,8 +7,8 @@ use App\Ship\Parents\Requests\Request as ParentRequest; class {{class-name}} extends ParentRequest { protected array $access = [ - 'permissions' => '', - 'roles' => '', + 'permissions' => null, + 'roles' => null, ]; protected array $decode = [ diff --git a/src/Generator/Stubs/requests/update.stub b/src/Generator/Stubs/requests/update.stub index 7081bbac..4352f3fc 100644 --- a/src/Generator/Stubs/requests/update.stub +++ b/src/Generator/Stubs/requests/update.stub @@ -7,8 +7,8 @@ use App\Ship\Parents\Requests\Request as ParentRequest; class {{class-name}} extends ParentRequest { protected array $access = [ - 'permissions' => '', - 'roles' => '', + 'permissions' => null, + 'roles' => null, ]; protected array $decode = [ diff --git a/src/Generator/Stubs/tasks/create.stub b/src/Generator/Stubs/tasks/create.stub index e5b14dcc..bec5b7ef 100644 --- a/src/Generator/Stubs/tasks/create.stub +++ b/src/Generator/Stubs/tasks/create.stub @@ -10,7 +10,7 @@ use App\Ship\Parents\Tasks\Task as ParentTask; class {{class-name}} extends ParentTask { public function __construct( - protected readonly {{model}}Repository $repository, + private readonly {{model}}Repository $repository, ) { } diff --git a/src/Generator/Stubs/tasks/delete.stub b/src/Generator/Stubs/tasks/delete.stub index 1e2710ec..503e275b 100644 --- a/src/Generator/Stubs/tasks/delete.stub +++ b/src/Generator/Stubs/tasks/delete.stub @@ -6,12 +6,11 @@ use App\Containers\{{section-name}}\{{container-name}}\Data\Repositories\{{model use App\Ship\Exceptions\DeleteResourceFailedException; use App\Ship\Exceptions\NotFoundException; use App\Ship\Parents\Tasks\Task as ParentTask; -use Illuminate\Database\Eloquent\ModelNotFoundException; class {{class-name}} extends ParentTask { public function __construct( - protected readonly {{model}}Repository $repository, + private readonly {{model}}Repository $repository, ) { } @@ -19,14 +18,8 @@ class {{class-name}} extends ParentTask * @throws DeleteResourceFailedException * @throws NotFoundException */ - public function run($id): int + public function run($id): bool { - try { - return $this->repository->delete($id); - } catch (ModelNotFoundException) { - throw new NotFoundException(); - } catch (\Exception) { - throw new DeleteResourceFailedException(); - } + return $this->repository->delete($id); } } diff --git a/src/Generator/Stubs/tasks/find.stub b/src/Generator/Stubs/tasks/find.stub index fcb2a502..299ee97d 100644 --- a/src/Generator/Stubs/tasks/find.stub +++ b/src/Generator/Stubs/tasks/find.stub @@ -10,7 +10,7 @@ use App\Ship\Parents\Tasks\Task as ParentTask; class {{class-name}} extends ParentTask { public function __construct( - protected readonly {{model}}Repository $repository, + private readonly {{model}}Repository $repository, ) { } diff --git a/src/Generator/Stubs/tasks/list.stub b/src/Generator/Stubs/tasks/list.stub index 07c73dc0..a8ace5cf 100644 --- a/src/Generator/Stubs/tasks/list.stub +++ b/src/Generator/Stubs/tasks/list.stub @@ -10,7 +10,7 @@ use Prettus\Repository\Exceptions\RepositoryException; class {{class-name}} extends ParentTask { public function __construct( - protected readonly {{model}}Repository $repository, + private readonly {{model}}Repository $repository, ) { } diff --git a/src/Generator/Stubs/tasks/update.stub b/src/Generator/Stubs/tasks/update.stub index 40813e90..de6055ed 100644 --- a/src/Generator/Stubs/tasks/update.stub +++ b/src/Generator/Stubs/tasks/update.stub @@ -12,7 +12,7 @@ use Illuminate\Database\Eloquent\ModelNotFoundException; class {{class-name}} extends ParentTask { public function __construct( - protected readonly {{model}}Repository $repository, + private readonly {{model}}Repository $repository, ) { } diff --git a/src/Generator/Stubs/tasks/with_event/create.stub b/src/Generator/Stubs/tasks/with_event/create.stub index a02009f0..609036ff 100644 --- a/src/Generator/Stubs/tasks/with_event/create.stub +++ b/src/Generator/Stubs/tasks/with_event/create.stub @@ -11,7 +11,7 @@ use App\Ship\Parents\Tasks\Task as ParentTask; class {{class-name}} extends ParentTask { public function __construct( - protected readonly {{model}}Repository $repository, + private readonly {{model}}Repository $repository, ) { } @@ -21,10 +21,10 @@ class {{class-name}} extends ParentTask public function run(array $data): {{model}} { try { - ${{_model}} = $this->repository->create($data); - {{event}}::dispatch(${{_model}}); + ${{model_}} = $this->repository->create($data); + {{event}}::dispatch(${{model_}}); - return ${{_model}}; + return ${{model_}}; } catch (\Exception) { throw new CreateResourceFailedException(); } diff --git a/src/Generator/Stubs/tasks/with_event/delete.stub b/src/Generator/Stubs/tasks/with_event/delete.stub index 9339fd6f..87cc138a 100644 --- a/src/Generator/Stubs/tasks/with_event/delete.stub +++ b/src/Generator/Stubs/tasks/with_event/delete.stub @@ -7,12 +7,11 @@ use App\Containers\{{section-name}}\{{container-name}}\Events\{{event}}; use App\Ship\Exceptions\DeleteResourceFailedException; use App\Ship\Exceptions\NotFoundException; use App\Ship\Parents\Tasks\Task as ParentTask; -use Illuminate\Database\Eloquent\ModelNotFoundException; class {{class-name}} extends ParentTask { public function __construct( - protected readonly {{model}}Repository $repository, + private readonly {{model}}Repository $repository, ) { } @@ -20,17 +19,11 @@ class {{class-name}} extends ParentTask * @throws DeleteResourceFailedException * @throws NotFoundException */ - public function run($id): int + public function run($id): bool { - try { - $result = $this->repository->delete($id); - {{event}}::dispatch($result); + $result = $this->repository->delete($id); + {{event}}::dispatch($result); - return $result; - } catch (ModelNotFoundException) { - throw new NotFoundException(); - } catch (\Exception) { - throw new DeleteResourceFailedException(); - } + return $result; } } diff --git a/src/Generator/Stubs/tasks/with_event/find.stub b/src/Generator/Stubs/tasks/with_event/find.stub index 592e178b..ddd9d189 100644 --- a/src/Generator/Stubs/tasks/with_event/find.stub +++ b/src/Generator/Stubs/tasks/with_event/find.stub @@ -11,7 +11,7 @@ use App\Ship\Parents\Tasks\Task as ParentTask; class {{class-name}} extends ParentTask { public function __construct( - protected readonly {{model}}Repository $repository, + private readonly {{model}}Repository $repository, ) { } @@ -21,10 +21,10 @@ class {{class-name}} extends ParentTask public function run($id): {{model}} { try { - ${{_model}} = $this->repository->find($id); - {{event}}::dispatch(${{_model}}); + ${{model_}} = $this->repository->find($id); + {{event}}::dispatch(${{model_}}); - return ${{_model}}; + return ${{model_}}; } catch (\Exception) { throw new NotFoundException(); } diff --git a/src/Generator/Stubs/tasks/with_event/list.stub b/src/Generator/Stubs/tasks/with_event/list.stub index 057e726a..5b716d0b 100644 --- a/src/Generator/Stubs/tasks/with_event/list.stub +++ b/src/Generator/Stubs/tasks/with_event/list.stub @@ -11,7 +11,7 @@ use Prettus\Repository\Exceptions\RepositoryException; class {{class-name}} extends ParentTask { public function __construct( - protected readonly {{model}}Repository $repository, + private readonly {{model}}Repository $repository, ) { } diff --git a/src/Generator/Stubs/tasks/with_event/update.stub b/src/Generator/Stubs/tasks/with_event/update.stub index b73d5d43..80f8238d 100644 --- a/src/Generator/Stubs/tasks/with_event/update.stub +++ b/src/Generator/Stubs/tasks/with_event/update.stub @@ -13,7 +13,7 @@ use Illuminate\Database\Eloquent\ModelNotFoundException; class {{class-name}} extends ParentTask { public function __construct( - protected readonly {{model}}Repository $repository, + private readonly {{model}}Repository $repository, ) { } @@ -24,10 +24,10 @@ class {{class-name}} extends ParentTask public function run(array $data, $id): {{model}} { try { - ${{_model}} = $this->repository->update($data, $id); - {{event}}::dispatch(${{_model}}); + ${{model_}} = $this->repository->update($data, $id); + {{event}}::dispatch(${{model_}}); - return ${{_model}}; + return ${{model_}}; } catch (ModelNotFoundException) { throw new NotFoundException(); } catch (\Exception) { diff --git a/src/Generator/Stubs/tests/functional/api.stub b/src/Generator/Stubs/tests/functional/api.stub index f816098f..c89fb365 100644 --- a/src/Generator/Stubs/tests/functional/api.stub +++ b/src/Generator/Stubs/tests/functional/api.stub @@ -3,11 +3,9 @@ namespace App\Containers\{{section-name}}\{{container-name}}\UI\API\Tests\Functional; use App\Containers\{{section-name}}\{{container-name}}\UI\API\Tests\ApiTestCase; +use PHPUnit\Framework\Attributes\CoversNothing; -/** - * @group {{_container-name}} - * @group api - */ +#[CoversNothing] class {{class-name}} extends ApiTestCase { // the endpoint to be called within this test (e.g., get@v1/users) @@ -15,8 +13,8 @@ class {{class-name}} extends ApiTestCase // fake some access rights protected array $access = [ - 'permissions' => '', - 'roles' => '', + 'permissions' => null, + 'roles' => null, ]; public function test(): void @@ -29,7 +27,7 @@ class {{class-name}} extends ApiTestCase $response = $this->makeCall($data); // assert the response status - $response->assertStatus(200); + $response->assertOk(); // make other asserts here } diff --git a/src/Generator/Stubs/tests/functional/cli.stub b/src/Generator/Stubs/tests/functional/cli.stub index ae497604..8a442c0d 100644 --- a/src/Generator/Stubs/tests/functional/cli.stub +++ b/src/Generator/Stubs/tests/functional/cli.stub @@ -4,10 +4,6 @@ namespace App\Containers\{{section-name}}\{{container-name}}\UI\CLI\Tests\Functi use App\Containers\{{section-name}}\{{container-name}}\UI\CLI\Tests\CliTestCase; -/** - * @group {{_container-name}} - * @group cli - */ class {{class-name}} extends CliTestCase { public function test(): void diff --git a/src/Generator/Stubs/tests/functional/create.stub b/src/Generator/Stubs/tests/functional/create.stub index a2284c38..bda81c48 100644 --- a/src/Generator/Stubs/tests/functional/create.stub +++ b/src/Generator/Stubs/tests/functional/create.stub @@ -4,18 +4,16 @@ namespace App\Containers\{{section-name}}\{{container-name}}\UI\API\Tests\Functi use App\Containers\{{section-name}}\{{container-name}}\UI\API\Tests\ApiTestCase; use Illuminate\Testing\Fluent\AssertableJson; +use PHPUnit\Framework\Attributes\CoversNothing; -/** - * @group {{_container-name}} - * @group api - */ +#[CoversNothing] class {{class-name}} extends ApiTestCase { protected string $endpoint = 'post@v1/{{url}}'; protected array $access = [ - 'permissions' => '', - 'roles' => '', + 'permissions' => null, + 'roles' => null, ]; // TODO TEST @@ -27,7 +25,7 @@ class {{class-name}} extends ApiTestCase $response = $this->makeCall($data); - $response->assertStatus(201); + $response->assertCreated(); $response->assertJson( fn (AssertableJson $json) => $json->has('data') @@ -47,7 +45,7 @@ class {{class-name}} extends ApiTestCase // // $response = $this->makeCall($data); // - // $response->assertStatus(422); + // $response->assertUnprocessable(); // // validate errors and their messages here // // $response->assertJson( // // fn (AssertableJson $json) => @@ -67,7 +65,7 @@ class {{class-name}} extends ApiTestCase // // $response = $this->makeCall([]); // - // $response->assertStatus(403); + // $response->assertForbidden(); // $response->assertJson( // fn (AssertableJson $json) => // $json->has('message') diff --git a/src/Generator/Stubs/tests/functional/delete.stub b/src/Generator/Stubs/tests/functional/delete.stub index 2ed4a386..ead94696 100644 --- a/src/Generator/Stubs/tests/functional/delete.stub +++ b/src/Generator/Stubs/tests/functional/delete.stub @@ -3,20 +3,17 @@ namespace App\Containers\{{section-name}}\{{container-name}}\UI\API\Tests\Functional; use App\Containers\{{section-name}}\{{container-name}}\Data\Factories\{{model}}Factory; -use App\Containers\{{section-name}}\{{container-name}}\Models\{{model}}; use App\Containers\{{section-name}}\{{container-name}}\UI\API\Tests\ApiTestCase; +use PHPUnit\Framework\Attributes\CoversNothing; -/** - * @group {{_container-name}} - * @group api - */ +#[CoversNothing] class {{class-name}} extends ApiTestCase { protected string $endpoint = 'delete@v1/{{url}}'; protected array $access = [ - 'permissions' => '', - 'roles' => '', + 'permissions' => null, + 'roles' => null, ]; public function testDeleteExisting{{model}}(): void @@ -25,7 +22,7 @@ class {{class-name}} extends ApiTestCase $response = $this->injectId(${{_model}}->id)->makeCall(); - $response->assertStatus(204); + $response->assertNoContent(); } public function testDeleteNonExisting{{model}}(): void @@ -34,7 +31,7 @@ class {{class-name}} extends ApiTestCase $response = $this->injectId($invalidId)->makeCall([]); - $response->assertStatus(404); + $response->assertNotFound(); } // TODO TEST @@ -48,6 +45,6 @@ class {{class-name}} extends ApiTestCase // // $response = $this->injectId(${{_model}}->id)->makeCall(); // - // $response->assertStatus(403); + // $response->assertForbidden(); // } } diff --git a/src/Generator/Stubs/tests/functional/find.stub b/src/Generator/Stubs/tests/functional/find.stub index 46e94deb..780082cf 100644 --- a/src/Generator/Stubs/tests/functional/find.stub +++ b/src/Generator/Stubs/tests/functional/find.stub @@ -3,21 +3,18 @@ namespace App\Containers\{{section-name}}\{{container-name}}\UI\API\Tests\Functional; use App\Containers\{{section-name}}\{{container-name}}\Data\Factories\{{model}}Factory; -use App\Containers\{{section-name}}\{{container-name}}\Models\{{model}}; use App\Containers\{{section-name}}\{{container-name}}\UI\API\Tests\ApiTestCase; use Illuminate\Testing\Fluent\AssertableJson; +use PHPUnit\Framework\Attributes\CoversNothing; -/** - * @group {{_container-name}} - * @group api - */ +#[CoversNothing] class {{class-name}} extends ApiTestCase { protected string $endpoint = 'get@v1/{{url}}'; protected array $access = [ - 'permissions' => '', - 'roles' => '', + 'permissions' => null, + 'roles' => null, ]; public function testFind{{model}}(): void @@ -26,7 +23,7 @@ class {{class-name}} extends ApiTestCase $response = $this->injectId(${{_model}}->id)->makeCall(); - $response->assertStatus(200); + $response->assertOk(); $response->assertJson( fn (AssertableJson $json) => $json->has('data') @@ -41,7 +38,7 @@ class {{class-name}} extends ApiTestCase $response = $this->injectId($invalidId)->makeCall([]); - $response->assertStatus(404); + $response->assertNotFound(); } public function testFindFiltered{{model}}Response(): void @@ -50,7 +47,7 @@ class {{class-name}} extends ApiTestCase $response = $this->injectId(${{_model}}->id)->endpoint($this->endpoint . '?filter=id')->makeCall(); - $response->assertStatus(200); + $response->assertOk(); $response->assertJson( fn (AssertableJson $json) => $json->has('data') @@ -71,7 +68,7 @@ class {{class-name}} extends ApiTestCase // // $response = $this->injectId(${{_model}}->id)->endpoint($this->endpoint . "?include=$relation")->makeCall(); // - // $response->assertStatus(200); + // $response->assertOk(); // $response->assertJson( // fn (AssertableJson $json) => // $json->has('data') diff --git a/src/Generator/Stubs/tests/functional/generic.stub b/src/Generator/Stubs/tests/functional/generic.stub index 9d767833..d3b2aa96 100644 --- a/src/Generator/Stubs/tests/functional/generic.stub +++ b/src/Generator/Stubs/tests/functional/generic.stub @@ -4,10 +4,6 @@ namespace App\Containers\{{section-name}}\{{container-name}}\UI\API\Tests\Functi use App\Containers\{{section-name}}\{{container-name}}\Tests\TestCase; -/** - * @group {{_container-name}} - * @group general - */ class {{class-name}} extends TestCase { public function test(): void diff --git a/src/Generator/Stubs/tests/functional/list.stub b/src/Generator/Stubs/tests/functional/list.stub index 2e431708..57ccd67d 100644 --- a/src/Generator/Stubs/tests/functional/list.stub +++ b/src/Generator/Stubs/tests/functional/list.stub @@ -3,21 +3,18 @@ namespace App\Containers\{{section-name}}\{{container-name}}\UI\API\Tests\Functional; use App\Containers\{{section-name}}\{{container-name}}\Data\Factories\{{model}}Factory; -use App\Containers\{{section-name}}\{{container-name}}\Models\{{model}}; use App\Containers\{{section-name}}\{{container-name}}\UI\API\Tests\ApiTestCase; use Illuminate\Testing\Fluent\AssertableJson; +use PHPUnit\Framework\Attributes\CoversNothing; -/** - * @group {{_container-name}} - * @group api - */ +#[CoversNothing] class {{class-name}} extends ApiTestCase { protected string $endpoint = 'get@v1/{{url}}'; protected array $access = [ - 'permissions' => '', - 'roles' => '', + 'permissions' => null, + 'roles' => null, ]; public function testList{{models}}ByAdmin(): void @@ -27,7 +24,7 @@ class {{class-name}} extends ApiTestCase $response = $this->makeCall(); - $response->assertStatus(200); + $response->assertOk(); $responseContent = $this->getResponseContentObject(); $this->assertCount(2, $responseContent->data); @@ -44,7 +41,7 @@ class {{class-name}} extends ApiTestCase // // $response = $this->makeCall(); // - // $response->assertStatus(403); + // $response->assertForbidden(); // $response->assertJson( // fn (AssertableJson $json) => // $json->has('message') @@ -65,7 +62,7 @@ class {{class-name}} extends ApiTestCase // // search by the above values // $response = $this->endpoint($this->endpoint . "?search=name:" . urlencode(${{_model}}->name))->makeCall(); // - // $response->assertStatus(200); + // $response->assertOk(); // $response->assertJson( // fn (AssertableJson $json) => // $json->has('data') @@ -74,19 +71,20 @@ class {{class-name}} extends ApiTestCase // ); // } - public function testSearch{{models}}ByHashID(): void - { - ${{_models}} = {{model}}Factory::new()->count(3)->create(); - $second{{model}} = ${{_models}}[1]; - - $response = $this->endpoint($this->endpoint . '?search=id:' . $second{{model}}->getHashedKey())->makeCall(); - - $response->assertStatus(200); - $response->assertJson( - fn (AssertableJson $json) => - $json->has('data') - ->where('data.0.id', $second{{model}}->getHashedKey()) - ->etc() - ); - } + // TODO TEST + // public function testSearch{{models}}ByHashID(): void + // { + // ${{_models}} = {{model}}Factory::new()->count(3)->create(); + // $second{{model}} = ${{_models}}[1]; + // + // $response = $this->endpoint($this->endpoint . '?search=id:' . $second{{model}}->getHashedKey())->makeCall(); + // + // $response->assertOk(); + // $response->assertJson( + // fn (AssertableJson $json) => + // $json->has('data') + // ->where('data.0.id', $second{{model}}->getHashedKey()) + // ->etc() + // ); + // } } diff --git a/src/Generator/Stubs/tests/functional/update.stub b/src/Generator/Stubs/tests/functional/update.stub index 3d91b6ef..fe845b4e 100644 --- a/src/Generator/Stubs/tests/functional/update.stub +++ b/src/Generator/Stubs/tests/functional/update.stub @@ -3,21 +3,18 @@ namespace App\Containers\{{section-name}}\{{container-name}}\UI\API\Tests\Functional; use App\Containers\{{section-name}}\{{container-name}}\Data\Factories\{{model}}Factory; -use App\Containers\{{section-name}}\{{container-name}}\Models\{{model}}; use App\Containers\{{section-name}}\{{container-name}}\UI\API\Tests\ApiTestCase; use Illuminate\Testing\Fluent\AssertableJson; +use PHPUnit\Framework\Attributes\CoversNothing; -/** - * @group {{_container-name}} - * @group api - */ +#[CoversNothing] class {{class-name}} extends ApiTestCase { protected string $endpoint = 'patch@v1/{{url}}'; protected array $access = [ - 'permissions' => '', - 'roles' => '', + 'permissions' => null, + 'roles' => null, ]; // TODO TEST @@ -32,7 +29,7 @@ class {{class-name}} extends ApiTestCase $response = $this->injectId(${{_model}}->id)->makeCall($data); - $response->assertStatus(200); + $response->assertOk(); $response->assertJson( fn (AssertableJson $json) => $json->has('data') @@ -49,7 +46,7 @@ class {{class-name}} extends ApiTestCase $response = $this->injectId($invalidId)->makeCall([]); - $response->assertStatus(404); + $response->assertNotFound(); } // TODO TEST @@ -64,7 +61,7 @@ class {{class-name}} extends ApiTestCase // // $response = $this->injectId(${{_model}}->id)->makeCall($data); // - // $response->assertStatus(422); + // $response->assertUnprocessable(); // $response->assertJson( // fn (AssertableJson $json) => // $json->has('errors') diff --git a/src/Generator/Stubs/tests/functional/web.stub b/src/Generator/Stubs/tests/functional/web.stub index d5f9ebfb..0dbc10d5 100644 --- a/src/Generator/Stubs/tests/functional/web.stub +++ b/src/Generator/Stubs/tests/functional/web.stub @@ -3,20 +3,16 @@ namespace App\Containers\{{section-name}}\{{container-name}}\UI\WEB\Tests\Functional; use App\Containers\{{section-name}}\{{container-name}}\UI\WEB\Tests\WebTestCase; +use PHPUnit\Framework\Attributes\CoversNothing; -/** - * @group {{_container-name}} - * @group web - */ +#[CoversNothing] class {{class-name}} extends WebTestCase { - // the endpoint to be called within this test (e.g., get@v1/users) protected string $endpoint = 'method@endpoint'; - // fake some access rights protected array $access = [ - 'permissions' => '', - 'roles' => '', + 'permissions' => null, + 'roles' => null, ]; public function test(): void @@ -29,8 +25,6 @@ class {{class-name}} extends WebTestCase $response = $this->makeCall($data); // assert the response status - $response->assertStatus(200); - - // make other asserts here + $response->assertOk(); } } diff --git a/src/Generator/Stubs/tests/testcase/api.stub b/src/Generator/Stubs/tests/testcase/api.stub index f2bc9cd1..ec7e5ae8 100644 --- a/src/Generator/Stubs/tests/testcase/api.stub +++ b/src/Generator/Stubs/tests/testcase/api.stub @@ -2,7 +2,7 @@ namespace App\Containers\{{section-name}}\{{container-name}}\UI\API\Tests; -use App\Ship\Parents\Tests\PhpUnit\TestCase as ParentTestCase; +use App\Ship\Parents\Tests\TestCase as ParentTestCase; class {{class-name}} extends ParentTestCase { diff --git a/src/Generator/Stubs/tests/testcase/cli.stub b/src/Generator/Stubs/tests/testcase/cli.stub index 264e2208..78f59540 100644 --- a/src/Generator/Stubs/tests/testcase/cli.stub +++ b/src/Generator/Stubs/tests/testcase/cli.stub @@ -2,7 +2,7 @@ namespace App\Containers\{{section-name}}\{{container-name}}\UI\CLI\Tests; -use App\Ship\Parents\Tests\PhpUnit\TestCase as ParentTestCase; +use App\Ship\Parents\Tests\TestCase as ParentTestCase; class {{class-name}} extends ParentTestCase { diff --git a/src/Generator/Stubs/tests/testcase/unit.stub b/src/Generator/Stubs/tests/testcase/unit.stub index 7e85ba06..aed4328e 100644 --- a/src/Generator/Stubs/tests/testcase/unit.stub +++ b/src/Generator/Stubs/tests/testcase/unit.stub @@ -2,7 +2,7 @@ namespace App\Containers\{{section-name}}\{{container-name}}\Tests; -use App\Ship\Parents\Tests\PhpUnit\TestCase as ParentTestCase; +use App\Ship\Parents\Tests\TestCase as ParentTestCase; class {{class-name}} extends ParentTestCase { diff --git a/src/Generator/Stubs/tests/testcase/web.stub b/src/Generator/Stubs/tests/testcase/web.stub index 89dc0c60..c64b93c8 100644 --- a/src/Generator/Stubs/tests/testcase/web.stub +++ b/src/Generator/Stubs/tests/testcase/web.stub @@ -2,7 +2,7 @@ namespace App\Containers\{{section-name}}\{{container-name}}\UI\WEB\Tests; -use App\Ship\Parents\Tests\PhpUnit\TestCase as ParentTestCase; +use App\Ship\Parents\Tests\TestCase as ParentTestCase; class {{class-name}} extends ParentTestCase { diff --git a/src/Generator/Stubs/tests/unit/create.stub b/src/Generator/Stubs/tests/unit/create.stub index 74518315..1a012fec 100644 --- a/src/Generator/Stubs/tests/unit/create.stub +++ b/src/Generator/Stubs/tests/unit/create.stub @@ -4,13 +4,9 @@ namespace App\Containers\{{section-name}}\{{container-name}}\Tests\Unit; use App\Containers\{{section-name}}\{{container-name}}\Tasks\Create{{model}}Task; use App\Containers\{{section-name}}\{{container-name}}\Tests\UnitTestCase; +use PHPUnit\Framework\Attributes\CoversClass; -use App\Ship\Exceptions\CreateResourceFailedException; - -/** - * @group {{_container-name}} - * @group unit - */ +#[CoversClass(Create{{model}}Task::class)] class {{class-name}} extends UnitTestCase { public function testCreate{{model}}(): void @@ -21,17 +17,4 @@ class {{class-name}} extends UnitTestCase $this->assertModelExists(${{_model}}); } - - // TODO TEST - // public function testCreate{{model}}WithInvalidData(): void - // { - // $this->expectException(CreateResourceFailedException::class); - // - // $data = [ - // // put some invalid data here - // // 'invalid' => 'data', - // ]; - // - // app(Create{{model}}Task::class)->run($data); - // } } diff --git a/src/Generator/Stubs/tests/unit/delete.stub b/src/Generator/Stubs/tests/unit/delete.stub index 1341c845..0a0352bf 100644 --- a/src/Generator/Stubs/tests/unit/delete.stub +++ b/src/Generator/Stubs/tests/unit/delete.stub @@ -5,12 +5,9 @@ namespace App\Containers\{{section-name}}\{{container-name}}\Tests\Unit; use App\Containers\{{section-name}}\{{container-name}}\Data\Factories\{{model}}Factory; use App\Containers\{{section-name}}\{{container-name}}\Tasks\Delete{{model}}Task; use App\Containers\{{section-name}}\{{container-name}}\Tests\UnitTestCase; -use App\Ship\Exceptions\NotFoundException; +use PHPUnit\Framework\Attributes\CoversClass; -/** - * @group {{_container-name}} - * @group unit - */ +#[CoversClass(Delete{{model}}Task::class)] class {{class-name}} extends UnitTestCase { public function testDelete{{model}}(): void @@ -21,13 +18,4 @@ class {{class-name}} extends UnitTestCase $this->assertEquals(1, $result); } - - public function testDelete{{model}}WithInvalidId(): void - { - $this->expectException(NotFoundException::class); - - $noneExistingId = 777777; - - app(Delete{{model}}Task::class)->run($noneExistingId); - } } diff --git a/src/Generator/Stubs/tests/unit/factory.stub b/src/Generator/Stubs/tests/unit/factory.stub index 8d1f6dad..afd4cdc4 100644 --- a/src/Generator/Stubs/tests/unit/factory.stub +++ b/src/Generator/Stubs/tests/unit/factory.stub @@ -5,11 +5,9 @@ namespace App\Containers\{{section-name}}\{{container-name}}\Tests\Unit; use App\Containers\{{section-name}}\{{container-name}}\Data\Factories\{{model}}Factory; use App\Containers\{{section-name}}\{{container-name}}\Models\{{model}}; use App\Containers\{{section-name}}\{{container-name}}\Tests\UnitTestCase; +use PHPUnit\Framework\Attributes\CoversClass; -/** - * @group {{_container-name}} - * @group unit - */ +#[CoversClass({{model}}Factory::class)] class {{class-name}} extends UnitTestCase { public function testCreate{{model}}(): void diff --git a/src/Generator/Stubs/tests/unit/find.stub b/src/Generator/Stubs/tests/unit/find.stub index 5a64addd..c5f955e9 100644 --- a/src/Generator/Stubs/tests/unit/find.stub +++ b/src/Generator/Stubs/tests/unit/find.stub @@ -5,12 +5,9 @@ namespace App\Containers\{{section-name}}\{{container-name}}\Tests\Unit; use App\Containers\{{section-name}}\{{container-name}}\Data\Factories\{{model}}Factory; use App\Containers\{{section-name}}\{{container-name}}\Tasks\Find{{model}}ByIdTask; use App\Containers\{{section-name}}\{{container-name}}\Tests\UnitTestCase; -use App\Ship\Exceptions\NotFoundException; +use PHPUnit\Framework\Attributes\CoversClass; -/** - * @group {{_container-name}} - * @group unit - */ +#[CoversClass(Find{{model}}ByIdTask::class)] class {{class-name}} extends UnitTestCase { public function testFind{{model}}ById(): void @@ -21,13 +18,4 @@ class {{class-name}} extends UnitTestCase $this->assertEquals(${{_model}}->id, $found{{model}}->id); } - - public function testFind{{model}}WithInvalidId(): void - { - $this->expectException(NotFoundException::class); - - $noneExistingId = 777777; - - app(Find{{model}}ByIdTask::class)->run($noneExistingId); - } } diff --git a/src/Generator/Stubs/tests/unit/generic.stub b/src/Generator/Stubs/tests/unit/generic.stub index b70d9002..bd6ecb9c 100644 --- a/src/Generator/Stubs/tests/unit/generic.stub +++ b/src/Generator/Stubs/tests/unit/generic.stub @@ -4,10 +4,6 @@ namespace App\Containers\{{section-name}}\{{container-name}}\Tests\Unit; use App\Containers\{{section-name}}\{{container-name}}\Tests\UnitTestCase; -/** - * @group {{_container-name}} - * @group unit - */ class {{class-name}} extends UnitTestCase { public function test(): void diff --git a/src/Generator/Stubs/tests/unit/list.stub b/src/Generator/Stubs/tests/unit/list.stub index 69493519..ec477fd6 100644 --- a/src/Generator/Stubs/tests/unit/list.stub +++ b/src/Generator/Stubs/tests/unit/list.stub @@ -6,11 +6,9 @@ use App\Containers\{{section-name}}\{{container-name}}\Data\Factories\{{model}}F use App\Containers\{{section-name}}\{{container-name}}\Tasks\List{{models}}Task; use App\Containers\{{section-name}}\{{container-name}}\Tests\UnitTestCase; use Illuminate\Contracts\Pagination\LengthAwarePaginator; +use PHPUnit\Framework\Attributes\CoversClass; -/** - * @group {{_container-name}} - * @group unit - */ +#[CoversClass(List{{models}}Task::class)] class {{class-name}} extends UnitTestCase { public function testList{{models}}(): void diff --git a/src/Generator/Stubs/tests/unit/migration.stub b/src/Generator/Stubs/tests/unit/migration.stub index 73ed7ebe..c659c55d 100644 --- a/src/Generator/Stubs/tests/unit/migration.stub +++ b/src/Generator/Stubs/tests/unit/migration.stub @@ -3,25 +3,19 @@ namespace App\Containers\{{section-name}}\{{container-name}}\Tests\Unit; use App\Containers\{{section-name}}\{{container-name}}\Tests\UnitTestCase; -use Illuminate\Support\Facades\Schema; +use PHPUnit\Framework\Attributes\CoversNothing; -/** - * @group {{_container-name}} - * @group unit - */ +#[CoversNothing] class {{class-name}} extends UnitTestCase { - public function test_{{table-name}}_table_has_expected_columns(): void + public function test{{_table-name_}}TableHasExpectedColumns(): void { $columns = [ - 'id', - // add your migration columns - 'created_at', - 'updated_at', + 'id' => 'bigint', + 'created_at' => 'datetime', + 'updated_at' => 'datetime', ]; - foreach ($columns as $column) { - $this->assertTrue(Schema::hasColumn('{{table-name}}', $column)); - } + $this->assertDatabaseTable('{{table-name}}', $columns); } } diff --git a/src/Generator/Stubs/tests/unit/update.stub b/src/Generator/Stubs/tests/unit/update.stub index 1dce0127..8106c033 100644 --- a/src/Generator/Stubs/tests/unit/update.stub +++ b/src/Generator/Stubs/tests/unit/update.stub @@ -5,12 +5,9 @@ namespace App\Containers\{{section-name}}\{{container-name}}\Tests\Unit; use App\Containers\{{section-name}}\{{container-name}}\Data\Factories\{{model}}Factory; use App\Containers\{{section-name}}\{{container-name}}\Tasks\Update{{model}}Task; use App\Containers\{{section-name}}\{{container-name}}\Tests\UnitTestCase; -use App\Ship\Exceptions\NotFoundException; +use PHPUnit\Framework\Attributes\CoversClass; -/** - * @group {{_container-name}} - * @group unit - */ +#[CoversClass(Update{{model}}Task::class)] class {{class-name}} extends UnitTestCase { // TODO TEST @@ -26,16 +23,6 @@ class {{class-name}} extends UnitTestCase $updated{{model}} = app(Update{{model}}Task::class)->run($data, ${{_model}}->id); $this->assertEquals(${{_model}}->id, $updated{{model}}->id); - // assert if fields are updated // $this->assertEquals($data['some_field'], $updated{{model}}->some_field); } - - public function testUpdate{{model}}WithInvalidId(): void - { - $this->expectException(NotFoundException::class); - - $noneExistingId = 777777; - - app(Update{{model}}Task::class)->run([], $noneExistingId); - } } diff --git a/src/Generator/Stubs/tests/unit/with_event/create.stub b/src/Generator/Stubs/tests/unit/with_event/create.stub index a3db4b29..7a820c46 100644 --- a/src/Generator/Stubs/tests/unit/with_event/create.stub +++ b/src/Generator/Stubs/tests/unit/with_event/create.stub @@ -5,13 +5,10 @@ namespace App\Containers\{{section-name}}\{{container-name}}\Tests\Unit; use App\Containers\{{section-name}}\{{container-name}}\Events\{{event}}; use App\Containers\{{section-name}}\{{container-name}}\Tasks\Create{{model}}Task; use App\Containers\{{section-name}}\{{container-name}}\Tests\UnitTestCase; -use App\Ship\Exceptions\CreateResourceFailedException; use Illuminate\Support\Facades\Event; +use PHPUnit\Framework\Attributes\CoversClass; -/** - * @group {{_container-name}} - * @group unit - */ +#[CoversClass(Create{{model}}Task::class)] class {{class-name}} extends UnitTestCase { public function testCreate{{model}}(): void @@ -24,17 +21,4 @@ class {{class-name}} extends UnitTestCase $this->assertModelExists(${{_model}}); Event::assertDispatched({{event}}::class); } - - // TODO TEST - // public function testCreate{{model}}WithInvalidData(): void - // { - // $this->expectException(CreateResourceFailedException::class); - // - // $data = [ - // // put some invalid data here - // // 'invalid' => 'data', - // ]; - // - // app(Create{{model}}Task::class)->run($data); - // } } diff --git a/src/Generator/Stubs/tests/unit/with_event/delete.stub b/src/Generator/Stubs/tests/unit/with_event/delete.stub index 16b7047f..2c494a48 100644 --- a/src/Generator/Stubs/tests/unit/with_event/delete.stub +++ b/src/Generator/Stubs/tests/unit/with_event/delete.stub @@ -6,13 +6,10 @@ use App\Containers\{{section-name}}\{{container-name}}\Data\Factories\{{model}}F use App\Containers\{{section-name}}\{{container-name}}\Events\{{event}}; use App\Containers\{{section-name}}\{{container-name}}\Tasks\Delete{{model}}Task; use App\Containers\{{section-name}}\{{container-name}}\Tests\UnitTestCase; -use App\Ship\Exceptions\NotFoundException; use Illuminate\Support\Facades\Event; +use PHPUnit\Framework\Attributes\CoversClass; -/** - * @group {{_container-name}} - * @group unit - */ +#[CoversClass(Delete{{model}}Task::class)] class {{class-name}} extends UnitTestCase { public function testDelete{{model}}(): void @@ -25,13 +22,4 @@ class {{class-name}} extends UnitTestCase $this->assertEquals(1, $result); Event::assertDispatched({{event}}::class); } - - public function testDelete{{model}}WithInvalidId(): void - { - $this->expectException(NotFoundException::class); - - $noneExistingId = 777777; - - app(Delete{{model}}Task::class)->run($noneExistingId); - } } diff --git a/src/Generator/Stubs/tests/unit/with_event/find.stub b/src/Generator/Stubs/tests/unit/with_event/find.stub index 88d297f3..a2cf1adf 100644 --- a/src/Generator/Stubs/tests/unit/with_event/find.stub +++ b/src/Generator/Stubs/tests/unit/with_event/find.stub @@ -6,13 +6,10 @@ use App\Containers\{{section-name}}\{{container-name}}\Data\Factories\{{model}}F use App\Containers\{{section-name}}\{{container-name}}\Events\{{event}}; use App\Containers\{{section-name}}\{{container-name}}\Tasks\Find{{model}}ByIdTask; use App\Containers\{{section-name}}\{{container-name}}\Tests\UnitTestCase; -use App\Ship\Exceptions\NotFoundException; use Illuminate\Support\Facades\Event; +use PHPUnit\Framework\Attributes\CoversClass; -/** - * @group {{_container-name}} - * @group unit - */ +#[CoversClass(Find{{model}}ByIdTask::class)] class {{class-name}} extends UnitTestCase { public function testFind{{model}}ById(): void @@ -25,13 +22,4 @@ class {{class-name}} extends UnitTestCase $this->assertEquals(${{_model}}->id, $found{{model}}->id); Event::assertDispatched({{event}}::class); } - - public function testFind{{model}}WithInvalidId(): void - { - $this->expectException(NotFoundException::class); - - $noneExistingId = 777777; - - app(Find{{model}}ByIdTask::class)->run($noneExistingId); - } } diff --git a/src/Generator/Stubs/tests/unit/with_event/list.stub b/src/Generator/Stubs/tests/unit/with_event/list.stub index 41c67033..49967bbd 100644 --- a/src/Generator/Stubs/tests/unit/with_event/list.stub +++ b/src/Generator/Stubs/tests/unit/with_event/list.stub @@ -8,11 +8,9 @@ use App\Containers\{{section-name}}\{{container-name}}\Tasks\List{{models}}Task; use App\Containers\{{section-name}}\{{container-name}}\Tests\UnitTestCase; use Illuminate\Contracts\Pagination\LengthAwarePaginator; use Illuminate\Support\Facades\Event; +use PHPUnit\Framework\Attributes\CoversClass; -/** - * @group {{_container-name}} - * @group unit - */ +#[CoversClass(List{{models}}Task::class)] class {{class-name}} extends UnitTestCase { public function testList{{models}}(): void diff --git a/src/Generator/Stubs/tests/unit/with_event/update.stub b/src/Generator/Stubs/tests/unit/with_event/update.stub index 4a206988..a655ad4e 100644 --- a/src/Generator/Stubs/tests/unit/with_event/update.stub +++ b/src/Generator/Stubs/tests/unit/with_event/update.stub @@ -6,13 +6,10 @@ use App\Containers\{{section-name}}\{{container-name}}\Data\Factories\{{model}}F use App\Containers\{{section-name}}\{{container-name}}\Events\{{event}}; use App\Containers\{{section-name}}\{{container-name}}\Tasks\Update{{model}}Task; use App\Containers\{{section-name}}\{{container-name}}\Tests\UnitTestCase; -use App\Ship\Exceptions\NotFoundException; use Illuminate\Support\Facades\Event; +use PHPUnit\Framework\Attributes\CoversClass; -/** - * @group {{_container-name}} - * @group unit - */ +#[CoversClass(Update{{model}}Task::class)] class {{class-name}} extends UnitTestCase { // TODO TEST @@ -21,24 +18,13 @@ class {{class-name}} extends UnitTestCase Event::fake(); ${{_model}} = {{model}}Factory::new()->createOne(); $data = [ - // add some fillable fields here // 'some_field' => 'new_field_data', ]; $updated{{model}} = app(Update{{model}}Task::class)->run($data, ${{_model}}->id); $this->assertEquals(${{_model}}->id, $updated{{model}}->id); - // assert if fields are updated // $this->assertEquals($data['some_field'], $updated{{model}}->some_field); Event::assertDispatched({{event}}::class); } - - public function testUpdate{{model}}WithInvalidId(): void - { - $this->expectException(NotFoundException::class); - - $noneExistingId = 777777; - - app(Update{{model}}Task::class)->run([], $noneExistingId); - } } diff --git a/src/Generator/Stubs/transformer.stub b/src/Generator/Stubs/transformer.stub index 3d376de5..0ff682d3 100644 --- a/src/Generator/Stubs/transformer.stub +++ b/src/Generator/Stubs/transformer.stub @@ -7,27 +7,18 @@ use App\Ship\Parents\Transformers\Transformer as ParentTransformer; class {{class-name}} extends ParentTransformer { - protected array $defaultIncludes = [ + protected array $defaultIncludes = []; - ]; - - protected array $availableIncludes = [ - - ]; + protected array $availableIncludes = []; public function transform({{model}} ${{_model}}): array { - $response = [ + return [ {{attributes}} - ]; - - return $this->ifAdmin([ - 'real_id' => ${{_model}}->id, 'created_at' => ${{_model}}->created_at, 'updated_at' => ${{_model}}->updated_at, 'readable_created_at' => ${{_model}}->created_at->diffForHumans(), 'readable_updated_at' => ${{_model}}->updated_at->diffForHumans(), - // 'deleted_at' => ${{_model}}->deleted_at, - ], $response); + ]; } } diff --git a/src/Generator/Stubs/value.stub b/src/Generator/Stubs/value.stub index 57051ba6..69665216 100644 --- a/src/Generator/Stubs/value.stub +++ b/src/Generator/Stubs/value.stub @@ -6,8 +6,4 @@ use App\Ship\Parents\Values\Value as ParentValue; class {{class-name}} extends ParentValue { - /** - * A resource key to be used by the the JSON API Serializer responses. - */ - protected string $resourceKey = '{{resource-key}}'; }