diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 1c40ef2..f14c12e 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -13,16 +13,22 @@ jobs: fail-fast: true matrix: os: [ubuntu-latest, windows-latest] - php: [8.2, 8.1] - laravel: [9.*, 10.*] + 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: ^3.0 + - laravel: 10.* + testbench: 8.* + carbon: ^2.63 + - laravel: 9.* + testbench: 7.* + carbon: ^2.63 + exclude: + - laravel: 11.* + php: 8.1 name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }} 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/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. diff --git a/composer.json b/composer.json index 080d893..2f83313 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", + "nunomaduro/collision": "^6.0|^7.0|^8.1", "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", diff --git a/src/Commands/DomainGeneratorCommand.php b/src/Commands/DomainGeneratorCommand.php index 5d01d86..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,19 +58,20 @@ protected function getDomain() protected function getDomainBasePath() { - return $this->laravel->basePath(config('ddd.paths.domains', 'src/Domains')); + return Path::normalize($this->laravel->basePath(config('ddd.paths.domains', 'src/Domains'))); } protected function getPath($name) { - $name = str($name) + $path = str($name) ->replaceFirst($this->rootNamespace(), '') ->replace('\\', '/') ->ltrim('/') ->append('.php') + ->prepend($this->getDomainBasePath().DIRECTORY_SEPARATOR) ->toString(); - return $this->getDomainBasePath().'/'.$name; + return Path::normalize($path); } protected function resolveStubPath($path) 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/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/Expectations.php b/tests/Expectations.php index 430dba0..ce57889 100644 --- a/tests/Expectations.php +++ b/tests/Expectations.php @@ -1,5 +1,7 @@ extend('toMatchRegularExpression', function ($pattern, string $message = '') { @@ -7,3 +9,7 @@ return $this; }); + +expect()->extend('toContainFilepath', function ($path) { + return $this->toContain(Path::normalize($path)); +}); diff --git a/tests/Generator/MakeActionTest.php b/tests/Generator/MakeActionTest.php index e13840c..c5ae16f 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(); 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/MakeFactoryTest.php b/tests/Generator/MakeFactoryTest.php index ee8f70e..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); @@ -33,11 +34,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 5884d66..de4f82a 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(); @@ -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(); 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..4105817 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();