From 60b0e0d9759c013f3a87d45449a384b93106450a Mon Sep 17 00:00:00 2001 From: Jasper Tey Date: Mon, 11 Mar 2024 12:27:14 -0400 Subject: [PATCH] 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();