From 2bb7a1b8d325fc3f0f546ebcea0f5c29903a6d21 Mon Sep 17 00:00:00 2001 From: Stiven Katuuk Date: Sat, 4 Feb 2023 15:17:49 +0800 Subject: [PATCH 1/3] build: add testbench laravel 10 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index ced1b0b..bb6e8fd 100644 --- a/composer.json +++ b/composer.json @@ -51,7 +51,7 @@ "laravel/pint": "^1.2", "pestphp/pest": "^1.22", "pestphp/pest-plugin-laravel": "^1.3", - "orchestra/testbench": "^7.14", + "orchestra/testbench": "^7.14|^8.0", "phpstan/phpstan": "^1.9" }, "config": { From 1a28f0ca65cb3075f94bda2f33be0f2c746eb897 Mon Sep 17 00:00:00 2001 From: Stiven Katuuk Date: Sat, 4 Feb 2023 15:40:11 +0800 Subject: [PATCH 2/3] fix(command): DataTransferObject at the wrong places --- .../DataTransferObjectMakeCommand.php | 11 ++- .../DataTransferObjectMakeCommandTest.php | 84 ++++++++++++++++++ .../RequestMakeCommandTest.php | 0 .../ResourceMakeCommandTest.php | 0 .../DataTransferObjectMakeCommandTest.php | 85 ------------------- .../{ => Domain}/ActionMakeCommandTest.php | 0 .../{ => Domain}/BuilderMakeCommandTest.php | 0 .../{ => Domain}/EnumMakeCommandTest.php | 0 .../{ => Domain}/ModelMakeCommandTest.php | 0 .../ValueObjectMakeCommandTest.php | 0 .../EventMakeCommandTest.php | 0 .../FactoryMakeCommandTest.php | 0 .../ListenerMakeCommandTest.php | 0 .../MailMakeCommandTest.php | 0 .../ObserverMakeCommandTest.php | 0 .../ProviderMakeCommandTest.php | 0 .../SeederMakeCommandTest.php | 0 tests/Pest.php | 1 + 18 files changed, 90 insertions(+), 91 deletions(-) rename src/Commands/{Domain => Application}/DataTransferObjectMakeCommand.php (77%) create mode 100644 tests/Feature/Commands/Application/DataTransferObjectMakeCommandTest.php rename tests/Feature/Commands/{ => Application}/RequestMakeCommandTest.php (100%) rename tests/Feature/Commands/{ => Application}/ResourceMakeCommandTest.php (100%) delete mode 100644 tests/Feature/Commands/DataTransferObjectMakeCommandTest.php rename tests/Feature/Commands/{ => Domain}/ActionMakeCommandTest.php (100%) rename tests/Feature/Commands/{ => Domain}/BuilderMakeCommandTest.php (100%) rename tests/Feature/Commands/{ => Domain}/EnumMakeCommandTest.php (100%) rename tests/Feature/Commands/{ => Domain}/ModelMakeCommandTest.php (100%) rename tests/Feature/Commands/{ => Domain}/ValueObjectMakeCommandTest.php (100%) rename tests/Feature/Commands/{ => Infrastructure}/EventMakeCommandTest.php (100%) rename tests/Feature/Commands/{ => Infrastructure}/FactoryMakeCommandTest.php (100%) rename tests/Feature/Commands/{ => Infrastructure}/ListenerMakeCommandTest.php (100%) rename tests/Feature/Commands/{ => Infrastructure}/MailMakeCommandTest.php (100%) rename tests/Feature/Commands/{ => Infrastructure}/ObserverMakeCommandTest.php (100%) rename tests/Feature/Commands/{ => Infrastructure}/ProviderMakeCommandTest.php (100%) rename tests/Feature/Commands/{ => Infrastructure}/SeederMakeCommandTest.php (100%) diff --git a/src/Commands/Domain/DataTransferObjectMakeCommand.php b/src/Commands/Application/DataTransferObjectMakeCommand.php similarity index 77% rename from src/Commands/Domain/DataTransferObjectMakeCommand.php rename to src/Commands/Application/DataTransferObjectMakeCommand.php index 5d53719..dd833d5 100644 --- a/src/Commands/Domain/DataTransferObjectMakeCommand.php +++ b/src/Commands/Application/DataTransferObjectMakeCommand.php @@ -1,11 +1,11 @@ resolveDomainArgument(), nameArgument: $this->resolveNameArgument(), - endsWith: 'DataTransferObjects', ) ); } diff --git a/tests/Feature/Commands/Application/DataTransferObjectMakeCommandTest.php b/tests/Feature/Commands/Application/DataTransferObjectMakeCommandTest.php new file mode 100644 index 0000000..aa30307 --- /dev/null +++ b/tests/Feature/Commands/Application/DataTransferObjectMakeCommandTest.php @@ -0,0 +1,84 @@ +tap(function () { + $filePath = app_path(path: 'DataTransferObjects/Post/PostData.php'); + + expect(value: File::exists(path: $filePath))->toBeFalse(); + + Artisan::call(command: 'diamond:install'); + Artisan::call(command: 'application:make:data-transfer-object PostData Post'); + + expect(value: File::exists(path: $filePath))->toBeTrue() + ->and( + value: Str::contains( + haystack: File::get(path: $filePath), + needles: ['{{ class }}', '{{ namespace }}'] + ) + )->toBeFalse(); + }) + ->group(groups: 'commands'); + +it(description: 'can generate new DTO with separator') + ->tap(function () { + $filePath = app_path(path: 'DataTransferObjects/Post/Foo/BarData.php'); + + expect(value: File::exists(path: $filePath))->toBeFalse(); + + Artisan::call(command: 'diamond:install'); + Artisan::call(command: 'application:make:data-transfer-object Foo/BarData Post'); + + expect(value: File::exists(path: $filePath)) + ->toBeTrue() + ->and( + value: Str::contains( + haystack: File::get(path: $filePath), + needles: ['{{ class }}', '{{ namespace }}'] + ) + ) + ->toBeFalse(); + }) + ->group(groups: 'commands'); + +it(description: 'can force generate exists DTO') + ->tap(function () { + $filePath = app_path(path: 'DataTransferObjects/Post/PostData.php'); + + expect(value: File::exists(path: $filePath))->toBeFalse(); + + Artisan::call(command: 'diamond:install'); + Artisan::call(command: 'application:make:data-transfer-object PostData Post'); + Artisan::call(command: 'application:make:data-transfer-object PostData Post --force'); + + expect(value: File::exists(path: $filePath))->toBeTrue() + ->and( + value: Str::contains( + haystack: File::get(path: $filePath), + needles: ['{{ class }}', '{{ namespace }}'] + ) + )->toBeFalse(); + }) + ->group(groups: 'commands'); + +it(description: 'cannot generate the DTO, if the DTO already exists') + ->tap(function () { + $filePath = app_path(path: 'DataTransferObjects/Post/PostData.php'); + + expect(value: File::exists(path: $filePath))->toBeFalse(); + + Artisan::call(command: 'diamond:install'); + Artisan::call(command: 'application:make:data-transfer-object PostData Post'); + + expect(value:File::exists(path: $filePath))->toBeTrue(); + + Artisan::call(command: 'application:make:data-transfer-object PostData Post'); + }) + ->group(groups: 'commands') + ->throws(exception: FileAlreadyExistException::class); diff --git a/tests/Feature/Commands/RequestMakeCommandTest.php b/tests/Feature/Commands/Application/RequestMakeCommandTest.php similarity index 100% rename from tests/Feature/Commands/RequestMakeCommandTest.php rename to tests/Feature/Commands/Application/RequestMakeCommandTest.php diff --git a/tests/Feature/Commands/ResourceMakeCommandTest.php b/tests/Feature/Commands/Application/ResourceMakeCommandTest.php similarity index 100% rename from tests/Feature/Commands/ResourceMakeCommandTest.php rename to tests/Feature/Commands/Application/ResourceMakeCommandTest.php diff --git a/tests/Feature/Commands/DataTransferObjectMakeCommandTest.php b/tests/Feature/Commands/DataTransferObjectMakeCommandTest.php deleted file mode 100644 index f1180bd..0000000 --- a/tests/Feature/Commands/DataTransferObjectMakeCommandTest.php +++ /dev/null @@ -1,85 +0,0 @@ -tap(function () { - $fileName = '/Post/DataTransferObjects/PostData.php'; - - expect(value: fileExists(relativeFileName: $fileName))->toBeFalse(); - - Artisan::call(command: 'diamond:install'); - Artisan::call(command: 'domain:make:data-transfer-object PostData Post'); - - expect(value: fileExists(relativeFileName: $fileName))->toBeTrue() - ->and( - value: Str::contains( - haystack: fileGet(relativeFileName: $fileName), - needles: ['{{ class }}', '{{ namespace }}'] - ) - )->toBeFalse(); - }) - ->group(groups: 'commands'); - -it(description: 'can generate new DTO with separator') - ->tap(function () { - $fileName = '/Post/DataTransferObjects/Foo/BarData.php'; - - expect(fileExists($fileName))->toBeFalse(); - - Artisan::call(command: 'diamond:install'); - Artisan::call(command: 'domain:make:data-transfer-object Foo/BarData Post'); - - expect(fileExists($fileName)) - ->toBeTrue() - ->and( - value: Str::contains( - haystack: fileGet(relativeFileName: $fileName), - needles: ['{{ class }}', '{{ namespace }}'] - ) - ) - ->toBeFalse(); - }) - ->group(groups: 'commands'); - -it(description: 'can force generate exists DTO') - ->tap(function () { - $fileName = '/Post/DataTransferObjects/PostData.php'; - - expect(value: fileExists(relativeFileName: $fileName))->toBeFalse(); - - Artisan::call(command: 'diamond:install'); - Artisan::call(command: 'domain:make:data-transfer-object PostData Post'); - Artisan::call(command: 'domain:make:data-transfer-object PostData Post --force'); - - expect(value: fileExists(relativeFileName: $fileName))->toBeTrue() - ->and( - value: Str::contains( - haystack: fileGet(relativeFileName: $fileName), - needles: ['{{ class }}', '{{ namespace }}'] - ) - )->toBeFalse(); - }) - ->group(groups: 'commands'); - -it(description: 'cannot generate the DTO, if the DTO already exists') - ->tap(function () { - $fileName = '/Post/DataTransferObjects/PostData.php'; - - expect(value: fileExists(relativeFileName: $fileName))->toBeFalse(); - - Artisan::call(command: 'diamond:install'); - Artisan::call(command: 'domain:make:data-transfer-object PostData Post'); - - expect(value: fileExists(relativeFileName: $fileName))->toBeTrue(); - - Artisan::call(command: 'domain:make:data-transfer-object PostData Post'); - - expect(value: fileExists(relativeFileName: $fileName))->toBeFalse(); - }) - ->group(groups: 'commands') - ->throws(exception: FileAlreadyExistException::class); diff --git a/tests/Feature/Commands/ActionMakeCommandTest.php b/tests/Feature/Commands/Domain/ActionMakeCommandTest.php similarity index 100% rename from tests/Feature/Commands/ActionMakeCommandTest.php rename to tests/Feature/Commands/Domain/ActionMakeCommandTest.php diff --git a/tests/Feature/Commands/BuilderMakeCommandTest.php b/tests/Feature/Commands/Domain/BuilderMakeCommandTest.php similarity index 100% rename from tests/Feature/Commands/BuilderMakeCommandTest.php rename to tests/Feature/Commands/Domain/BuilderMakeCommandTest.php diff --git a/tests/Feature/Commands/EnumMakeCommandTest.php b/tests/Feature/Commands/Domain/EnumMakeCommandTest.php similarity index 100% rename from tests/Feature/Commands/EnumMakeCommandTest.php rename to tests/Feature/Commands/Domain/EnumMakeCommandTest.php diff --git a/tests/Feature/Commands/ModelMakeCommandTest.php b/tests/Feature/Commands/Domain/ModelMakeCommandTest.php similarity index 100% rename from tests/Feature/Commands/ModelMakeCommandTest.php rename to tests/Feature/Commands/Domain/ModelMakeCommandTest.php diff --git a/tests/Feature/Commands/ValueObjectMakeCommandTest.php b/tests/Feature/Commands/Domain/ValueObjectMakeCommandTest.php similarity index 100% rename from tests/Feature/Commands/ValueObjectMakeCommandTest.php rename to tests/Feature/Commands/Domain/ValueObjectMakeCommandTest.php diff --git a/tests/Feature/Commands/EventMakeCommandTest.php b/tests/Feature/Commands/Infrastructure/EventMakeCommandTest.php similarity index 100% rename from tests/Feature/Commands/EventMakeCommandTest.php rename to tests/Feature/Commands/Infrastructure/EventMakeCommandTest.php diff --git a/tests/Feature/Commands/FactoryMakeCommandTest.php b/tests/Feature/Commands/Infrastructure/FactoryMakeCommandTest.php similarity index 100% rename from tests/Feature/Commands/FactoryMakeCommandTest.php rename to tests/Feature/Commands/Infrastructure/FactoryMakeCommandTest.php diff --git a/tests/Feature/Commands/ListenerMakeCommandTest.php b/tests/Feature/Commands/Infrastructure/ListenerMakeCommandTest.php similarity index 100% rename from tests/Feature/Commands/ListenerMakeCommandTest.php rename to tests/Feature/Commands/Infrastructure/ListenerMakeCommandTest.php diff --git a/tests/Feature/Commands/MailMakeCommandTest.php b/tests/Feature/Commands/Infrastructure/MailMakeCommandTest.php similarity index 100% rename from tests/Feature/Commands/MailMakeCommandTest.php rename to tests/Feature/Commands/Infrastructure/MailMakeCommandTest.php diff --git a/tests/Feature/Commands/ObserverMakeCommandTest.php b/tests/Feature/Commands/Infrastructure/ObserverMakeCommandTest.php similarity index 100% rename from tests/Feature/Commands/ObserverMakeCommandTest.php rename to tests/Feature/Commands/Infrastructure/ObserverMakeCommandTest.php diff --git a/tests/Feature/Commands/ProviderMakeCommandTest.php b/tests/Feature/Commands/Infrastructure/ProviderMakeCommandTest.php similarity index 100% rename from tests/Feature/Commands/ProviderMakeCommandTest.php rename to tests/Feature/Commands/Infrastructure/ProviderMakeCommandTest.php diff --git a/tests/Feature/Commands/SeederMakeCommandTest.php b/tests/Feature/Commands/Infrastructure/SeederMakeCommandTest.php similarity index 100% rename from tests/Feature/Commands/SeederMakeCommandTest.php rename to tests/Feature/Commands/Infrastructure/SeederMakeCommandTest.php diff --git a/tests/Pest.php b/tests/Pest.php index e673dd2..a9ffb06 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -23,6 +23,7 @@ $fileSystem->deleteDirectory(basePath()); $fileSystem->cleanDirectory(base_path(path: applicationPath() . '/Http/Requests')); $fileSystem->cleanDirectory(base_path(path: applicationPath() . '/Http/Resources')); + $fileSystem->cleanDirectory(base_path(path: applicationPath() . '/DataTransferObjects')); $fileSystem->cleanDirectory(base_path(path: 'database/migrations')); }) ->in(__DIR__ . '/Feature'); From a8cec7cbcbc0c107ce393f4e4a4d4a985e6e7002 Mon Sep 17 00:00:00 2001 From: Stiven Katuuk Date: Sat, 4 Feb 2023 18:04:18 +0800 Subject: [PATCH 3/3] refactor: using pest function to define app path --- .../Application/DataTransferObjectMakeCommandTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/Feature/Commands/Application/DataTransferObjectMakeCommandTest.php b/tests/Feature/Commands/Application/DataTransferObjectMakeCommandTest.php index aa30307..5f27d8b 100644 --- a/tests/Feature/Commands/Application/DataTransferObjectMakeCommandTest.php +++ b/tests/Feature/Commands/Application/DataTransferObjectMakeCommandTest.php @@ -9,7 +9,7 @@ it(description: 'can generate new DTO') ->tap(function () { - $filePath = app_path(path: 'DataTransferObjects/Post/PostData.php'); + $filePath = base_path(path: applicationPath() . '/DataTransferObjects/Post/PostData.php'); expect(value: File::exists(path: $filePath))->toBeFalse(); @@ -28,7 +28,7 @@ it(description: 'can generate new DTO with separator') ->tap(function () { - $filePath = app_path(path: 'DataTransferObjects/Post/Foo/BarData.php'); + $filePath = base_path(path: applicationPath() . '/DataTransferObjects/Post/Foo/BarData.php'); expect(value: File::exists(path: $filePath))->toBeFalse(); @@ -49,7 +49,7 @@ it(description: 'can force generate exists DTO') ->tap(function () { - $filePath = app_path(path: 'DataTransferObjects/Post/PostData.php'); + $filePath = base_path(path: applicationPath() . '/DataTransferObjects/Post/PostData.php'); expect(value: File::exists(path: $filePath))->toBeFalse(); @@ -69,7 +69,7 @@ it(description: 'cannot generate the DTO, if the DTO already exists') ->tap(function () { - $filePath = app_path(path: 'DataTransferObjects/Post/PostData.php'); + $filePath = base_path(path: applicationPath() . '/DataTransferObjects/Post/PostData.php'); expect(value: File::exists(path: $filePath))->toBeFalse();