Skip to content

Commit

Permalink
Command aliases.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaspertey committed Mar 27, 2024
1 parent 2775e5e commit 02f88b5
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 5 deletions.
14 changes: 9 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All notable changes to `laravel-ddd` will be documented in this file.
## [Unversioned]
### Added
- `ddd:list` to show a summary of current domains in the domain folder.
- For all generator commands, if a domain isn't specified, prompt for it with auto-completion suggestions based on the contents of the root domain folder.
- Command aliases for some generators:
- Data Transfer Object: `ddd:dto`, `ddd:data`, `ddd:data-transfer-object`, `ddd:datatransferobject`
- Value Object: `ddd:value`, `ddd:valueobject`, `ddd:value-object`
- View Model: `ddd:view-model`, `ddd:viewmodel`
- Additional generators that extend Laravel's generators and funnel the generated objects into the domain layer:
- `ddd:cast {domain}:{name}`
- `ddd:channel {domain}:{name}`
Expand All @@ -22,14 +27,13 @@ All notable changes to `laravel-ddd` will be documented in this file.
- `ddd:resource {domain}:{name}`
- `ddd:rule {domain}:{name}`
- `ddd:scope {domain}:{name}`
- For all `ddd:*` generator commands, if a domain wasn't specified, prompt for the domain with auto-completion (based on current domains in the domain folder).

### Changed
- (BREAKING) `ddd:*` commands no longer receive a dedicated domain argument. Example: `ddd:action Invoicing CreateInvoice` can be one of:
- `ddd:action CreateInvoice --domain=Invoicing` (this takes precedence).
- (BREAKING) Generator commands no longer receive a domain argument. Instead of `ddd:action Invoicing CreateInvoice`, one of the following would be used:
- Using the --domain option: `ddd:action CreateInvoice --domain=Invoicing` (this takes precedence).
- Shorthand syntax: `ddd:action Invoicing:CreateInvoice`.
- Or simply `ddd:action CreateInvoice` to be prompted for the domain.
- Improve the reliability of generating base view models when `ddd.base_view_model` is something other than the default `Domain\Shared\ViewModels\ViewModel`.
- Or simply `ddd:action CreateInvoice` to be prompted for the domain afterwards.
- Improved the reliability of generating base view models when `ddd.base_view_model` is something other than the default `Domain\Shared\ViewModels\ViewModel`.

### Chore
- Dropped Laravel 9 support.
Expand Down
1 change: 1 addition & 0 deletions src/Commands/DomainDtoMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ protected function configure()
$this->setAliases([
'ddd:data-transfer-object',
'ddd:datatransferobject',
'ddd:data',
]);

parent::configure();
Expand Down
9 changes: 9 additions & 0 deletions src/Commands/DomainViewModelMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ class DomainViewModelMakeCommand extends DomainGeneratorCommand

protected $type = 'View Model';

protected function configure()
{
$this->setAliases([
'ddd:viewmodel',
]);

parent::configure();
}

protected function getStub()
{
return $this->resolveStubPath('view-model.php.stub');
Expand Down
12 changes: 12 additions & 0 deletions tests/Generator/MakeDataTransferObjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@
expect(file_get_contents($expectedPath))->toContain("namespace {$expectedNamespace};");
})->with('domainPaths');

it('recognizes command aliases', function ($commandName) {
$this->artisan($commandName, [
'name' => 'InvoicePayload',
'--domain' => 'Invoicing',
])->assertExitCode(0);
})->with([
'ddd:dto',
'ddd:data-transfer-object',
'ddd:datatransferobject',
'ddd:data',
]);

it('normalizes generated data transfer object to pascal case', function ($given, $normalized) {
$domain = Str::studly(fake()->word());

Expand Down
11 changes: 11 additions & 0 deletions tests/Generator/MakeValueObjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@
expect(file_get_contents($expectedPath))->toContain("namespace {$expectedNamespace};");
})->with('domainPaths');

it('recognizes command aliases', function ($commandName) {
$this->artisan($commandName, [
'name' => 'InvoiceTotalValue',
'--domain' => 'Invoicing',
])->assertExitCode(0);
})->with([
'ddd:value-object',
'ddd:valueobject',
'ddd:value',
]);

it('normalizes generated value object to pascal case', function ($given, $normalized) {
$domain = Str::studly(fake()->word());

Expand Down
10 changes: 10 additions & 0 deletions tests/Generator/MakeViewModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@
);
})->with('domainPaths');

it('recognizes command aliases', function ($commandName) {
$this->artisan($commandName, [
'name' => 'ShowInvoiceViewModel',
'--domain' => 'Invoicing',
])->assertExitCode(0);
})->with([
'ddd:view-model',
'ddd:viewmodel',
]);

it('normalizes generated view model to pascal case', function ($given, $normalized) {
$domain = Str::studly(fake()->word());

Expand Down

0 comments on commit 02f88b5

Please sign in to comment.