Skip to content

Commit

Permalink
fix(command): DataTransferObject at the wrong places
Browse files Browse the repository at this point in the history
  • Loading branch information
Stiven Katuuk committed Feb 4, 2023
1 parent 2bb7a1b commit 1a28f0c
Show file tree
Hide file tree
Showing 18 changed files with 90 additions and 91 deletions.
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 = 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);
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 1a28f0c

Please sign in to comment.