Skip to content

Commit

Permalink
refactor(migrator)!: The \LastDragon_ru\LaraASP\Core\Path\Path will…
Browse files Browse the repository at this point in the history
… be used instead of `\LastDragon_ru\LaraASP\Core\Utils\Path`.
  • Loading branch information
LastDragon-ru committed Oct 19, 2024
1 parent e3be7e0 commit f3af25a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
5 changes: 3 additions & 2 deletions packages/migrator/src/Commands/SqlMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down
4 changes: 2 additions & 2 deletions packages/migrator/src/Migrations/Migrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
}
}

Expand Down
27 changes: 14 additions & 13 deletions packages/migrator/src/Migrations/SqlMigrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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()
Expand All @@ -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();
Expand All @@ -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()
Expand All @@ -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();
Expand All @@ -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()
Expand Down Expand Up @@ -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();
Expand All @@ -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()
Expand All @@ -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();
Expand All @@ -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()
Expand All @@ -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();
Expand All @@ -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()
Expand Down

0 comments on commit f3af25a

Please sign in to comment.