Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(command): change structure domain layer #97

Merged
merged 5 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/Commands/Domain/BuilderMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public function getNamespace(): string
{
return Source::resolveNamespace(
data: new NamespaceData(
structures: Source::resolveDomainPath(),
domainArgument: 'Shared\\' . $this->resolveDomainArgument(),
domainArgument: $this->resolveDomainArgument(),
structures: Source::resolveDomainPath() . '\\Shared',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the structure supposed not started with domain i guess coz it "src/Shared"

nameArgument: $this->resolveNameArgument(),
endsWith: 'Models\\Builders',
)
Expand Down Expand Up @@ -67,8 +67,8 @@ public function resolveModelNamespace(): ?string
if ($this->resolveModelOption()) {
$namespace = Source::resolveNamespace(
data: new NamespaceData(
structures: Source::resolveDomainPath(),
domainArgument: 'Shared\\' . $this->resolveDomainArgument(),
domainArgument: $this->resolveDomainArgument(),
structures: Source::resolveDomainPath() . '\\Shared',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the structure supposed not started with domain i guess coz it "src/Shared"

nameArgument: $this->resolveModelOption(),
endsWith: 'Models\\' . $this->resolveModelOption(),
)
Expand Down
8 changes: 1 addition & 7 deletions src/Commands/Domain/EnumMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,14 @@ public function afterCreate(): void
public function beforeCreate(): void
{
$this->info(string: 'Generating enum file to your project');

if (version_compare(version1: PHP_VERSION, version2: '8.1.0', operator: '<=')) {
throw new \RuntimeException(
message: 'The required PHP version is 8.1 while the version you have is ' . PHP_VERSION
);
}
}

public function getNamespace(): string
{
return Source::resolveNamespace(
data: new NamespaceData(
structures: Source::resolveDomainPath(),
domainArgument: $this->resolveDomainArgument(),
structures: Source::resolveDomainPath(),
nameArgument: $this->resolveNameArgument(),
endsWith: 'Enums',
)
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Domain/ExceptionMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public function getNamespace(): string
{
return Source::resolveNamespace(
data: new NamespaceData(
structures: Source::resolveDomainPath(),
domainArgument: $this->resolveDomainArgument(),
structures: Source::resolveDomainPath(),
nameArgument: $this->resolveNameArgument(),
endsWith: 'Exceptions',
)
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Domain/ValueObjectMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public function getNamespace(): string
{
return Source::resolveNamespace(
data: new NamespaceData(
structures: Source::resolveDomainPath(),
domainArgument: $this->resolveDomainArgument(),
structures: Source::resolveDomainPath(),
nameArgument: $this->resolveNameArgument(),
endsWith: 'ValueObjects',
)
Expand Down
69 changes: 35 additions & 34 deletions tests/Feature/Commands/Domain/BuilderMakeCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@

it(description: 'can generate new Builder class')
->tap(function () {
$fileName = '/Shared/User/Models/Builders/UserBuilder.php';
$fileName = '/Shared/Models/Builders/UserBuilder.php';

expect(value: fileExists(relativeFileName: $fileName))->toBeFalse();
expect(value: fileExists(relativeFileName: $fileName, domain: 'User'))->toBeFalse();

Artisan::call(command: 'diamond:install');
Artisan::call(command: 'domain:install User');
Artisan::call(command: 'domain:make:builder UserBuilder User');

expect(value: fileExists(relativeFileName: $fileName))->toBeTrue()
expect(value: fileExists(relativeFileName: $fileName, domain: 'User'))->toBeTrue()
->and(
value: Str::contains(
haystack: fileGet(relativeFileName: $fileName),
haystack: fileGet(relativeFileName: $fileName, domain: 'User'),
needles: ['{{ class }}', '{{ namespace }}']
)
)->toBeFalse();
Expand All @@ -27,17 +27,17 @@

it(description: 'can generate new Builder class with Model option')
->tap(function () {
$fileName = '/Shared/Post/Models/Builders/PostBuilder.php';
$fileName = '/Shared/Models/Builders/PostBuilder.php';

expect(value: fileExists(relativeFileName: $fileName))->toBeFalse();
expect(value: fileExists(relativeFileName: $fileName, domain: 'Post'))->toBeFalse();

Artisan::call(command: 'diamond:install');
Artisan::call(command: 'domain:install Post');
Artisan::call(command: 'domain:make:builder PostBuilder Post --model=Post');

expect(value: fileExists(relativeFileName: $fileName))->toBeTrue()
expect(value: fileExists(relativeFileName: $fileName, domain: 'Post'))->toBeTrue()
->and(
value: Str::contains(
haystack: fileGet(relativeFileName: $fileName),
haystack: fileGet(relativeFileName: $fileName, domain: 'Post'),
needles: ['{{ class }}', '{{ namespace }}', '{{ model }}', '{{ modelNamespace }}']
)
)->toBeFalse();
Expand All @@ -46,17 +46,17 @@

it(description: 'can generate new Model class with separator')
->tap(function () {
$fileName = '/Shared/User/Models/Builders/Foo/barBuilder.php';
$fileName = '/Shared/Models/Builders/Foo/barBuilder.php';

expect(value: fileExists(relativeFileName: $fileName))->toBeFalse();
expect(value: fileExists(relativeFileName: $fileName, domain: 'User'))->toBeFalse();

Artisan::call(command: 'diamond:install');
Artisan::call(command: 'domain:install User');
Artisan::call(command: 'domain:make:builder Foo/barBuilder User');

expect(value: fileExists(relativeFileName: $fileName))->toBeTrue()
expect(value: fileExists(relativeFileName: $fileName, domain: 'User'))->toBeTrue()
->and(
value: Str::contains(
haystack: fileGet(relativeFileName: $fileName),
haystack: fileGet(relativeFileName: $fileName, domain: 'User'),
needles: ['{{ class }}', '{{ namespace }}']
)
)->toBeFalse();
Expand All @@ -65,18 +65,18 @@

it(description: 'can force generate exists Builder class')
->tap(function () {
$fileName = '/Shared/User/Models/Builders/UserBuilder.php';
$fileName = '/Shared/Models/Builders/UserBuilder.php';

expect(value: fileExists(relativeFileName: $fileName))->toBeFalse();
expect(value: fileExists(relativeFileName: $fileName, domain: 'User'))->toBeFalse();

Artisan::call(command: 'diamond:install');
Artisan::call(command: 'domain:install User');
Artisan::call(command: 'domain:make:builder UserBuilder User');
Artisan::call(command: 'domain:make:builder UserBuilder User --force');

expect(value: fileExists(relativeFileName: $fileName))->toBeTrue()
expect(value: fileExists(relativeFileName: $fileName, domain: 'User'))->toBeTrue()
->and(
value: Str::contains(
haystack: fileGet(relativeFileName: $fileName),
haystack: fileGet(relativeFileName: $fileName, domain: 'User'),
needles: ['{{ class }}', '{{ namespace }}']
)
)->toBeFalse();
Expand All @@ -85,18 +85,18 @@

it(description: 'can force generate exists Builder class with Model option')
->tap(function () {
$fileName = '/Shared/Post/Models/Builders/PostBuilder.php';
$fileName = '/Shared/Models/Builders/PostBuilder.php';

expect(value: fileExists(relativeFileName: $fileName))->toBeFalse();
expect(value: fileExists(relativeFileName: $fileName, domain: 'Post'))->toBeFalse();

Artisan::call(command: 'diamond:install');
Artisan::call(command: 'domain:install Post');
Artisan::call(command: 'domain:make:builder PostBuilder Post --model=Post');
Artisan::call(command: 'domain:make:builder PostBuilder Post --model=Post --force');

expect(value: fileExists(relativeFileName: $fileName))->toBeTrue()
expect(value: fileExists(relativeFileName: $fileName, domain: 'Post'))->toBeTrue()
->and(
value: Str::contains(
haystack: fileGet(relativeFileName: $fileName),
haystack: fileGet(relativeFileName: $fileName, domain: 'Post'),
needles: ['{{ class }}', '{{ namespace }}', '{{ model }}', '{{ modelNamespace }}']
)
)->toBeFalse();
Expand All @@ -105,34 +105,35 @@

it(description: 'cannot generate the Builder, if the Builder already exists')
->tap(function () {
$fileName = '/Shared/User/Models/Builders/UserBuilder.php';
$fileName = '/Shared/Models/Builders/UserBuilder.php';

expect(value: fileExists(relativeFileName: $fileName))->toBeFalse();
expect(value: fileExists(relativeFileName: $fileName, domain: 'User'))->toBeFalse();

Artisan::call(command: 'domain:install User');
Artisan::call(command: 'domain:make:builder UserBuilder User');

expect(value: fileExists(relativeFileName: $fileName))->toBeTrue();
expect(value: fileExists(relativeFileName: $fileName, domain: 'User'))->toBeTrue();

Artisan::call(command: 'domain:make:builder UserBuilder User');

expect(value: fileExists(relativeFileName: $fileName))->toBeFalse();
expect(value: fileExists(relativeFileName: $fileName, domain: 'User'))->toBeFalse();
})
->group(groups: 'commands')
->throws(exception: FileAlreadyExistException::class);

it(description: 'cannot generate the Builder with Model opPost, if the Builder already exists')
it(description: 'cannot generate the Builder with Model Post, if the Builder already exists')
->tap(function () {
$fileName = '/Shared/Post/Models/Builders/PostBuilder.php';
$fileName = '/Shared/Models/Builders/PostBuilder.php';

expect(value: fileExists(relativeFileName: $fileName))->toBeFalse();
expect(value: fileExists(relativeFileName: $fileName, domain: 'Post'))->toBeFalse();

Artisan::call(command: 'domain:make:builder PostBuilder Post --model=Post');

expect(value: fileExists(relativeFileName: $fileName))->toBeTrue();
expect(value: fileExists(relativeFileName: $fileName, domain: 'Post'))->toBeTrue();

Artisan::call(command: 'domain:make:builder PostBuilder Post --model=Post');

expect(value: fileExists(relativeFileName: $fileName))->toBeFalse();
expect(value: fileExists(relativeFileName: $fileName, domain: 'Post'))->toBeFalse();
})
->group(groups: 'commands')
->throws(exception: FileAlreadyExistException::class);
44 changes: 20 additions & 24 deletions tests/Feature/Commands/Domain/EnumMakeCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,81 +7,77 @@
use KoalaFacade\DiamondConsole\Exceptions\FileAlreadyExistException;

it(description: 'can generate new Enum')
->skip(version_compare(PHP_VERSION, '8.1.0', '<'), 'code contains php 8.1 feature cause this test run in ' . PHP_VERSION)
->tap(function () {
$fileName = '/Post/Enums/PostStatus.php';
$fileName = '/Enums/PostStatus.php';

expect(value: fileExists(relativeFileName: $fileName))->toBeFalse();
expect(value: fileExists(relativeFileName: $fileName, domain: 'Post'))->toBeFalse();

Artisan::call(command: 'diamond:install');
Artisan::call(command: 'domain:install Post');
Artisan::call(command: 'domain:make:enum PostStatus Post');

expect(value: fileExists(relativeFileName: $fileName))->toBeTrue()
expect(value: fileExists(relativeFileName: $fileName, domain: 'Post'))->toBeTrue()
->and(
value: Str::contains(
haystack: fileGet(relativeFileName: $fileName),
haystack: fileGet(relativeFileName: $fileName, domain: 'Post'),
needles: ['{{ class }}', '{{ namespace }}']
)
)->toBeFalse();
})
->group(groups: 'commands');

it(description: 'can generate new Enum with separator')
->skip(version_compare(PHP_VERSION, '8.1.0', '<'), 'code contains php 8.1 feature cause this test run in ' . PHP_VERSION)
->tap(function () {
$fileName = '/Post/Enums/Foo/Bar.php';
$fileName = '/Enums/Foo/Bar.php';

expect(value: fileExists(relativeFileName: $fileName))->toBeFalse();
expect(value: fileExists(relativeFileName: $fileName, domain: 'Post'))->toBeFalse();

Artisan::call(command: 'diamond:install');
Artisan::call(command: 'domain:install Post');
Artisan::call(command: 'domain:make:enum Foo/Bar Post');

expect(value: fileExists(relativeFileName: $fileName))->toBeTrue()
expect(value: fileExists(relativeFileName: $fileName, domain: 'Post'))->toBeTrue()
->and(
value: Str::contains(
haystack: fileGet(relativeFileName: $fileName),
haystack: fileGet(relativeFileName: $fileName, domain: 'Post'),
needles: ['{{ class }}', '{{ namespace }}']
)
)->toBeFalse();
})
->group(groups: 'commands');

it(description: 'can force generate exists Enum')
->skip(version_compare(PHP_VERSION, '8.1.0', '<'), 'code contains php 8.1 feature cause this test run in ' . PHP_VERSION)
->tap(function () {
$fileName = '/Post/Enums/PostStatus.php';
$fileName = '/Enums/PostStatus.php';

expect(value: fileExists(relativeFileName: $fileName))->toBeFalse();
expect(value: fileExists(relativeFileName: $fileName, domain: 'Post'))->toBeFalse();

Artisan::call(command: 'diamond:install');
Artisan::call(command: 'domain:install Post');
Artisan::call(command: 'domain:make:enum PostStatus Post');
Artisan::call(command: 'domain:make:enum PostStatus Post --force');

expect(value: fileExists(relativeFileName: $fileName))->toBeTrue()
expect(value: fileExists(relativeFileName: $fileName, domain: 'Post'))->toBeTrue()
->and(
value: Str::contains(
haystack: fileGet(relativeFileName: $fileName),
haystack: fileGet(relativeFileName: $fileName, domain: 'Post'),
needles: ['{{ class }}', '{{ namespace }}']
)
)->toBeFalse();
})
->group(groups: 'commands');

it(description: 'cannot generate the Enum, if the Enum already exists')
->skip(version_compare(PHP_VERSION, '8.1.0', '<'), 'code contains php 8.1 feature cause this test run in ' . PHP_VERSION)
->tap(function () {
$fileName = '/Post/Enums/PostStatus.php';
$fileName = '/Enums/PostStatus.php';

expect(value: fileExists(relativeFileName: $fileName))->toBeFalse();
expect(value: fileExists(relativeFileName: $fileName, domain: 'Post'))->toBeFalse();

Artisan::call(command: 'diamond:install');
Artisan::call(command: 'domain:install Post');
Artisan::call(command: 'domain:make:enum PostStatus Post');

expect(value: fileExists(relativeFileName: $fileName))->toBeTrue();
expect(value: fileExists(relativeFileName: $fileName, domain: 'Post'))->toBeTrue();

Artisan::call(command: 'domain:make:enum PostStatus Post');

expect(value: fileExists(relativeFileName: $fileName))->toBeFalse();
expect(value: fileExists(relativeFileName: $fileName, domain: 'Post'))->toBeFalse();
})
->group(groups: 'commands')
->throws(exception: FileAlreadyExistException::class);
Loading