Skip to content

Commit

Permalink
A few more path normalizations.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaspertey committed Mar 11, 2024
1 parent 9fe6999 commit 60b0e0d
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 15 deletions.
10 changes: 4 additions & 6 deletions src/Commands/DomainGeneratorCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions tests/Expectations.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use Lunarstorm\LaravelDDD\Support\Path;

use function PHPUnit\Framework\assertMatchesRegularExpression;

expect()->extend('toMatchRegularExpression', function ($pattern, string $message = '') {
Expand All @@ -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));
});
4 changes: 1 addition & 3 deletions tests/Generator/MakeFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 1 addition & 3 deletions tests/Generator/MakeModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 60b0e0d

Please sign in to comment.