Skip to content

Commit

Permalink
Merge pull request #72 from pemudakoding/main
Browse files Browse the repository at this point in the history
fix: DTO generated at the wrong place should be present in application layer
  • Loading branch information
holiq authored Feb 4, 2023
2 parents 481fbe5 + a8cec7c commit 9299ff4
Show file tree
Hide file tree
Showing 19 changed files with 91 additions and 92 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
<?php

namespace KoalaFacade\DiamondConsole\Commands\Domain;
namespace KoalaFacade\DiamondConsole\Commands\Application;

use Illuminate\Console\Command;
use KoalaFacade\DiamondConsole\Commands\Application\Concerns\InteractsWithConsoleInApplication;
use KoalaFacade\DiamondConsole\Commands\Concerns\HasArguments;
use KoalaFacade\DiamondConsole\Commands\Concerns\HasOptions;
use KoalaFacade\DiamondConsole\Commands\Concerns\InteractsWithConsole;
use KoalaFacade\DiamondConsole\Contracts\Console;
use KoalaFacade\DiamondConsole\DataTransferObjects\NamespaceData;
use KoalaFacade\DiamondConsole\DataTransferObjects\PlaceholderData;
use KoalaFacade\DiamondConsole\Support\Source;

class DataTransferObjectMakeCommand extends Command implements Console
{
use HasArguments, HasOptions, InteractsWithConsole;
use HasArguments, HasOptions, InteractsWithConsoleInApplication;

protected $signature = 'domain:make:data-transfer-object {name} {domain} {--force}';
protected $signature = 'application:make:data-transfer-object {name} {domain} {--force}';

protected $description = 'Create a new Data Transfer Object';

public function getNamespace(): string
{
return Source::resolveNamespace(
data: new NamespaceData(
structures: Source::resolveDomainPath(),
structures: Source::resolveApplicationPath() . '\\DataTransferObjects',
domainArgument: $this->resolveDomainArgument(),
nameArgument: $this->resolveNameArgument(),
endsWith: 'DataTransferObjects',
)
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php

namespace Tests\Feature\Commands;

use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
use KoalaFacade\DiamondConsole\Exceptions\FileAlreadyExistException;

it(description: 'can generate new DTO')
->tap(function () {
$filePath = base_path(path: applicationPath() . '/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 = base_path(path: applicationPath() . '/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 = base_path(path: applicationPath() . '/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 = base_path(path: applicationPath() . '/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);
85 changes: 0 additions & 85 deletions tests/Feature/Commands/DataTransferObjectMakeCommandTest.php

This file was deleted.

1 change: 1 addition & 0 deletions tests/Pest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 9299ff4

Please sign in to comment.