diff --git a/packages/migrator/src/Commands/SqlMigration.php b/packages/migrator/src/Commands/SqlMigration.php index 61ee05cf..02a65846 100644 --- a/packages/migrator/src/Commands/SqlMigration.php +++ b/packages/migrator/src/Commands/SqlMigration.php @@ -4,8 +4,8 @@ use Illuminate\Database\Console\Migrations\BaseCommand; use Illuminate\Support\Str; +use LastDragon_ru\LaraASP\Core\Path\DirectoryPath; use LastDragon_ru\LaraASP\Core\Utils\Cast; -use LastDragon_ru\LaraASP\Core\Utils\Path; use LastDragon_ru\LaraASP\Migrator\Migrations\SqlMigrationCreator; use LastDragon_ru\LaraASP\Migrator\Package; use Override; @@ -33,7 +33,8 @@ protected function configure(): void { public function __invoke(SqlMigrationCreator $creator): int { $name = Str::snake(trim(Cast::toString($this->input->getArgument('name')))); $path = Cast::toStringNullable($this->input->getOption('path')) ?? $this->getMigrationPath(); - $path = Path::getPath($this->laravel->basePath(), $path); + $path = (new DirectoryPath($this->laravel->basePath()))->getFilePath($path); + $path = (string) $path; $file = $creator->create($name, $path); $this->components->info(sprintf('SQL Migration [%s] created successfully.', $file)); diff --git a/packages/migrator/src/Migrations/Migrator.php b/packages/migrator/src/Migrations/Migrator.php index ad4e0507..b0c87755 100644 --- a/packages/migrator/src/Migrations/Migrator.php +++ b/packages/migrator/src/Migrations/Migrator.php @@ -3,8 +3,8 @@ namespace LastDragon_ru\LaraASP\Migrator\Migrations; use Illuminate\Database\Migrations\Migrator as IlluminateMigrator; +use LastDragon_ru\LaraASP\Core\Path\DirectoryPath; use LastDragon_ru\LaraASP\Core\Utils\Cast; -use LastDragon_ru\LaraASP\Core\Utils\Path; use Override; use Symfony\Component\Finder\Finder; @@ -38,7 +38,7 @@ public function getMigrationFiles($paths): array { foreach ($paths as $path) { foreach (Finder::create()->in(Cast::toString($path))->directories() as $dir) { - $paths[] = Path::normalize($dir->getPathname()); + $paths[] = (string) (new DirectoryPath($dir->getPathname()))->getNormalizedPath(); } } diff --git a/packages/migrator/src/Migrations/SqlMigrationTest.php b/packages/migrator/src/Migrations/SqlMigrationTest.php index 8a915553..eb9ef9f8 100644 --- a/packages/migrator/src/Migrations/SqlMigrationTest.php +++ b/packages/migrator/src/Migrations/SqlMigrationTest.php @@ -3,7 +3,8 @@ namespace LastDragon_ru\LaraASP\Migrator\Migrations; use Illuminate\Database\Connection; -use LastDragon_ru\LaraASP\Core\Utils\Path; +use LastDragon_ru\LaraASP\Core\Path\DirectoryPath; +use LastDragon_ru\LaraASP\Core\Path\FilePath; use LastDragon_ru\LaraASP\Migrator\Testing\Package\TestCase; use LastDragon_ru\LaraASP\Testing\Mockery\MockProperties; use Mockery; @@ -63,7 +64,7 @@ public function testUp(): void { // With file, No Connection $file = pathinfo(__FILE__, PATHINFO_FILENAME); - $directory = __DIR__; + $directory = new DirectoryPath(__DIR__); $migration = Mockery::mock(SqlMigration::class, MockProperties::class); $migration->shouldAllowMockingProtectedMethods(); $migration->makePartial(); @@ -77,7 +78,7 @@ public function testUp(): void { ->withArgs( static function (Connection $connection, string $path) use ($aConnection, $directory, $file): bool { return $aConnection === $connection - && Path::normalize($path) === Path::join($directory, "{$file}~up.sql"); + && $directory->getFilePath("{$file}~up.sql")->isEqual(new FilePath($path)); }, ) ->once() @@ -89,7 +90,7 @@ static function (Connection $connection, string $path) use ($aConnection, $direc // With file, With Driver $file = pathinfo(__FILE__, PATHINFO_FILENAME); - $directory = __DIR__; + $directory = new DirectoryPath(__DIR__); $migration = Mockery::mock(SqlMigration::class, MockProperties::class); $migration->shouldAllowMockingProtectedMethods(); $migration->makePartial(); @@ -103,7 +104,7 @@ static function (Connection $connection, string $path) use ($aConnection, $direc ->withArgs( static function (Connection $connection, string $path) use ($aConnection, $directory, $file): bool { return $aConnection === $connection - && Path::normalize($path) === Path::join($directory, "{$file}~a.up.sql"); + && $directory->getFilePath("{$file}~a.up.sql")->isEqual(new FilePath($path)); }, ) ->once() @@ -116,7 +117,7 @@ static function (Connection $connection, string $path) use ($aConnection, $direc // With file, With Connection $file = pathinfo(__FILE__, PATHINFO_FILENAME); - $directory = __DIR__; + $directory = new DirectoryPath(__DIR__); $migration = Mockery::mock(SqlMigration::class, MockProperties::class); $migration->shouldAllowMockingProtectedMethods(); $migration->makePartial(); @@ -130,7 +131,7 @@ static function (Connection $connection, string $path) use ($aConnection, $direc ->withArgs( static function (Connection $connection, string $path) use ($bConnection, $directory, $file): bool { return $bConnection === $connection - && Path::normalize($path) === Path::join($directory, "{$file}~up.sql"); + && $directory->getFilePath("{$file}~up.sql")->isEqual(new FilePath($path)); }, ) ->once() @@ -187,7 +188,7 @@ public function testDown(): void { // With file, No Connection $file = pathinfo(__FILE__, PATHINFO_FILENAME); - $directory = __DIR__; + $directory = new DirectoryPath(__DIR__); $migration = Mockery::mock(SqlMigration::class, MockProperties::class); $migration->shouldAllowMockingProtectedMethods(); $migration->makePartial(); @@ -201,7 +202,7 @@ public function testDown(): void { ->withArgs( static function (Connection $connection, string $path) use ($aConnection, $directory, $file): bool { return $aConnection === $connection - && Path::normalize($path) === Path::join($directory, "{$file}~down.sql"); + && $directory->getFilePath("{$file}~down.sql")->isEqual(new FilePath($path)); }, ) ->once() @@ -213,7 +214,7 @@ static function (Connection $connection, string $path) use ($aConnection, $direc // With file, With Driver $file = pathinfo(__FILE__, PATHINFO_FILENAME); - $directory = __DIR__; + $directory = new DirectoryPath(__DIR__); $migration = Mockery::mock(SqlMigration::class, MockProperties::class); $migration->shouldAllowMockingProtectedMethods(); $migration->makePartial(); @@ -227,7 +228,7 @@ static function (Connection $connection, string $path) use ($aConnection, $direc ->withArgs( static function (Connection $connection, string $path) use ($aConnection, $directory, $file): bool { return $aConnection === $connection - && Path::normalize($path) === Path::join($directory, "{$file}~a.down.sql"); + && $directory->getFilePath("{$file}~a.down.sql")->isEqual(new FilePath($path)); }, ) ->once() @@ -240,7 +241,7 @@ static function (Connection $connection, string $path) use ($aConnection, $direc // With file, With Connection $file = pathinfo(__FILE__, PATHINFO_FILENAME); - $directory = __DIR__; + $directory = new DirectoryPath(__DIR__); $migration = Mockery::mock(SqlMigration::class, MockProperties::class); $migration->shouldAllowMockingProtectedMethods(); $migration->makePartial(); @@ -254,7 +255,7 @@ static function (Connection $connection, string $path) use ($aConnection, $direc ->withArgs( static function (Connection $connection, string $path) use ($bConnection, $directory, $file): bool { return $bConnection === $connection - && Path::normalize($path) === Path::join($directory, "{$file}~down.sql"); + && $directory->getFilePath("{$file}~down.sql")->isEqual(new FilePath($path)); }, ) ->once()