From 8c3554e623a2c1795a058c99b9005268b43f9c60 Mon Sep 17 00:00:00 2001 From: Jasper Tey Date: Mon, 11 Mar 2024 09:59:40 -0400 Subject: [PATCH 01/16] Adding Laravel 11 support to dependencies and test matrix. --- .github/workflows/run-tests.yml | 4 ++-- composer.json | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 1c40ef2..afa19e6 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -13,8 +13,8 @@ jobs: fail-fast: true matrix: os: [ubuntu-latest, windows-latest] - php: [8.2, 8.1] - laravel: [9.*, 10.*] + php: [8.1, 8.2, 8.3] + laravel: [9, 10, 11] stability: [prefer-lowest, prefer-stable] include: - laravel: 9.* diff --git a/composer.json b/composer.json index 080d893..3f1af1a 100644 --- a/composer.json +++ b/composer.json @@ -18,15 +18,15 @@ } ], "require": { - "php": "^8.1|^8.2", + "php": "^8.1|^8.2|^8.3", "spatie/laravel-package-tools": "^1.13.0", - "illuminate/contracts": "^9.0|^10.0" + "illuminate/contracts": "^9.0|^10.0|^11.0" }, "require-dev": { "laravel/pint": "^1.0", "nunomaduro/collision": "^6.0|^7.0", "larastan/larastan": "^2.0.1", - "orchestra/testbench": "^7|^8", + "orchestra/testbench": "^7|^8|^9.0", "pestphp/pest": "^1.22|^2.0", "pestphp/pest-plugin-laravel": "^1.1|^2.0", "phpstan/extension-installer": "^1.1", From 0265d0607f3ec737b4d7d05937953da0c70bc265 Mon Sep 17 00:00:00 2001 From: Jasper Tey Date: Mon, 11 Mar 2024 10:00:33 -0400 Subject: [PATCH 02/16] Change notes. --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 413d142..0eb4adf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to `laravel-ddd` will be documented in this file. +## [Unversioned] +### Chore +- Add Laravel 11 support. + ## [0.8.1] - 2023-12-05 ### Chore - Update dependencies. From 85797f0a7416484794808fe0621754c72349a38b Mon Sep 17 00:00:00 2001 From: Jasper Tey Date: Mon, 11 Mar 2024 10:04:03 -0400 Subject: [PATCH 03/16] Update matrix. --- .github/workflows/run-tests.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index afa19e6..6de57e4 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -23,6 +23,9 @@ jobs: - laravel: 10.* testbench: 8.* carbon: ^2.63 + - laravel: 11.* + testbench: 9.* + carbon: ^2.63 name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }} From 7380b53dc63004a6cf80840755471f791bcfb0b7 Mon Sep 17 00:00:00 2001 From: Jasper Tey Date: Mon, 11 Mar 2024 10:19:04 -0400 Subject: [PATCH 04/16] Attempt moving `runs-on` config --- .github/workflows/run-tests.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 6de57e4..a8c71d8 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -8,7 +8,6 @@ on: jobs: test: - runs-on: ${{ matrix.os }} strategy: fail-fast: true matrix: @@ -27,6 +26,8 @@ jobs: testbench: 9.* carbon: ^2.63 + runs-on: ${{ matrix.os }} + name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }} steps: From baf1936930e9d172ce3da922849bfe950aa210a0 Mon Sep 17 00:00:00 2001 From: Jasper Tey Date: Mon, 11 Mar 2024 10:29:15 -0400 Subject: [PATCH 05/16] Attempted yaml fix. --- .github/workflows/run-tests.yml | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index a8c71d8..65ca8f2 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -8,25 +8,24 @@ on: jobs: test: + runs-on: ${{ matrix.os }} strategy: fail-fast: true matrix: os: [ubuntu-latest, windows-latest] - php: [8.1, 8.2, 8.3] - laravel: [9, 10, 11] + php: [8.3, 8.2, 8.1] + laravel: [11.*, 10.*, 9.*] stability: [prefer-lowest, prefer-stable] include: - - laravel: 9.* - testbench: 7.* - carbon: ^2.63 - - laravel: 10.* - testbench: 8.* - carbon: ^2.63 - - laravel: 11.* - testbench: 9.* - carbon: ^2.63 - - runs-on: ${{ matrix.os }} + - laravel: 11.* + testbench: 9.* + - laravel: 10.* + testbench: 8.* + - laravel: 9.* + testbench: 7.* + exclude: + - laravel: 11.* + php: 8.1 name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }} From 8c5171c5e8d39a19b6ca74a9a19082fee758ecfb Mon Sep 17 00:00:00 2001 From: Jasper Tey Date: Mon, 11 Mar 2024 10:32:31 -0400 Subject: [PATCH 06/16] Add missing carbon contraints. --- .github/workflows/run-tests.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 65ca8f2..a093c54 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -19,10 +19,13 @@ jobs: include: - laravel: 11.* testbench: 9.* + carbon: ^2.63 - laravel: 10.* testbench: 8.* + carbon: ^2.63 - laravel: 9.* testbench: 7.* + carbon: ^2.63 exclude: - laravel: 11.* php: 8.1 From 0346d409e1ed16934b72070957c02a6ca382226b Mon Sep 17 00:00:00 2001 From: Jasper Tey Date: Mon, 11 Mar 2024 10:35:46 -0400 Subject: [PATCH 07/16] Ensure collision supports L11 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 3f1af1a..2f83313 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ }, "require-dev": { "laravel/pint": "^1.0", - "nunomaduro/collision": "^6.0|^7.0", + "nunomaduro/collision": "^6.0|^7.0|^8.1", "larastan/larastan": "^2.0.1", "orchestra/testbench": "^7|^8|^9.0", "pestphp/pest": "^1.22|^2.0", From 517a64d51738e143220d69456d309b1fe716cb73 Mon Sep 17 00:00:00 2001 From: Jasper Tey Date: Mon, 11 Mar 2024 10:45:15 -0400 Subject: [PATCH 08/16] Refactor carbon dependency --- .github/workflows/run-tests.yml | 3 --- composer.json | 1 + 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index a093c54..65ca8f2 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -19,13 +19,10 @@ jobs: include: - laravel: 11.* testbench: 9.* - carbon: ^2.63 - laravel: 10.* testbench: 8.* - carbon: ^2.63 - laravel: 9.* testbench: 7.* - carbon: ^2.63 exclude: - laravel: 11.* php: 8.1 diff --git a/composer.json b/composer.json index 2f83313..da5e792 100644 --- a/composer.json +++ b/composer.json @@ -25,6 +25,7 @@ "require-dev": { "laravel/pint": "^1.0", "nunomaduro/collision": "^6.0|^7.0|^8.1", + "nesbot/carbon": "^2.0|^3.0", "larastan/larastan": "^2.0.1", "orchestra/testbench": "^7|^8|^9.0", "pestphp/pest": "^1.22|^2.0", From 68290317634c0a1d77a09efb6b703bfd9d352296 Mon Sep 17 00:00:00 2001 From: Jasper Tey Date: Mon, 11 Mar 2024 10:47:08 -0400 Subject: [PATCH 09/16] Trying again. --- .github/workflows/run-tests.yml | 3 +++ composer.json | 1 - 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 65ca8f2..f14c12e 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -19,10 +19,13 @@ jobs: include: - laravel: 11.* testbench: 9.* + carbon: ^3.0 - laravel: 10.* testbench: 8.* + carbon: ^2.63 - laravel: 9.* testbench: 7.* + carbon: ^2.63 exclude: - laravel: 11.* php: 8.1 diff --git a/composer.json b/composer.json index da5e792..2f83313 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,6 @@ "require-dev": { "laravel/pint": "^1.0", "nunomaduro/collision": "^6.0|^7.0|^8.1", - "nesbot/carbon": "^2.0|^3.0", "larastan/larastan": "^2.0.1", "orchestra/testbench": "^7|^8|^9.0", "pestphp/pest": "^1.22|^2.0", From 552a9f3914cbfd87484db6824be47377cf067aba Mon Sep 17 00:00:00 2001 From: Jasper Tey Date: Mon, 11 Mar 2024 11:36:20 -0400 Subject: [PATCH 10/16] Attempt toContainFilepath expectation to normalize OS-specific directory separator. --- .gitignore | 1 + tests/Expectations.php | 6 ++++++ tests/Generator/MakeActionTest.php | 6 +++--- tests/Generator/MakeBaseModelTest.php | 2 +- tests/Generator/MakeBaseViewModelTest.php | 2 +- tests/Generator/MakeDataTransferObjectTest.php | 2 +- tests/Generator/MakeModelTest.php | 2 +- tests/Generator/MakeValueObjectTest.php | 2 +- tests/Generator/MakeViewModelTest.php | 4 ++-- 9 files changed, 17 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 83c9b9f..8054c8d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .idea .phpunit.result.cache +.phpunit.cache build composer.lock coverage diff --git a/tests/Expectations.php b/tests/Expectations.php index 430dba0..9e4aae7 100644 --- a/tests/Expectations.php +++ b/tests/Expectations.php @@ -7,3 +7,9 @@ return $this; }); + +expect()->extend('toContainFilepath', function ($path) { + $normalizedPath = str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $path); + + return $this->toContain($normalizedPath); +}); diff --git a/tests/Generator/MakeActionTest.php b/tests/Generator/MakeActionTest.php index e13840c..a0867f7 100644 --- a/tests/Generator/MakeActionTest.php +++ b/tests/Generator/MakeActionTest.php @@ -30,7 +30,7 @@ expect(Artisan::output())->when( Feature::IncludeFilepathInGeneratorCommandOutput->exists(), - fn ($output) => $output->toContain($relativePath), + fn ($output) => $output->toContainFilepath($relativePath), ); expect(file_exists($expectedPath))->toBeTrue(); @@ -87,7 +87,7 @@ expect(file_exists($expectedPath))->toBeTrue(); - expect(file_get_contents($expectedPath))->toContain("class {$name} extends {$baseAction}".PHP_EOL.'{'); + expect(file_get_contents($expectedPath))->toContain("class {$name} extends {$baseAction}" . PHP_EOL . '{'); })->with([ 'BaseAction' => 'BaseAction', 'Base\Action' => 'Base\Action', @@ -113,5 +113,5 @@ Artisan::call("ddd:action {$domain} {$name}"); expect(file_exists($expectedPath))->toBeTrue(); - expect(file_get_contents($expectedPath))->toContain("class {$name}".PHP_EOL.'{'); + expect(file_get_contents($expectedPath))->toContain("class {$name}" . PHP_EOL . '{'); }); diff --git a/tests/Generator/MakeBaseModelTest.php b/tests/Generator/MakeBaseModelTest.php index a1b3e96..8713df0 100644 --- a/tests/Generator/MakeBaseModelTest.php +++ b/tests/Generator/MakeBaseModelTest.php @@ -29,7 +29,7 @@ expect(Artisan::output())->when( Feature::IncludeFilepathInGeneratorCommandOutput->exists(), - fn ($output) => $output->toContain($relativePath), + fn ($output) => $output->toContainFilepath($relativePath), ); expect(file_exists($expectedPath))->toBeTrue(); diff --git a/tests/Generator/MakeBaseViewModelTest.php b/tests/Generator/MakeBaseViewModelTest.php index 37b749f..49d1df1 100644 --- a/tests/Generator/MakeBaseViewModelTest.php +++ b/tests/Generator/MakeBaseViewModelTest.php @@ -29,7 +29,7 @@ expect(Artisan::output())->when( Feature::IncludeFilepathInGeneratorCommandOutput->exists(), - fn ($output) => $output->toContain($relativePath), + fn ($output) => $output->toContainFilepath($relativePath), ); expect(file_exists($expectedPath))->toBeTrue(); diff --git a/tests/Generator/MakeDataTransferObjectTest.php b/tests/Generator/MakeDataTransferObjectTest.php index e581151..6959bc7 100644 --- a/tests/Generator/MakeDataTransferObjectTest.php +++ b/tests/Generator/MakeDataTransferObjectTest.php @@ -30,7 +30,7 @@ expect(Artisan::output())->when( Feature::IncludeFilepathInGeneratorCommandOutput->exists(), - fn ($output) => $output->toContain($relativePath), + fn ($output) => $output->toContainFilepath($relativePath), ); expect(file_exists($expectedPath))->toBeTrue(); diff --git a/tests/Generator/MakeModelTest.php b/tests/Generator/MakeModelTest.php index 5884d66..5090313 100644 --- a/tests/Generator/MakeModelTest.php +++ b/tests/Generator/MakeModelTest.php @@ -31,7 +31,7 @@ expect(Artisan::output())->when( Feature::IncludeFilepathInGeneratorCommandOutput->exists(), - fn ($output) => $output->toContain($relativePath), + fn ($output) => $output->toContainFilepath($relativePath), ); expect(file_exists($expectedModelPath))->toBeTrue(); diff --git a/tests/Generator/MakeValueObjectTest.php b/tests/Generator/MakeValueObjectTest.php index 670a4c4..8c4cbf7 100644 --- a/tests/Generator/MakeValueObjectTest.php +++ b/tests/Generator/MakeValueObjectTest.php @@ -30,7 +30,7 @@ expect(Artisan::output())->when( Feature::IncludeFilepathInGeneratorCommandOutput->exists(), - fn ($output) => $output->toContain($relativePath), + fn ($output) => $output->toContainFilepath($relativePath), ); expect(file_exists($expectedPath))->toBeTrue(); diff --git a/tests/Generator/MakeViewModelTest.php b/tests/Generator/MakeViewModelTest.php index 1fe190f..5835229 100644 --- a/tests/Generator/MakeViewModelTest.php +++ b/tests/Generator/MakeViewModelTest.php @@ -30,7 +30,7 @@ expect(Artisan::output())->when( Feature::IncludeFilepathInGeneratorCommandOutput->exists(), - fn ($output) => $output->toContain($relativePath), + fn ($output) => $output->toContainFilepath($relativePath), ); expect(file_exists($expectedPath))->toBeTrue(); @@ -77,7 +77,7 @@ expect(file_exists($expectedPath))->toBeFalse(); // This currently only tests for the default base model - $expectedBaseViewModelPath = base_path(config('ddd.paths.domains').'/Shared/ViewModels/ViewModel.php'); + $expectedBaseViewModelPath = base_path(config('ddd.paths.domains') . '/Shared/ViewModels/ViewModel.php'); if (file_exists($expectedBaseViewModelPath)) { unlink($expectedBaseViewModelPath); From 09e44c0f7808172d5913cd04e618249a86d1cc89 Mon Sep 17 00:00:00 2001 From: Jasper Tey Date: Mon, 11 Mar 2024 11:36:43 -0400 Subject: [PATCH 11/16] Formatting. --- src/Support/Domain.php | 4 ++-- src/ValueObjects/DomainNamespaces.php | 2 +- tests/Generator/MakeActionTest.php | 4 ++-- tests/Generator/MakeViewModelTest.php | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Support/Domain.php b/src/Support/Domain.php index b88219b..1b3d1a0 100644 --- a/src/Support/Domain.php +++ b/src/Support/Domain.php @@ -19,7 +19,7 @@ class Domain public readonly DomainNamespaces $namespace; - public function __construct(string $domain, string $subdomain = null) + public function __construct(string $domain, ?string $subdomain = null) { if (is_null($subdomain)) { // If a subdomain isn't explicitly specified, we @@ -62,7 +62,7 @@ protected function getDomainBasePath() return app()->basePath(config('ddd.paths.domains')); } - public function path(string $path = null): string + public function path(?string $path = null): string { if (is_null($path)) { return $this->path; diff --git a/src/ValueObjects/DomainNamespaces.php b/src/ValueObjects/DomainNamespaces.php index 2ca8d4e..b7307bb 100644 --- a/src/ValueObjects/DomainNamespaces.php +++ b/src/ValueObjects/DomainNamespaces.php @@ -15,7 +15,7 @@ public function __construct( ) { } - public static function from(string $domain, string $subdomain = null): self + public static function from(string $domain, ?string $subdomain = null): self { $domainWithSubdomain = str($domain) ->when($subdomain, fn ($domain) => $domain->append("\\{$subdomain}")) diff --git a/tests/Generator/MakeActionTest.php b/tests/Generator/MakeActionTest.php index a0867f7..c5ae16f 100644 --- a/tests/Generator/MakeActionTest.php +++ b/tests/Generator/MakeActionTest.php @@ -87,7 +87,7 @@ expect(file_exists($expectedPath))->toBeTrue(); - expect(file_get_contents($expectedPath))->toContain("class {$name} extends {$baseAction}" . PHP_EOL . '{'); + expect(file_get_contents($expectedPath))->toContain("class {$name} extends {$baseAction}".PHP_EOL.'{'); })->with([ 'BaseAction' => 'BaseAction', 'Base\Action' => 'Base\Action', @@ -113,5 +113,5 @@ Artisan::call("ddd:action {$domain} {$name}"); expect(file_exists($expectedPath))->toBeTrue(); - expect(file_get_contents($expectedPath))->toContain("class {$name}" . PHP_EOL . '{'); + expect(file_get_contents($expectedPath))->toContain("class {$name}".PHP_EOL.'{'); }); diff --git a/tests/Generator/MakeViewModelTest.php b/tests/Generator/MakeViewModelTest.php index 5835229..4105817 100644 --- a/tests/Generator/MakeViewModelTest.php +++ b/tests/Generator/MakeViewModelTest.php @@ -77,7 +77,7 @@ expect(file_exists($expectedPath))->toBeFalse(); // This currently only tests for the default base model - $expectedBaseViewModelPath = base_path(config('ddd.paths.domains') . '/Shared/ViewModels/ViewModel.php'); + $expectedBaseViewModelPath = base_path(config('ddd.paths.domains').'/Shared/ViewModels/ViewModel.php'); if (file_exists($expectedBaseViewModelPath)) { unlink($expectedBaseViewModelPath); From 75d1783efb8abeaad0e6cf7038c4155af112b91a Mon Sep 17 00:00:00 2001 From: Jasper Tey Date: Mon, 11 Mar 2024 11:53:00 -0400 Subject: [PATCH 12/16] Normalize paths at the DomainGeneratorCommand level --- src/Commands/DomainGeneratorCommand.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Commands/DomainGeneratorCommand.php b/src/Commands/DomainGeneratorCommand.php index 5d01d86..3352130 100644 --- a/src/Commands/DomainGeneratorCommand.php +++ b/src/Commands/DomainGeneratorCommand.php @@ -62,14 +62,16 @@ protected function getDomainBasePath() protected function getPath($name) { - $name = str($name) + $normalizedPath = str($name) ->replaceFirst($this->rootNamespace(), '') ->replace('\\', '/') ->ltrim('/') ->append('.php') + ->prepend($this->getDomainBasePath() . DIRECTORY_SEPARATOR) + ->replace(['/', '\\'], DIRECTORY_SEPARATOR) ->toString(); - return $this->getDomainBasePath().'/'.$name; + return $normalizedPath; } protected function resolveStubPath($path) From 6786d5cf4e2b14332e0dea7fd0def2bfc39e5f13 Mon Sep 17 00:00:00 2001 From: JasperTey Date: Mon, 11 Mar 2024 15:53:34 +0000 Subject: [PATCH 13/16] Fix styling --- src/Commands/DomainGeneratorCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Commands/DomainGeneratorCommand.php b/src/Commands/DomainGeneratorCommand.php index 3352130..02ec4e3 100644 --- a/src/Commands/DomainGeneratorCommand.php +++ b/src/Commands/DomainGeneratorCommand.php @@ -67,7 +67,7 @@ protected function getPath($name) ->replace('\\', '/') ->ltrim('/') ->append('.php') - ->prepend($this->getDomainBasePath() . DIRECTORY_SEPARATOR) + ->prepend($this->getDomainBasePath().DIRECTORY_SEPARATOR) ->replace(['/', '\\'], DIRECTORY_SEPARATOR) ->toString(); From 9fe6999646173576f6cb991eb4996bb8754fca35 Mon Sep 17 00:00:00 2001 From: Jasper Tey Date: Mon, 11 Mar 2024 12:03:39 -0400 Subject: [PATCH 14/16] Normalize getDomainBasePath() too. --- src/Commands/DomainGeneratorCommand.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Commands/DomainGeneratorCommand.php b/src/Commands/DomainGeneratorCommand.php index 02ec4e3..ab588b4 100644 --- a/src/Commands/DomainGeneratorCommand.php +++ b/src/Commands/DomainGeneratorCommand.php @@ -57,7 +57,9 @@ protected function getDomain() protected function getDomainBasePath() { - return $this->laravel->basePath(config('ddd.paths.domains', 'src/Domains')); + return str($this->laravel->basePath(config('ddd.paths.domains', 'src/Domains'))) + ->replace(['/', '\\'], DIRECTORY_SEPARATOR) + ->toString(); } protected function getPath($name) From 60b0e0d9759c013f3a87d45449a384b93106450a Mon Sep 17 00:00:00 2001 From: Jasper Tey Date: Mon, 11 Mar 2024 12:27:14 -0400 Subject: [PATCH 15/16] A few more path normalizations. --- src/Commands/DomainGeneratorCommand.php | 10 ++++------ tests/Expectations.php | 6 +++--- tests/Generator/MakeFactoryTest.php | 4 +--- tests/Generator/MakeModelTest.php | 4 +--- 4 files changed, 9 insertions(+), 15 deletions(-) diff --git a/src/Commands/DomainGeneratorCommand.php b/src/Commands/DomainGeneratorCommand.php index ab588b4..a4fcab9 100644 --- a/src/Commands/DomainGeneratorCommand.php +++ b/src/Commands/DomainGeneratorCommand.php @@ -4,6 +4,7 @@ use Illuminate\Console\GeneratorCommand; use Illuminate\Support\Str; +use Lunarstorm\LaravelDDD\Support\Path; use Symfony\Component\Console\Input\InputArgument; abstract class DomainGeneratorCommand extends GeneratorCommand @@ -57,23 +58,20 @@ protected function getDomain() protected function getDomainBasePath() { - return str($this->laravel->basePath(config('ddd.paths.domains', 'src/Domains'))) - ->replace(['/', '\\'], DIRECTORY_SEPARATOR) - ->toString(); + return Path::normalize($this->laravel->basePath(config('ddd.paths.domains', 'src/Domains'))); } protected function getPath($name) { - $normalizedPath = str($name) + $path = str($name) ->replaceFirst($this->rootNamespace(), '') ->replace('\\', '/') ->ltrim('/') ->append('.php') ->prepend($this->getDomainBasePath().DIRECTORY_SEPARATOR) - ->replace(['/', '\\'], DIRECTORY_SEPARATOR) ->toString(); - return $normalizedPath; + return Path::normalize($path); } protected function resolveStubPath($path) diff --git a/tests/Expectations.php b/tests/Expectations.php index 9e4aae7..ce57889 100644 --- a/tests/Expectations.php +++ b/tests/Expectations.php @@ -1,5 +1,7 @@ extend('toMatchRegularExpression', function ($pattern, string $message = '') { @@ -9,7 +11,5 @@ }); expect()->extend('toContainFilepath', function ($path) { - $normalizedPath = str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $path); - - return $this->toContain($normalizedPath); + return $this->toContain(Path::normalize($path)); }); diff --git a/tests/Generator/MakeFactoryTest.php b/tests/Generator/MakeFactoryTest.php index ee8f70e..1f3f82e 100644 --- a/tests/Generator/MakeFactoryTest.php +++ b/tests/Generator/MakeFactoryTest.php @@ -33,11 +33,9 @@ Artisan::call("ddd:factory {$domain->dotName} {$modelName}"); - $outputPath = str_replace('\\', '/', $domainFactory->path); - expect(Artisan::output())->when( Feature::IncludeFilepathInGeneratorCommandOutput->exists(), - fn ($output) => $output->toContain($outputPath), + fn ($output) => $output->toContainFilepath($domainFactory->path), ); expect(file_exists($expectedFactoryPath))->toBeTrue( diff --git a/tests/Generator/MakeModelTest.php b/tests/Generator/MakeModelTest.php index 5090313..de4f82a 100644 --- a/tests/Generator/MakeModelTest.php +++ b/tests/Generator/MakeModelTest.php @@ -76,11 +76,9 @@ '--factory' => true, ]); - $outputPath = str_replace('\\', '/', $domainModel->path); - expect(Artisan::output())->when( Feature::IncludeFilepathInGeneratorCommandOutput->exists(), - fn ($output) => $output->toContain($outputPath), + fn ($output) => $output->toContainFilepath($domainModel->path), ); expect(file_exists($expectedModelPath))->toBeTrue(); From 98da7da5ad5ff7973c55913cc4e049b915a66e61 Mon Sep 17 00:00:00 2001 From: Jasper Tey Date: Mon, 11 Mar 2024 12:38:11 -0400 Subject: [PATCH 16/16] MakeFactory::getPath() wasn't normalized --- src/Commands/MakeFactory.php | 3 ++- tests/Generator/MakeFactoryTest.php | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Commands/MakeFactory.php b/src/Commands/MakeFactory.php index 0fc7085..b18b702 100644 --- a/src/Commands/MakeFactory.php +++ b/src/Commands/MakeFactory.php @@ -3,6 +3,7 @@ namespace Lunarstorm\LaravelDDD\Commands; use Lunarstorm\LaravelDDD\Support\Domain; +use Lunarstorm\LaravelDDD\Support\Path; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; @@ -74,7 +75,7 @@ protected function getPath($name) ->append('.php') ->toString(); - return base_path('database/factories/'.$name); + return Path::normalize(base_path('database/factories/'.$name)); } protected function getFactoryName() diff --git a/tests/Generator/MakeFactoryTest.php b/tests/Generator/MakeFactoryTest.php index 1f3f82e..16ad901 100644 --- a/tests/Generator/MakeFactoryTest.php +++ b/tests/Generator/MakeFactoryTest.php @@ -4,6 +4,7 @@ use Illuminate\Support\Facades\Config; use Illuminate\Support\Str; use Lunarstorm\LaravelDDD\Support\Domain; +use Lunarstorm\LaravelDDD\Support\Path; use Lunarstorm\LaravelDDD\Tests\Fixtures\Enums\Feature; it('can generate domain factories', function ($domainPath, $domainRoot, $domain, $subdomain) { @@ -23,7 +24,7 @@ $domainFactory = $domain->factory($factoryName); - $expectedFactoryPath = base_path($domainFactory->path); + $expectedFactoryPath = Path::normalize(base_path($domainFactory->path)); if (file_exists($expectedFactoryPath)) { unlink($expectedFactoryPath);