From e795621b69b234f4ace888620d023a0ff9baf5ea Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Thu, 13 Oct 2022 01:11:36 +0300 Subject: [PATCH 1/3] Refactored path --- src/Console/Command.php | 2 +- src/Processors/Fresh.php | 2 +- src/Processors/Install.php | 13 +++++-- src/Processors/Make.php | 23 ++++++++----- src/Processors/Migrate.php | 24 +++++++------ src/Processors/Processor.php | 32 +++--------------- src/Processors/Refresh.php | 9 +++-- src/Processors/Reset.php | 5 ++- src/Processors/Rollback.php | 14 ++------ src/Processors/Status.php | 2 +- src/Processors/Upgrade.php | 34 +++++++++++-------- src/Services/Migrator.php | 62 +++++++++++++++++++--------------- src/Values/Options.php | 16 +++++++++ tests/Commands/MigrateTest.php | 5 ++- 14 files changed, 129 insertions(+), 114 deletions(-) diff --git a/src/Console/Command.php b/src/Console/Command.php index a08a83bc..6ba40ed0 100644 --- a/src/Console/Command.php +++ b/src/Console/Command.php @@ -51,6 +51,6 @@ protected function container(): Container protected function getOptionsDto(): OptionsDto { - return OptionsDto::fromArray(array_merge($this->options(), $this->arguments())); + return OptionsDto::fromArray(array_merge($this->options(), $this->arguments()))->resolvePath(); } } diff --git a/src/Processors/Fresh.php b/src/Processors/Fresh.php index bba52c52..dd7b8342 100644 --- a/src/Processors/Fresh.php +++ b/src/Processors/Fresh.php @@ -36,7 +36,7 @@ protected function migrate(): void $this->runCommand(Names::MIGRATE, [ '--' . Options::CONNECTION => $this->options->connection, '--' . Options::PATH => $this->options->path, - '--' . Options::REALPATH => $this->options->realpath, + '--' . Options::REALPATH => true, ]); } } diff --git a/src/Processors/Install.php b/src/Processors/Install.php index 39683fde..ad7e7806 100644 --- a/src/Processors/Install.php +++ b/src/Processors/Install.php @@ -5,6 +5,8 @@ namespace DragonCode\LaravelActions\Processors; use DragonCode\Support\Facades\Filesystem\Directory; +use DragonCode\Support\Facades\Filesystem\Path; +use DragonCode\Support\Facades\Helpers\Str; class Install extends Processor { @@ -34,8 +36,13 @@ protected function create(): void protected function ensureDirectory(): void { - Directory::ensureDirectory( - $this->getActionsPath(realpath: $this->options->realpath) - ); + $this->isFile($this->options->path) + ? Directory::ensureDirectory(Path::dirname($this->options->path)) + : Directory::ensureDirectory($this->options->path); + } + + protected function isFile(string $path): bool + { + return Str::of($path)->lower()->endsWith('.php'); } } diff --git a/src/Processors/Make.php b/src/Processors/Make.php index b2af904f..fedb4653 100644 --- a/src/Processors/Make.php +++ b/src/Processors/Make.php @@ -10,7 +10,7 @@ class Make extends Processor { - protected string $fallbackName = 'auto'; + protected string $fallback = 'auto'; protected string $stub = __DIR__ . '/../../resources/stubs/action.stub'; @@ -22,9 +22,9 @@ public function handle(): void protected function run(): void { $name = $this->getName(); - $path = $this->getActionsPath($name, realpath: $this->options->realpath); + $path = $this->getPath(); - $this->create($path); + $this->create($path . '/' . $name); } protected function create(string $path): void @@ -34,20 +34,27 @@ protected function create(string $path): void protected function getName(): string { - $branch = $this->getBranchName(); - $filename = $this->getFilename($branch); + $branch = $this->getBranchName(); - return Path::dirname($branch) . DIRECTORY_SEPARATOR . $filename; + return $this->getFilename($branch); + } + + protected function getPath(): string + { + return $this->options->path; } protected function getFilename(string $branch): string { - return Str::of(Path::filename($branch))->prepend($this->getTime())->finish('.php')->toString(); + $directory = Path::dirname($branch); + $filename = Path::filename($branch); + + return Str::of($filename)->prepend($this->getTime())->finish('.php')->prepend($directory . '/')->toString(); } protected function getBranchName(): string { - return $this->options->name ?? $this->git->currentBranch() ?? $this->fallbackName; + return $this->options->name ?? $this->git->currentBranch() ?? $this->fallback; } protected function getTime(): string diff --git a/src/Processors/Migrate.php b/src/Processors/Migrate.php index a62e9d1d..903db383 100644 --- a/src/Processors/Migrate.php +++ b/src/Processors/Migrate.php @@ -18,7 +18,7 @@ class Migrate extends Processor public function handle(): void { $this->ensureRepository(); - $this->runActions(); + $this->runActions($this->getCompleted()); } protected function ensureRepository(): void @@ -29,10 +29,10 @@ protected function ensureRepository(): void ]); } - protected function runActions(): void + protected function runActions(array $completed): void { try { - if ($files = $this->getNewFiles()) { + if ($files = $this->getNewFiles($completed)) { $this->fireEvent(ActionStarted::class, 'up'); $this->runEach($files, $this->getBatch()); @@ -58,22 +58,24 @@ protected function runEach(array $files, int $batch): void } } - protected function run(string $file, int $batch): void + protected function run(string $filename, int $batch): void { - $this->migrator->runUp($file, $batch, $this->options); + $this->migrator->runUp($filename, $batch, $this->options); } - protected function getNewFiles(): array + protected function getNewFiles(array $completed): array { - $completed = $this->repository->getCompleted()->pluck('action')->toArray(); - return $this->getFiles( - filter : fn (string $file) => ! Str::of($file)->replace('\\', '/')->contains($completed), - path : $this->options->path, - fullpath: true + path: $this->options->path, + filter: fn (string $file) => ! Str::of($file)->replace('\\', '/')->contains($completed) ); } + protected function getCompleted(): array + { + return $this->repository->getCompleted()->pluck('action')->toArray(); + } + protected function getBatch(): int { return $this->repository->getNextBatchNumber(); diff --git a/src/Processors/Processor.php b/src/Processors/Processor.php index 78544d74..e87604f9 100644 --- a/src/Processors/Processor.php +++ b/src/Processors/Processor.php @@ -12,10 +12,8 @@ use DragonCode\LaravelActions\Repositories\ActionRepository; use DragonCode\LaravelActions\Services\Migrator; use DragonCode\LaravelActions\Values\Options; -use DragonCode\Support\Facades\Helpers\Arr; use DragonCode\Support\Facades\Helpers\Str; use DragonCode\Support\Filesystem\File; -use DragonCode\Support\Helpers\Ables\Arrayable; use Illuminate\Console\OutputStyle; use Illuminate\Contracts\Events\Dispatcher; use Symfony\Component\Console\Input\InputInterface; @@ -43,35 +41,15 @@ public function __construct( $this->migrator->setConnection($this->options->connection)->setOutput($this->output); } - protected function getFiles(?Closure $filter = null, ?string $path = null, bool $realpath = false, bool $fullpath = false, bool $withExtension = true): array + protected function getFiles(string $path, ?Closure $filter = null): array { - $path = $this->getActionsPath($path, $realpath); + $file = Str::finish($path, '.php'); - $names = $this->file->exists($path) ? [$path] : $this->file->allPaths($path, $filter, true); - - return Arr::of($names) - ->when( - ! $fullpath, - fn (Arrayable $array) => $array - ->map(fn (string $value) => Str::of(realpath($value))->after(realpath($path))->ltrim('\\/')->toString()) - ) - ->when( - ! $withExtension, - fn (Arrayable $array) => $array - ->map(fn (string $value) => Str::before($value, '.php')) - ) - ->toArray(); - } - - protected function getActionsPath(?string $path = null, bool $realpath = false): string - { - $path = $realpath ? $path : $this->config->path($path); - - if (! is_dir($path) && ! Str::endsWith($path, '.php')) { - return $this->file->exists($path . '.php') ? $path . '.php' : $path; + if ($this->file->exists($file) && $this->file->isFile($file)) { + return [$file]; } - return $path; + return $this->file->names($path, $filter, true); } protected function runCommand(string $command, array $options = []): void diff --git a/src/Processors/Refresh.php b/src/Processors/Refresh.php index 0ed70b15..b46a05d4 100644 --- a/src/Processors/Refresh.php +++ b/src/Processors/Refresh.php @@ -13,13 +13,12 @@ public function handle(): void { $connection = $this->options->connection; $path = $this->options->path; - $realPath = $this->options->realpath; - $this->runReset($connection, $path, $realPath); - $this->runMigrate($connection, $path, $realPath); + $this->runReset($connection, $path); + $this->runMigrate($connection, $path); } - protected function runReset(?string $connection, ?string $path, bool $realPath): void + protected function runReset(?string $connection, ?string $path, bool $realPath = true): void { $this->runCommand(Names::RESET, [ '--' . Options::CONNECTION => $connection, @@ -29,7 +28,7 @@ protected function runReset(?string $connection, ?string $path, bool $realPath): ]); } - protected function runMigrate(?string $connection, ?string $path, bool $realPath): void + protected function runMigrate(?string $connection, ?string $path, bool $realPath = true): void { $this->runCommand(Names::MIGRATE, [ '--' . Options::CONNECTION => $connection, diff --git a/src/Processors/Reset.php b/src/Processors/Reset.php index e57ecf0b..19f3e20c 100644 --- a/src/Processors/Reset.php +++ b/src/Processors/Reset.php @@ -14,17 +14,16 @@ public function handle(): void $this->rollback( $this->options->connection, $this->options->path, - $this->options->realpath, $this->count() ); } - protected function rollback(?string $connection, ?string $path, ?bool $realPath, int $step): void + protected function rollback(?string $connection, ?string $path, int $step): void { $this->runCommand(Names::ROLLBACK, [ '--' . Options::CONNECTION => $connection, '--' . Options::PATH => $path, - '--' . Options::REALPATH => $realPath, + '--' . Options::REALPATH => true, '--' . Options::STEP => $step, '--' . Options::FORCE => true, ]); diff --git a/src/Processors/Rollback.php b/src/Processors/Rollback.php index b0851d87..f200ee51 100644 --- a/src/Processors/Rollback.php +++ b/src/Processors/Rollback.php @@ -7,7 +7,6 @@ use DragonCode\LaravelActions\Events\ActionEnded; use DragonCode\LaravelActions\Events\ActionStarted; use DragonCode\LaravelActions\Events\NoPendingActions; -use DragonCode\Support\Facades\Helpers\Str; class Rollback extends Processor { @@ -35,9 +34,7 @@ public function handle(): void protected function run(array $actions): void { foreach ($actions as $row) { - $this->rollbackAction( - $this->resolveFilename($row->action) - ); + $this->rollbackAction($row->action); } } @@ -50,9 +47,7 @@ protected function getActions(?int $step): array protected function rollbackAction(string $action): void { - $this->migrator->runDown( - $this->getActionsPath($action, realpath: $this->options->realpath) - ); + $this->migrator->runDown($action, $this->options); } protected function nothingToRollback(): bool @@ -70,9 +65,4 @@ protected function count(): int { return $this->repository->getLastBatchNumber(); } - - protected function resolveFilename(string $name): string - { - return Str::finish($name, '.php'); - } } diff --git a/src/Processors/Status.php b/src/Processors/Status.php index 25b06430..3c5bf6f3 100644 --- a/src/Processors/Status.php +++ b/src/Processors/Status.php @@ -50,7 +50,7 @@ protected function showStatus(array $actions, array $completed): void protected function getData(): array { - $files = $this->getFiles(withExtension: false); + $files = $this->getFiles($this->options->path); $completed = $this->getCompleted(); return [$files, $completed]; diff --git a/src/Processors/Upgrade.php b/src/Processors/Upgrade.php index fe258b24..fbc106d0 100644 --- a/src/Processors/Upgrade.php +++ b/src/Processors/Upgrade.php @@ -56,24 +56,20 @@ protected function move(string $filename): void protected function clean(): void { - $this->notification->task('Delete old directory', fn () => Directory::ensureDelete( - database_path('actions') - )); + $this->notification->task( + 'Delete old directory', + fn () => Directory::ensureDelete($this->oldPath()) + ); } protected function open(string $filename): string { - return file_get_contents(base_path('database/actions/' . $filename)); + return file_get_contents($this->oldPath($filename)); } protected function store(string $filename, string $content): void { - File::store($this->config->path($filename), $content); - } - - protected function delete(string $filename): void - { - File::ensureDelete($filename); + File::store($this->newPath($filename), $content); } protected function replaceNamespace(string $content): string @@ -149,20 +145,30 @@ protected function callMigration(): void : __DIR__ . '/../../database/migrations/named/2022_08_18_180137_change_migration_actions_table.php'; $this->artisan('migrate', [ - '--path' => $path, + '--path' => $path, '--realpath' => true, - '--force' => true, + '--force' => true, ]); }); } protected function getOldFiles(): array { - return $this->getFiles(path: database_path('actions'), realpath: true); + return $this->getFiles($this->oldPath()); + } + + protected function oldPath(?string $filename = null): string + { + return database_path('actions/' . $filename); + } + + protected function newPath(?string $filename = null): string + { + return $this->options->path . '/' . $filename; } protected function alreadyUpgraded(): bool { - return Directory::exists($this->config->path()); + return Directory::exists($this->newPath()); } } diff --git a/src/Services/Migrator.php b/src/Services/Migrator.php index 550d40d8..fce34525 100644 --- a/src/Services/Migrator.php +++ b/src/Services/Migrator.php @@ -20,11 +20,11 @@ class Migrator { public function __construct( - protected File $file, - protected Notification $notification, + protected File $file, + protected Notification $notification, protected ActionRepository $repository, - protected Config $config, - protected Application $laravel + protected Config $config, + protected Application $laravel ) { } @@ -42,10 +42,11 @@ public function setOutput(OutputStyle $output): self return $this; } - public function runUp(string $file, int $batch, Options $options): void + public function runUp(string $filename, int $batch, Options $options): void { - $action = $this->resolvePath($file); - $name = $this->resolveActionName($file); + $path = $this->resolvePath($filename, $options->path); + $action = $this->resolveAction($path); + $name = $this->resolveActionName($filename); if ($this->allowAction($action, $name, $options)) { $this->hasAction($action, '__invoke') @@ -58,10 +59,11 @@ public function runUp(string $file, int $batch, Options $options): void } } - public function runDown(string $file): void + public function runDown(string $filename, Options $options): void { - $action = $this->resolvePath($file); - $name = $this->resolveActionName($file); + $path = $this->resolvePath($filename, $options->path); + $action = $this->resolveAction($path); + $name = $this->resolveActionName($filename); if (! $this->hasAction($action, '__invoke') && $this->hasAction($action, 'down')) { $this->runAction($action, $name, 'down'); @@ -77,23 +79,20 @@ protected function hasAction(Action $action, string $method): bool protected function runAction(Action $action, string $name, string $method): void { - $this->notification->task( - Str::of($name)->before('.php')->prepend('Action: ')->toString(), - function () use ($action, $method) { - if ($this->hasAction($action, $method)) { - try { - $this->runMethod($action, $method, $action->enabledTransactions(), $action->transactionAttempts()); + $this->notification->task($name, function () use ($action, $method) { + if ($this->hasAction($action, $method)) { + try { + $this->runMethod($action, $method, $action->enabledTransactions(), $action->transactionAttempts()); - $action->success(); - } - catch (Throwable $e) { - $action->failed(); + $action->success(); + } + catch (Throwable $e) { + $action->failed(); - throw $e; - } + throw $e; } } - ); + }); } protected function runMethod(Action $action, string $method, bool $transactions, int $attempts): void @@ -159,7 +158,16 @@ protected function allowLogging(Action $action): bool return $action->isOnce(); } - protected function resolvePath(string $path): Action + protected function resolvePath(string $filename, string $path): string + { + if ($this->file->exists($filename) && $this->file->isFile($filename)) { + return $filename; + } + + return Str::finish($path . DIRECTORY_SEPARATOR . $filename, '.php'); + } + + protected function resolveAction(string $path): Action { if ($this->file->exists($path)) { return require $path; @@ -168,12 +176,12 @@ protected function resolvePath(string $path): Action throw new FileNotFoundException($path); } - protected function resolveActionName(string $path): string + protected function resolveActionName(string $filename): string { - return Str::of(realpath($path)) - ->after(realpath($this->config->path())) + return Str::of($filename) ->ltrim('\\/') ->replace('\\', '/') + ->before('.php') ->toString(); } } diff --git a/src/Values/Options.php b/src/Values/Options.php index 560e3ed4..8bd33b28 100644 --- a/src/Values/Options.php +++ b/src/Values/Options.php @@ -4,8 +4,10 @@ namespace DragonCode\LaravelActions\Values; +use DragonCode\LaravelActions\Helpers\Config; use DragonCode\SimpleDataTransferObject\DataTransferObject; use DragonCode\Support\Facades\Helpers\Str; +use Illuminate\Container\Container; class Options extends DataTransferObject { @@ -23,6 +25,15 @@ class Options extends DataTransferObject public ?int $step = null; + public function resolvePath(): self + { + $this->path = $this->realpath + ? $this->path ?: $this->config()->path() + : $this->config()->path($this->path); + + return $this; + } + protected function castName(?string $value): ?string { if (empty($value)) { @@ -37,4 +48,9 @@ protected function castName(?string $value): ?string ->implode(DIRECTORY_SEPARATOR) ->toString(); } + + protected function config(): Config + { + return Container::getInstance()->make(Config::class); + } } diff --git a/tests/Commands/MigrateTest.php b/tests/Commands/MigrateTest.php index 2027859d..61f0711a 100644 --- a/tests/Commands/MigrateTest.php +++ b/tests/Commands/MigrateTest.php @@ -312,6 +312,9 @@ public function testUpFailedOnException() $this->assertDatabaseCount($this->table, 11); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_failed_failure'); + $this->assertDatabaseCount($table, 0); + $this->assertDatabaseCount($this->table, 11); + try { $this->copyFailedMethod(); @@ -325,7 +328,7 @@ public function testUpFailedOnException() $this->assertTrue(Str::contains($e->getFile(), 'run_failed_failure')); } - $this->assertDatabaseCount($table, 1); + $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 11); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_failed_failure'); } From cb0405c816c782ec698dd50cefc1b46a0cef4284 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Thu, 13 Oct 2022 01:37:10 +0300 Subject: [PATCH 2/3] Fixed sorting files --- src/Helpers/Sorter.php | 36 ++++++++++++++ src/Processors/Processor.php | 24 ++++++---- tests/Commands/MigrateTest.php | 34 ++++++++++++++ tests/{Services => Helpers}/GitTest.php | 2 +- tests/Helpers/SorterTest.php | 62 +++++++++++++++++++++++++ 5 files changed, 147 insertions(+), 11 deletions(-) create mode 100644 src/Helpers/Sorter.php rename tests/{Services => Helpers}/GitTest.php (95%) create mode 100644 tests/Helpers/SorterTest.php diff --git a/src/Helpers/Sorter.php b/src/Helpers/Sorter.php new file mode 100644 index 00000000..3288dc6f --- /dev/null +++ b/src/Helpers/Sorter.php @@ -0,0 +1,36 @@ +callback()); + } + + public function byKeys(array $items): array + { + return Arr::ksort($items, $this->callback()); + } + + protected function callback(): Closure + { + return function (string $a, string $b): int { + $current = Path::filename($a); + $next = Path::filename($b); + + if ($current === $next) { + return 0; + } + + return $current < $next ? -1 : 1; + }; + } +} diff --git a/src/Processors/Processor.php b/src/Processors/Processor.php index e87604f9..9d97c37a 100644 --- a/src/Processors/Processor.php +++ b/src/Processors/Processor.php @@ -9,6 +9,7 @@ use DragonCode\LaravelActions\Contracts\Notification; use DragonCode\LaravelActions\Helpers\Config; use DragonCode\LaravelActions\Helpers\Git; +use DragonCode\LaravelActions\Helpers\Sorter; use DragonCode\LaravelActions\Repositories\ActionRepository; use DragonCode\LaravelActions\Services\Migrator; use DragonCode\LaravelActions\Values\Options; @@ -25,16 +26,17 @@ abstract class Processor abstract public function handle(): void; public function __construct( - protected Options $options, - protected InputInterface $input, - protected OutputStyle $output, - protected Config $config, + protected Options $options, + protected InputInterface $input, + protected OutputStyle $output, + protected Config $config, protected ActionRepository $repository, - protected Git $git, - protected File $file, - protected Migrator $migrator, - protected Notification $notification, - protected Dispatcher $events + protected Git $git, + protected File $file, + protected Migrator $migrator, + protected Notification $notification, + protected Dispatcher $events, + protected Sorter $sorter ) { $this->notification->setOutput($this->output); $this->repository->setConnection($this->options->connection); @@ -49,7 +51,9 @@ protected function getFiles(string $path, ?Closure $filter = null): array return [$file]; } - return $this->file->names($path, $filter, true); + return $this->sorter->byValues( + $this->file->names($path, $filter, true) + ); } protected function runCommand(string $command, array $options = []): void diff --git a/tests/Commands/MigrateTest.php b/tests/Commands/MigrateTest.php index 61f0711a..14f32c51 100644 --- a/tests/Commands/MigrateTest.php +++ b/tests/Commands/MigrateTest.php @@ -4,6 +4,7 @@ use DragonCode\LaravelActions\Constants\Names; use Exception; +use Illuminate\Support\Facades\DB; use Illuminate\Support\Str; use Tests\TestCase; use Throwable; @@ -521,4 +522,37 @@ public function testDI(): void $this->assertDatabaseMigrationHas($table, 'invoke_down', column: 'value'); $this->assertDatabaseMigrationHas($table, 'invoke', column: 'value'); } + + public function testSorting(): void + { + $files = []; + + $this->artisan(Names::INSTALL)->assertExitCode(0); + + $files[] = date('Y_m_d_His_') . 'test1'; + $this->artisan(Names::MAKE, ['name' => 'test1'])->assertExitCode(0); + sleep(2); + $files[] = 'foo/' . date('Y_m_d_His_') . 'test2'; + $this->artisan(Names::MAKE, ['name' => 'foo/test2'])->assertExitCode(0); + sleep(2); + $files[] = 'bar/' . date('Y_m_d_His_') . 'test3'; + $this->artisan(Names::MAKE, ['name' => 'bar/test3'])->assertExitCode(0); + sleep(2); + $files[] = 'foo/' . date('Y_m_d_His_') . 'test4'; + $this->artisan(Names::MAKE, ['name' => 'foo/test4'])->assertExitCode(0); + sleep(2); + $files[] = 'bar/' . date('Y_m_d_His_') . 'test5'; + $this->artisan(Names::MAKE, ['name' => 'bar/test5'])->assertExitCode(0); + sleep(2); + $files[] = date('Y_m_d_His_') . 'test6'; + $this->artisan(Names::MAKE, ['name' => 'test6'])->assertExitCode(0); + + $this->assertDatabaseCount($this->table, 0); + $this->artisan(Names::MIGRATE)->assertExitCode(0); + $this->assertDatabaseCount($this->table, 6); + + $records = DB::table($this->table)->orderBy('id')->pluck('action')->toArray(); + + $this->assertSame($files, $records); + } } diff --git a/tests/Services/GitTest.php b/tests/Helpers/GitTest.php similarity index 95% rename from tests/Services/GitTest.php rename to tests/Helpers/GitTest.php index d8980c04..fbf15003 100644 --- a/tests/Services/GitTest.php +++ b/tests/Helpers/GitTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Tests\Services; +namespace Tests\Helpers; use DragonCode\LaravelActions\Helpers\Git; use Tests\TestCase; diff --git a/tests/Helpers/SorterTest.php b/tests/Helpers/SorterTest.php new file mode 100644 index 00000000..0358f0a0 --- /dev/null +++ b/tests/Helpers/SorterTest.php @@ -0,0 +1,62 @@ +assertSame($expected, $this->sorter()->byValues($values)); + } + + public function testByKeys(): void + { + $expected = [ + '2022_10_13_013321_test1' => 1, + 'foo/2022_10_13_013321_test2' => 2, + 'bar/2022_10_13_013321_test3' => 3, + 'foo/2022_10_13_013321_test4' => 4, + 'bar/2022_10_13_013321_test5' => 5, + '2022_10_13_013321_test6' => 6, + ]; + + $values = [ + '2022_10_13_013321_test1' => 1, + '2022_10_13_013321_test6' => 6, + 'bar/2022_10_13_013321_test3' => 3, + 'bar/2022_10_13_013321_test5' => 5, + 'foo/2022_10_13_013321_test2' => 2, + 'foo/2022_10_13_013321_test4' => 4, + ]; + + $this->assertSame($expected, $this->sorter()->byKeys($values)); + } + + protected function sorter(): Sorter + { + return new Sorter(); + } +} From a5c42c75ac4fe0853fdfa1ade5ad371cc73b9deb Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Thu, 13 Oct 2022 01:39:00 +0300 Subject: [PATCH 3/3] Fixed code-style --- src/Processors/Processor.php | 20 ++++++++++---------- src/Processors/Upgrade.php | 4 ++-- src/Services/Migrator.php | 8 ++++---- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/Processors/Processor.php b/src/Processors/Processor.php index 9d97c37a..9b8993e0 100644 --- a/src/Processors/Processor.php +++ b/src/Processors/Processor.php @@ -26,17 +26,17 @@ abstract class Processor abstract public function handle(): void; public function __construct( - protected Options $options, - protected InputInterface $input, - protected OutputStyle $output, - protected Config $config, + protected Options $options, + protected InputInterface $input, + protected OutputStyle $output, + protected Config $config, protected ActionRepository $repository, - protected Git $git, - protected File $file, - protected Migrator $migrator, - protected Notification $notification, - protected Dispatcher $events, - protected Sorter $sorter + protected Git $git, + protected File $file, + protected Migrator $migrator, + protected Notification $notification, + protected Dispatcher $events, + protected Sorter $sorter ) { $this->notification->setOutput($this->output); $this->repository->setConnection($this->options->connection); diff --git a/src/Processors/Upgrade.php b/src/Processors/Upgrade.php index fbc106d0..d388514c 100644 --- a/src/Processors/Upgrade.php +++ b/src/Processors/Upgrade.php @@ -145,9 +145,9 @@ protected function callMigration(): void : __DIR__ . '/../../database/migrations/named/2022_08_18_180137_change_migration_actions_table.php'; $this->artisan('migrate', [ - '--path' => $path, + '--path' => $path, '--realpath' => true, - '--force' => true, + '--force' => true, ]); }); } diff --git a/src/Services/Migrator.php b/src/Services/Migrator.php index fce34525..b57c197c 100644 --- a/src/Services/Migrator.php +++ b/src/Services/Migrator.php @@ -20,11 +20,11 @@ class Migrator { public function __construct( - protected File $file, - protected Notification $notification, + protected File $file, + protected Notification $notification, protected ActionRepository $repository, - protected Config $config, - protected Application $laravel + protected Config $config, + protected Application $laravel ) { }