From 46fb08c0824a5dba155e13357602b70dc574d391 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Wed, 17 Aug 2022 23:10:56 +0300 Subject: [PATCH 001/153] Refactoring project --- .github/workflows/laravel-6.yml | 31 ---- .github/workflows/laravel-7.yml | 2 +- .github/workflows/laravel-8.yml | 2 +- README.md | 26 ++- ide.json | 22 +-- resources/stubs/action-named.stub | 16 -- .../{action-anonymous.stub => action.stub} | 0 src/Concerns/About.php | 19 +++ src/Concerns/Anonymous.php | 20 --- src/Concerns/Argumentable.php | 20 +-- src/Concerns/Infoable.php | 28 +++- src/Concerns/Optionable.php | 16 +- src/Console/Command.php | 56 +++++++ src/Constants/Action.php | 12 -- src/Constants/Command.php | 22 --- src/Constants/Options.php | 18 +++ src/Facades/Git.php | 19 --- src/Facades/Information.php | 17 -- src/ServiceProvider.php | 150 +++--------------- src/{Support => Services}/Actionable.php | 2 +- src/Support/Information.php | 25 --- src/Support/MigrationCreator.php | 7 +- tests/Commands/CreatorTest.php | 12 +- tests/Commands/MakeTest.php | 15 +- tests/Concerns/Actionable.php | 13 -- tests/Concerns/Files.php | 45 +++--- tests/TestCase.php | 4 - .../actions/2020_12_07_153105_foo_bar.php | 2 +- .../actions/2021_01_02_020947_every_time.php | 2 +- .../actions/2021_05_24_120003_run_on_all.php | 2 +- ..._05_24_120003_run_on_many_environments.php | 2 +- .../2021_05_24_120003_run_on_production.php | 2 +- .../2021_05_24_120003_run_on_testing.php | 2 +- ...021_06_07_132849_run_except_production.php | 2 +- .../2021_06_07_132917_run_except_testing.php | 2 +- ...07_134045_run_except_many_environments.php | 2 +- .../actions/2021_10_26_143247_run_allow.php | 2 +- .../2021_10_26_143304_run_disallow.php | 2 +- .../actions/2021_12_23_165047_run_success.php | 2 +- .../actions/2021_12_23_184029_run_failed.php | 2 +- .../2022_08_17_135147_test_before_enabled.php | 2 +- ...2022_08_17_135153_test_before_disabled.php | 2 +- .../sub_path/2021_12_15_205804_baz.php | 2 +- ...021_12_23_165048_run_success_on_failed.php | 2 +- .../2021_12_23_184029_run_failed_failure.php | 2 +- .../actions/2020_12_07_153105_foo_bar.php | 26 --- .../actions/2021_01_02_020947_every_time.php | 23 --- .../actions/2021_05_24_120003_run_on_all.php | 28 ---- ..._05_24_120003_run_on_many_environments.php | 30 ---- .../2021_05_24_120003_run_on_production.php | 30 ---- .../2021_05_24_120003_run_on_testing.php | 30 ---- ...021_06_07_132849_run_except_production.php | 30 ---- .../2021_06_07_132917_run_except_testing.php | 30 ---- ...07_134045_run_except_many_environments.php | 32 ---- .../actions/2021_10_26_143247_run_allow.php | 28 ---- .../2021_10_26_143304_run_disallow.php | 33 ---- .../actions/2021_12_23_165047_run_success.php | 35 ---- .../actions/2021_12_23_184029_run_failed.php | 29 ---- .../2022_08_17_135147_test_before_enabled.php | 30 ---- ...2022_08_17_135153_test_before_disabled.php | 30 ---- .../sub_path/2021_12_15_205804_baz.php | 26 --- ...021_12_23_165048_run_success_on_failed.php | 31 ---- .../2021_12_23_184029_run_failed_failure.php | 31 ---- ...2_15_124237_test_success_transactions.stub | 29 ---- ...02_15_124852_test_failed_transactions.stub | 31 ---- .../app/named/stubs/make_example.stub | 16 -- ...2_15_124237_test_success_transactions.stub | 0 ...02_15_124852_test_failed_transactions.stub | 0 .../{anonymous => }/stubs/make_example.stub | 0 69 files changed, 213 insertions(+), 1050 deletions(-) delete mode 100644 .github/workflows/laravel-6.yml delete mode 100644 resources/stubs/action-named.stub rename resources/stubs/{action-anonymous.stub => action.stub} (100%) create mode 100644 src/Concerns/About.php delete mode 100644 src/Concerns/Anonymous.php create mode 100644 src/Console/Command.php delete mode 100644 src/Constants/Action.php delete mode 100644 src/Constants/Command.php create mode 100644 src/Constants/Options.php delete mode 100644 src/Facades/Git.php delete mode 100644 src/Facades/Information.php rename src/{Support => Services}/Actionable.php (98%) delete mode 100644 src/Support/Information.php delete mode 100644 tests/Concerns/Actionable.php rename tests/fixtures/app/{anonymous => }/actions/2020_12_07_153105_foo_bar.php (89%) rename tests/fixtures/app/{anonymous => }/actions/2021_01_02_020947_every_time.php (88%) rename tests/fixtures/app/{anonymous => }/actions/2021_05_24_120003_run_on_all.php (90%) rename tests/fixtures/app/{anonymous => }/actions/2021_05_24_120003_run_on_many_environments.php (91%) rename tests/fixtures/app/{anonymous => }/actions/2021_05_24_120003_run_on_production.php (91%) rename tests/fixtures/app/{anonymous => }/actions/2021_05_24_120003_run_on_testing.php (91%) rename tests/fixtures/app/{anonymous => }/actions/2021_06_07_132849_run_except_production.php (91%) rename tests/fixtures/app/{anonymous => }/actions/2021_06_07_132917_run_except_testing.php (91%) rename tests/fixtures/app/{anonymous => }/actions/2021_06_07_134045_run_except_many_environments.php (92%) rename tests/fixtures/app/{anonymous => }/actions/2021_10_26_143247_run_allow.php (90%) rename tests/fixtures/app/{anonymous => }/actions/2021_10_26_143304_run_disallow.php (91%) rename tests/fixtures/app/{anonymous => }/actions/2021_12_23_165047_run_success.php (92%) rename tests/fixtures/app/{anonymous => }/actions/2021_12_23_184029_run_failed.php (89%) rename tests/fixtures/app/{anonymous => }/actions/2022_08_17_135147_test_before_enabled.php (91%) rename tests/fixtures/app/{anonymous => }/actions/2022_08_17_135153_test_before_disabled.php (91%) rename tests/fixtures/app/{anonymous => }/actions/sub_path/2021_12_15_205804_baz.php (89%) rename tests/fixtures/app/{anonymous => }/actions_failed/2021_12_23_165048_run_success_on_failed.php (91%) rename tests/fixtures/app/{anonymous => }/actions_failed/2021_12_23_184029_run_failed_failure.php (91%) delete mode 100644 tests/fixtures/app/named/actions/2020_12_07_153105_foo_bar.php delete mode 100644 tests/fixtures/app/named/actions/2021_01_02_020947_every_time.php delete mode 100644 tests/fixtures/app/named/actions/2021_05_24_120003_run_on_all.php delete mode 100644 tests/fixtures/app/named/actions/2021_05_24_120003_run_on_many_environments.php delete mode 100644 tests/fixtures/app/named/actions/2021_05_24_120003_run_on_production.php delete mode 100644 tests/fixtures/app/named/actions/2021_05_24_120003_run_on_testing.php delete mode 100644 tests/fixtures/app/named/actions/2021_06_07_132849_run_except_production.php delete mode 100644 tests/fixtures/app/named/actions/2021_06_07_132917_run_except_testing.php delete mode 100644 tests/fixtures/app/named/actions/2021_06_07_134045_run_except_many_environments.php delete mode 100644 tests/fixtures/app/named/actions/2021_10_26_143247_run_allow.php delete mode 100644 tests/fixtures/app/named/actions/2021_10_26_143304_run_disallow.php delete mode 100644 tests/fixtures/app/named/actions/2021_12_23_165047_run_success.php delete mode 100644 tests/fixtures/app/named/actions/2021_12_23_184029_run_failed.php delete mode 100644 tests/fixtures/app/named/actions/2022_08_17_135147_test_before_enabled.php delete mode 100644 tests/fixtures/app/named/actions/2022_08_17_135153_test_before_disabled.php delete mode 100644 tests/fixtures/app/named/actions/sub_path/2021_12_15_205804_baz.php delete mode 100644 tests/fixtures/app/named/actions_failed/2021_12_23_165048_run_success_on_failed.php delete mode 100644 tests/fixtures/app/named/actions_failed/2021_12_23_184029_run_failed_failure.php delete mode 100644 tests/fixtures/app/named/stubs/2021_02_15_124237_test_success_transactions.stub delete mode 100644 tests/fixtures/app/named/stubs/2021_02_15_124852_test_failed_transactions.stub delete mode 100644 tests/fixtures/app/named/stubs/make_example.stub rename tests/fixtures/app/{anonymous => }/stubs/2021_02_15_124237_test_success_transactions.stub (100%) rename tests/fixtures/app/{anonymous => }/stubs/2021_02_15_124852_test_failed_transactions.stub (100%) rename tests/fixtures/app/{anonymous => }/stubs/make_example.stub (100%) diff --git a/.github/workflows/laravel-6.yml b/.github/workflows/laravel-6.yml deleted file mode 100644 index 11a7b029..00000000 --- a/.github/workflows/laravel-6.yml +++ /dev/null @@ -1,31 +0,0 @@ -name: "Laravel 6" -on: [ push ] - -jobs: - build: - runs-on: ubuntu-latest - - strategy: - fail-fast: true - matrix: - php: [ "7.3", "7.4", "8.0" ] - laravel: [ "6.0" ] - - name: PHP ${{ matrix.php }} - - steps: - - name: Checkout code - uses: actions/checkout@v3 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php }} - extensions: curl, mbstring, zip, pcntl, pdo, pdo_sqlite, iconv - coverage: none - - - name: Install dependencies - run: composer require --dev laravel/framework:^${{ matrix.laravel }} - - - name: Execute tests - run: sudo vendor/bin/phpunit diff --git a/.github/workflows/laravel-7.yml b/.github/workflows/laravel-7.yml index f1af2202..70765fb9 100644 --- a/.github/workflows/laravel-7.yml +++ b/.github/workflows/laravel-7.yml @@ -8,7 +8,7 @@ jobs: strategy: fail-fast: true matrix: - php: [ "7.3", "7.4", "8.0" ] + php: [ "7.4", "8.0" ] laravel: [ "7.0" ] name: PHP ${{ matrix.php }} diff --git a/.github/workflows/laravel-8.yml b/.github/workflows/laravel-8.yml index b5ed48a4..d024d5dc 100644 --- a/.github/workflows/laravel-8.yml +++ b/.github/workflows/laravel-8.yml @@ -8,7 +8,7 @@ jobs: strategy: fail-fast: true matrix: - php: [ "7.3", "7.4", "8.0", "8.1" ] + php: [ "7.4", "8.0", "8.1" ] laravel: [ "8.0" ] name: PHP ${{ matrix.php }} diff --git a/README.md b/README.md index 1bf0fbbb..e6e12478 100644 --- a/README.md +++ b/README.md @@ -159,7 +159,7 @@ In some cases, you need to call the code every time you deploy the application. To do this, override the `$once` variable in the action file: ```php -use DragonCode\LaravelActions\Support\Actionable; +use DragonCode\LaravelActions\Services\Actionable; return new class extends Actionable { @@ -187,7 +187,7 @@ In some cases, it becomes necessary to execute an action in a specific environme For this you can use the `$environment` parameter: ```php -use DragonCode\LaravelActions\Support\Actionable; +use DragonCode\LaravelActions\Services\Actionable; return new class extends Actionable { @@ -204,7 +204,7 @@ return new class extends Actionable You can also specify multiple environment names: ```php -use DragonCode\LaravelActions\Support\Actionable; +use DragonCode\LaravelActions\Services\Actionable; return new class extends Actionable { @@ -227,7 +227,7 @@ In some cases, it becomes necessary to execute an action excluding certain envir For this you can use the `$except_environment` parameter: ```php -use DragonCode\LaravelActions\Support\Actionable; +use DragonCode\LaravelActions\Services\Actionable; return new class extends Actionable { @@ -244,7 +244,7 @@ return new class extends Actionable You can also specify multiple environment names: ```php -use DragonCode\LaravelActions\Support\Actionable; +use DragonCode\LaravelActions\Services\Actionable; return new class extends Actionable { @@ -275,7 +275,7 @@ When calling the `migrate:actions` command with the `before` parameter, the scri For backwards compatibility, the `before` parameter is set to `true` by default, but actions will only be executed if the option is explicitly passed. ```php -use DragonCode\LaravelActions\Support\Actionable; +use DragonCode\LaravelActions\Services\Actionable; return new class extends Actionable { @@ -320,7 +320,7 @@ By setting the `$transactions = true` parameter, you will ensure that your code will reduce the time it takes to create the action. ```php -use DragonCode\LaravelActions\Support\Actionable; +use DragonCode\LaravelActions\Services\Actionable; return new class extends Actionable { @@ -400,8 +400,7 @@ You can also override the `success` and `failed` methods, which are called on su #### If Success ```php -use DragonCode\LaravelActions\Support\Actionable; -use Illuminate\Support\Facade\Log; +use DragonCode\LaravelActions\Services\Actionable;use Illuminate\Support\Facade\Log; return new class extends Actionable { @@ -434,9 +433,7 @@ The log file will contain two `success` entries. #### If Failed ```php -use DragonCode\LaravelActions\Support\Actionable; -use Exeption; -use Illuminate\Support\Facade\Log; +use DragonCode\LaravelActions\Services\Actionable;use Exeption;use Illuminate\Support\Facade\Log; return new class extends Actionable { @@ -471,8 +468,7 @@ The log file will contain two `failed` entries. Quite often, when working with actions, it becomes necessary to run one or another console command, and each time you have to write the following code: ```php -use DragonCode\LaravelActions\Support\Actionable; -use Illuminate\Support\Facades\Artisan; +use DragonCode\LaravelActions\Services\Actionable;use Illuminate\Support\Facades\Artisan; return new class extends Actionable { @@ -488,7 +484,7 @@ return new class extends Actionable Since version [`2.3`](https://github.com/TheDragonCode/laravel-migration-actions/releases/tag/v2.3.0) we have added a method call. Now calling commands has become much easier: ```php -use DragonCode\LaravelActions\Support\Actionable; +use DragonCode\LaravelActions\Services\Actionable; return new class extends Actionable { diff --git a/ide.json b/ide.json index 0182c9d1..6e27b12b 100644 --- a/ide.json +++ b/ide.json @@ -7,29 +7,11 @@ "inputFilter": "migration", "files": [ { - "directory": "/database/actions", + "directory": "/actions", "name": "${CURRENT_TIME|format:yyyy_MM_dd_HHmmss}_${INPUT_CLASS|className|snakeCase}.php", "template": { "type": "stub", - "path": "resources/stubs/action-named.stub", - "parameters": { - "DummyClass": "${INPUT_FQN|className}" - } - } - } - ] - }, - { - "id": "dragon-code.create-anonymous-action", - "name": "Create Anonymous Migration Action", - "inputFilter": "migration", - "files": [ - { - "directory": "/database/actions", - "name": "${CURRENT_TIME|format:yyyy_MM_dd_HHmmss}_${INPUT_CLASS|className|snakeCase}.php", - "template": { - "type": "stub", - "path": "resources/stubs/action-anonymous.stub" + "path": "resources/stubs/action.stub" } } ] diff --git a/resources/stubs/action-named.stub b/resources/stubs/action-named.stub deleted file mode 100644 index f94af728..00000000 --- a/resources/stubs/action-named.stub +++ /dev/null @@ -1,16 +0,0 @@ - [ + 'Version' => '3.0.0', + ]); + } + } +} diff --git a/src/Concerns/Anonymous.php b/src/Concerns/Anonymous.php deleted file mode 100644 index a33a3b74..00000000 --- a/src/Concerns/Anonymous.php +++ /dev/null @@ -1,20 +0,0 @@ -allowAnonymous(); - } -} diff --git a/src/Concerns/Argumentable.php b/src/Concerns/Argumentable.php index f8c2ec33..fe553fe3 100644 --- a/src/Concerns/Argumentable.php +++ b/src/Concerns/Argumentable.php @@ -7,12 +7,8 @@ /** @mixin \Illuminate\Console\Command */ trait Argumentable { - use Anonymous; - protected $auto_prefix = 'auto'; - protected $branch_prefix = 'branch'; - protected function argumentName(): string { if ($name = (string) $this->argument('name')) { @@ -24,11 +20,7 @@ protected function argumentName(): string protected function makeName(): string { - if ($this->allowAnonymous()) { - return $this->getAutoPrefix(); - } - - return $this->getAutoPrefix() . '_' . time(); + return $this->getAutoPrefix(); } protected function getAutoPrefix(): string @@ -38,14 +30,6 @@ protected function getAutoPrefix(): string protected function getGitBranchName(): ?string { - $name = Git::currentBranch(base_path('.git')); - - preg_match('/^\d.*$/', $name, $output); - - if (! empty($output) && $this->disallowAnonymous()) { - return $this->branch_prefix . '_' . $name; - } - - return $name; + return Git::currentBranch(base_path('.git')); } } diff --git a/src/Concerns/Infoable.php b/src/Concerns/Infoable.php index 7c4af5ba..febe1d7e 100644 --- a/src/Concerns/Infoable.php +++ b/src/Concerns/Infoable.php @@ -25,15 +25,35 @@ public function line($string, $style = null, $verbosity = null) } } + /** + * Write a string as warning output. + * + * @param string $string + * @param int|string|null $verbosity + * + * @return void + */ + public function warn($string, $verbosity = null) + { + $this->line($string, 'warn', $verbosity); + } + + /** + * Write a string as standard output. + * + * @param string $message + */ protected function note($message) { $this->line($message); } - protected function parsedVerbosity($verbosity = null) + protected function parsedVerbosity($verbosity = null): int { - return method_exists($this, 'parseVerbosity') - ? $this->parseVerbosity($verbosity) - : OutputInterface::VERBOSITY_NORMAL; + if (method_exists($this, 'parseVerbosity')) { + return $this->parseVerbosity($verbosity); + } + + return OutputInterface::VERBOSITY_NORMAL; } } diff --git a/src/Concerns/Optionable.php b/src/Concerns/Optionable.php index 3e29bc78..af29dd09 100644 --- a/src/Concerns/Optionable.php +++ b/src/Concerns/Optionable.php @@ -2,33 +2,39 @@ namespace DragonCode\LaravelActions\Concerns; +use DragonCode\LaravelActions\Constants\Options; use Illuminate\Support\Str; /** @mixin \Illuminate\Console\Command */ trait Optionable { + protected function optionForce(): bool + { + return $this->hasOption(Options::FORCE) && $this->option(Options::FORCE); + } + protected function optionBefore(): bool { - return $this->input->getOption('before'); + return $this->option(Options::BEFORE); } protected function optionDatabase(): ?string { - return $this->input->getOption('database'); + return $this->option(Options::DATABASE); } protected function optionStep(?int $default = null): ?int { - return $this->input->getOption('step') ?: $default; + return $this->option(Options::STEP) ?: $default; } protected function optionPath(): ?array { - if (! $this->hasOption('path')) { + if (! $this->hasOption(Options::PATH)) { return null; } - if ($path = $this->option('path')) { + if ($path = $this->option(Options::PATH)) { return collect($path)->map(function ($path) { if ($this->usingRealPath()) { return $path; diff --git a/src/Console/Command.php b/src/Console/Command.php new file mode 100644 index 00000000..d56f08c2 --- /dev/null +++ b/src/Console/Command.php @@ -0,0 +1,56 @@ +confirmToProceed()) { + return 1; + } + + $this->process(); + + return 0; + } + + protected function confirmToProceed(): bool + { + if ($this->optionForce()) { + return true; + } + + $this->warn('Application in production'); + + if ($this->confirm('Do you really wish to run this command?')) { + return true; + } + + $this->warn('Command canceled.'); + + return false; + } + + protected function getOptions(): array + { + return [ + [Options::FORCE, null, InputOption::VALUE_NONE, 'Force the operation to run when in production'], + + [Options::DATABASE, null, InputOption::VALUE_OPTIONAL, 'The database connection to use'], + ]; + } +} diff --git a/src/Constants/Action.php b/src/Constants/Action.php deleted file mode 100644 index 4c411a96..00000000 --- a/src/Constants/Action.php +++ /dev/null @@ -1,12 +0,0 @@ - Command::MIGRATE, - 'MigrateFresh' => Command::FRESH, - 'MigrateInstall' => Command::INSTALL, - 'MigrateMake' => Command::MAKE, - 'MigrateRefresh' => Command::REFRESH, - 'MigrateReset' => Command::RESET, - 'MigrateRollback' => Command::ROLLBACK, - 'MigrateStatus' => Command::STATUS, - ]; + use About; - public function register(): void + public function boot(): void { - $this->registerConfig(); - $this->registerRepository(); - $this->registerMigrator(); - $this->registerCreator(); - $this->registerCommands($this->commands); - } - - public function provides(): array - { - return array_merge([ - Action::MIGRATOR, - Action::REPOSITORY, - Action::CREATOR, - ], array_values($this->commands)); - } - - protected function registerRepository(): void - { - $this->app->singleton(Action::REPOSITORY, static function ($app) { - return new DatabaseMigrationRepository($app['db'], $app['config']['database.actions']); - }); - } - - protected function registerMigrator(): void - { - $this->app->singleton(Action::MIGRATOR, static function ($app) { - return new Migrator($app[Action::REPOSITORY], $app['db'], $app['files'], $app['events']); - }); - } - - protected function registerCreator(): void - { - $this->app->singleton(Action::CREATOR, static function ($app) { - return new MigrationCreator($app['files'], __DIR__ . '/../resources/stubs'); - }); - } - - protected function registerCommands(array $commands): void - { - foreach (array_keys($commands) as $command) { - $this->{"register{$command}Command"}(); + if ($this->app->runningInConsole()) { + $this->registerCommands(); + $this->registerAbout(); } - - $this->commands(array_values($commands)); - } - - protected function registerMigrateCommand(): void - { - $this->app->singleton(Command::MIGRATE, static function ($app) { - return new Migrate($app[Action::MIGRATOR], $app[Dispatcher::class]); - }); - } - - protected function registerMigrateStatusCommand(): void - { - $this->app->singleton(Command::STATUS, static function ($app) { - return new Status($app[Action::MIGRATOR]); - }); - } - - protected function registerMigrateInstallCommand(): void - { - $this->app->singleton(Command::INSTALL, static function ($app) { - return new Install($app[Action::REPOSITORY]); - }); - } - - protected function registerMigrateMakeCommand(): void - { - $this->app->singleton(Command::MAKE, function ($app) { - return new Make( - $app[Action::CREATOR], - $app['composer'] - ); - }); - } - - protected function registerMigrateRollbackCommand(): void - { - $this->app->singleton(Command::ROLLBACK, function ($app) { - return new Rollback($app[Action::MIGRATOR]); - }); - } - - protected function registerMigrateResetCommand(): void - { - $this->app->singleton(Command::RESET, function ($app) { - return new Reset($app[Action::MIGRATOR]); - }); - } - - protected function registerMigrateRefreshCommand(): void - { - $this->app->singleton(Command::REFRESH, function () { - return new Refresh(); - }); - } - - protected function registerMigrateFreshCommand(): void - { - $this->app->singleton(Command::FRESH, function () { - return new Fresh(); - }); } - protected function registerConfig(): void + protected function registerCommands(): void { - $this->mergeConfigFrom( - __DIR__ . '/../config/database.php', - 'database' - ); + $this->commands([ + Console\Fresh::class, + Console\Install::class, + Console\Make::class, + Console\Migrate::class, + Console\Refresh::class, + Console\Reset::class, + Console\Rollback::class, + Console\Status::class, + ]); } } diff --git a/src/Support/Actionable.php b/src/Services/Actionable.php similarity index 98% rename from src/Support/Actionable.php rename to src/Services/Actionable.php index 167caaf3..d3038cad 100644 --- a/src/Support/Actionable.php +++ b/src/Services/Actionable.php @@ -1,6 +1,6 @@ 'Done:', - 'Migrating:' => 'Running:', - 'Migration not found' => 'Action not found', - 'Migration table created successfully' => 'Action table created successfully', - 'Migration table not found' => 'Actions table not found', - 'No migrations found' => 'No actions found', - 'Nothing to migrate' => 'Nothing to do', - ]; - - public function replace(string $value): string - { - return str_replace( - array_keys($this->available), - array_values($this->available), - $value - ); - } -} diff --git a/src/Support/MigrationCreator.php b/src/Support/MigrationCreator.php index 02ad9a32..93fa723e 100644 --- a/src/Support/MigrationCreator.php +++ b/src/Support/MigrationCreator.php @@ -2,14 +2,11 @@ namespace DragonCode\LaravelActions\Support; -use DragonCode\LaravelActions\Concerns\Anonymous; use Illuminate\Database\Migrations\MigrationCreator as BaseMigrationCreator; use Illuminate\Filesystem\Filesystem; class MigrationCreator extends BaseMigrationCreator { - use Anonymous; - protected $customStubPath; public function __construct(Filesystem $files, ?string $custom_stub_path) @@ -33,10 +30,8 @@ public function stubPath() protected function getStub($table, $create): string { - $stub = $this->allowAnonymous() ? '/action-anonymous.stub' : '/action-named.stub'; - return $this->files->get( - $this->stubPath() . $stub + $this->stubPath() . '/action.stub' ); } } diff --git a/tests/Commands/CreatorTest.php b/tests/Commands/CreatorTest.php index 0f86dfd1..c0ef5292 100644 --- a/tests/Commands/CreatorTest.php +++ b/tests/Commands/CreatorTest.php @@ -24,11 +24,9 @@ public function testCreateAction() public function testDuplicateOnPrev() { - if ($this->allowAnonymous()) { - $this->assertTrue(true); + $this->assertTrue(true); - return; - } + return; $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('A BarExample class already exists.'); @@ -41,11 +39,9 @@ public function testDuplicateOnPrev() public function testDuplicateOnLatest() { - if ($this->disallowAnonymous()) { - $this->assertTrue(true); + $this->assertTrue(true); - return; - } + return; $name = 'BarExample'; diff --git a/tests/Commands/MakeTest.php b/tests/Commands/MakeTest.php index 97577973..a968634a 100644 --- a/tests/Commands/MakeTest.php +++ b/tests/Commands/MakeTest.php @@ -20,20 +20,17 @@ public function testMakingFiles() $this->assertFileExists($path); - $expected = $this->allowAnonymous() - ? __DIR__ . '/../fixtures/app/anonymous/stubs/make_example.stub' - : __DIR__ . '/../fixtures/app/named/stubs/make_example.stub'; + $expected = __DIR__ . '/../fixtures/app/anonymous/stubs/make_example.stub'; - $this->assertEquals(file_get_contents($expected), file_get_contents($path)); + $this->assertEquals( + file_get_contents($expected), + file_get_contents($path) + ); } public function testAutoName() { - $filename = $this->allowAnonymous() - ? date('Y_m_d_His') . '_auto.php' - : date('Y_m_d_His') . '_auto_' . time() . '.php'; - - $path = database_path('actions/' . $filename); + $path = database_path('actions/' . date('Y_m_d_His') . '_auto.php'); $this->assertFileDoesNotExist($path); diff --git a/tests/Concerns/Actionable.php b/tests/Concerns/Actionable.php deleted file mode 100644 index e46ed374..00000000 --- a/tests/Concerns/Actionable.php +++ /dev/null @@ -1,13 +0,0 @@ -allowAnonymous() - ? __DIR__ . '/../fixtures/app/anonymous/actions' - : __DIR__ . '/../fixtures/app/named/actions'; - } -} diff --git a/tests/Concerns/Files.php b/tests/Concerns/Files.php index facabfbb..0b88e8c4 100644 --- a/tests/Concerns/Files.php +++ b/tests/Concerns/Files.php @@ -15,47 +15,42 @@ protected function freshFiles(): void protected function copyFiles(): void { - $source = $this->allowAnonymous() - ? __DIR__ . '/../fixtures/app/anonymous/actions' - : __DIR__ . '/../fixtures/app/named/actions'; - - File::copyDirectory($source, $this->targetDirectory()); + File::copyDirectory( + __DIR__ . '/../fixtures/app/anonymous/actions', + $this->targetDirectory() + ); } protected function copySuccessFailureMethod() { - $source = $this->allowAnonymous() - ? __DIR__ . '/../fixtures/app/anonymous/actions_failed/2021_12_23_165048_run_success_on_failed.php' - : __DIR__ . '/../fixtures/app/named/actions_failed/2021_12_23_165048_run_success_on_failed.php'; - - File::copy($source, $this->targetDirectory('2021_12_23_165048_run_success_on_failed.php')); + File::copy( + __DIR__ . '/../fixtures/app/anonymous/actions_failed/2021_12_23_165048_run_success_on_failed.php', + $this->targetDirectory('2021_12_23_165048_run_success_on_failed.php') + ); } protected function copyFailedMethod() { - $source = $this->allowAnonymous() - ? __DIR__ . '/../fixtures/app/anonymous/actions_failed/2021_12_23_184029_run_failed_failure.php' - : __DIR__ . '/../fixtures/app/named/actions_failed/2021_12_23_184029_run_failed_failure.php'; - - File::copy($source, $this->targetDirectory('2021_12_23_184029_run_failed_failure.php')); + File::copy( + __DIR__ . '/../fixtures/app/anonymous/actions_failed/2021_12_23_184029_run_failed_failure.php', + $this->targetDirectory('2021_12_23_184029_run_failed_failure.php') + ); } protected function copySuccessTransaction(): void { - $source = $this->allowAnonymous() - ? __DIR__ . '/../fixtures/app/anonymous/stubs/2021_02_15_124237_test_success_transactions.stub' - : __DIR__ . '/../fixtures/app/named/stubs/2021_02_15_124237_test_success_transactions.stub'; - - File::copy($source, $this->targetDirectory('2021_02_15_124237_test_success_transactions.php')); + File::copy( + __DIR__ . '/../fixtures/app/anonymous/stubs/2021_02_15_124237_test_success_transactions.stub', + $this->targetDirectory('2021_02_15_124237_test_success_transactions.php') + ); } protected function copyFailedTransaction(): void { - $source = $this->allowAnonymous() - ? __DIR__ . '/../fixtures/app/anonymous/stubs/2021_02_15_124852_test_failed_transactions.stub' - : __DIR__ . '/../fixtures/app/named/stubs/2021_02_15_124852_test_failed_transactions.stub'; - - File::copy($source, $this->targetDirectory('2021_02_15_124852_test_failed_transactions.php')); + File::copy( + __DIR__ . '/../fixtures/app/anonymous/stubs/2021_02_15_124852_test_failed_transactions.stub', + $this->targetDirectory('2021_02_15_124852_test_failed_transactions.php') + ); } protected function targetDirectory(?string $path = null): string diff --git a/tests/TestCase.php b/tests/TestCase.php index 17584d94..7e1820de 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -2,14 +2,12 @@ namespace Tests; -use DragonCode\LaravelActions\Concerns\Anonymous; use DragonCode\LaravelActions\ServiceProvider; use Illuminate\Console\View\Components\Factory as Components; use Illuminate\Database\Query\Builder; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Support\Facades\DB; use Orchestra\Testbench\TestCase as BaseTestCase; -use Tests\Concerns\Actionable; use Tests\Concerns\AssertDatabase; use Tests\Concerns\Database; use Tests\Concerns\Files; @@ -18,8 +16,6 @@ abstract class TestCase extends BaseTestCase { - use Actionable; - use Anonymous; use AssertDatabase; use Database; use Files; diff --git a/tests/fixtures/app/anonymous/actions/2020_12_07_153105_foo_bar.php b/tests/fixtures/app/actions/2020_12_07_153105_foo_bar.php similarity index 89% rename from tests/fixtures/app/anonymous/actions/2020_12_07_153105_foo_bar.php rename to tests/fixtures/app/actions/2020_12_07_153105_foo_bar.php index f10667b9..d509337b 100644 --- a/tests/fixtures/app/anonymous/actions/2020_12_07_153105_foo_bar.php +++ b/tests/fixtures/app/actions/2020_12_07_153105_foo_bar.php @@ -1,6 +1,6 @@ table()->insert([ - 'value' => Uuid::uuid4(), - ]); - } - - public function down(): void - { - $this->table()->truncate(); - } - - protected function table(): Builder - { - return DB::table('test'); - } -} diff --git a/tests/fixtures/app/named/actions/2021_01_02_020947_every_time.php b/tests/fixtures/app/named/actions/2021_01_02_020947_every_time.php deleted file mode 100644 index 551f6acf..00000000 --- a/tests/fixtures/app/named/actions/2021_01_02_020947_every_time.php +++ /dev/null @@ -1,23 +0,0 @@ -table()->insert([ - 'value' => Uuid::uuid4(), - ]); - } - - protected function table(): Builder - { - return DB::table('every_time'); - } -} diff --git a/tests/fixtures/app/named/actions/2021_05_24_120003_run_on_all.php b/tests/fixtures/app/named/actions/2021_05_24_120003_run_on_all.php deleted file mode 100644 index 60ef9b20..00000000 --- a/tests/fixtures/app/named/actions/2021_05_24_120003_run_on_all.php +++ /dev/null @@ -1,28 +0,0 @@ -table()->insert([ - 'value' => Uuid::uuid4(), - ]); - } - - public function down(): void - { - $this->table()->insert([ - 'value' => Uuid::uuid4(), - ]); - } - - protected function table(): Builder - { - return DB::table('environment'); - } -} diff --git a/tests/fixtures/app/named/actions/2021_05_24_120003_run_on_many_environments.php b/tests/fixtures/app/named/actions/2021_05_24_120003_run_on_many_environments.php deleted file mode 100644 index 9adfddf9..00000000 --- a/tests/fixtures/app/named/actions/2021_05_24_120003_run_on_many_environments.php +++ /dev/null @@ -1,30 +0,0 @@ -table()->insert([ - 'value' => Uuid::uuid4(), - ]); - } - - public function down(): void - { - $this->table()->insert([ - 'value' => Uuid::uuid4(), - ]); - } - - protected function table(): Builder - { - return DB::table('environment'); - } -} diff --git a/tests/fixtures/app/named/actions/2021_05_24_120003_run_on_production.php b/tests/fixtures/app/named/actions/2021_05_24_120003_run_on_production.php deleted file mode 100644 index 78bc81d2..00000000 --- a/tests/fixtures/app/named/actions/2021_05_24_120003_run_on_production.php +++ /dev/null @@ -1,30 +0,0 @@ -table()->insert([ - 'value' => Uuid::uuid4(), - ]); - } - - public function down(): void - { - $this->table()->insert([ - 'value' => Uuid::uuid4(), - ]); - } - - protected function table(): Builder - { - return DB::table('environment'); - } -} diff --git a/tests/fixtures/app/named/actions/2021_05_24_120003_run_on_testing.php b/tests/fixtures/app/named/actions/2021_05_24_120003_run_on_testing.php deleted file mode 100644 index 53838fc8..00000000 --- a/tests/fixtures/app/named/actions/2021_05_24_120003_run_on_testing.php +++ /dev/null @@ -1,30 +0,0 @@ -table()->insert([ - 'value' => Uuid::uuid4(), - ]); - } - - public function down(): void - { - $this->table()->insert([ - 'value' => Uuid::uuid4(), - ]); - } - - protected function table(): Builder - { - return DB::table('environment'); - } -} diff --git a/tests/fixtures/app/named/actions/2021_06_07_132849_run_except_production.php b/tests/fixtures/app/named/actions/2021_06_07_132849_run_except_production.php deleted file mode 100644 index e59d8093..00000000 --- a/tests/fixtures/app/named/actions/2021_06_07_132849_run_except_production.php +++ /dev/null @@ -1,30 +0,0 @@ -table()->insert([ - 'value' => Uuid::uuid4(), - ]); - } - - public function down(): void - { - $this->table()->insert([ - 'value' => Uuid::uuid4(), - ]); - } - - protected function table(): Builder - { - return DB::table('environment'); - } -} diff --git a/tests/fixtures/app/named/actions/2021_06_07_132917_run_except_testing.php b/tests/fixtures/app/named/actions/2021_06_07_132917_run_except_testing.php deleted file mode 100644 index 36f4a9dc..00000000 --- a/tests/fixtures/app/named/actions/2021_06_07_132917_run_except_testing.php +++ /dev/null @@ -1,30 +0,0 @@ -table()->insert([ - 'value' => Uuid::uuid4(), - ]); - } - - public function down(): void - { - $this->table()->insert([ - 'value' => Uuid::uuid4(), - ]); - } - - protected function table(): Builder - { - return DB::table('environment'); - } -} diff --git a/tests/fixtures/app/named/actions/2021_06_07_134045_run_except_many_environments.php b/tests/fixtures/app/named/actions/2021_06_07_134045_run_except_many_environments.php deleted file mode 100644 index bb4a8094..00000000 --- a/tests/fixtures/app/named/actions/2021_06_07_134045_run_except_many_environments.php +++ /dev/null @@ -1,32 +0,0 @@ -table()->insert([ - 'value' => Uuid::uuid4(), - ]); - } - - public function down(): void - { - $this->table()->insert([ - 'value' => Uuid::uuid4(), - ]); - } - - protected function table(): Builder - { - return DB::table('environment'); - } -} diff --git a/tests/fixtures/app/named/actions/2021_10_26_143247_run_allow.php b/tests/fixtures/app/named/actions/2021_10_26_143247_run_allow.php deleted file mode 100644 index 22557cf0..00000000 --- a/tests/fixtures/app/named/actions/2021_10_26_143247_run_allow.php +++ /dev/null @@ -1,28 +0,0 @@ -table()->insert([ - 'value' => Uuid::uuid4(), - ]); - } - - public function down(): void - { - $this->table()->insert([ - 'value' => Uuid::uuid4(), - ]); - } - - protected function table(): Builder - { - return DB::table('environment'); - } -} diff --git a/tests/fixtures/app/named/actions/2021_10_26_143304_run_disallow.php b/tests/fixtures/app/named/actions/2021_10_26_143304_run_disallow.php deleted file mode 100644 index 50e1daff..00000000 --- a/tests/fixtures/app/named/actions/2021_10_26_143304_run_disallow.php +++ /dev/null @@ -1,33 +0,0 @@ -table()->insert([ - 'value' => Uuid::uuid4(), - ]); - } - - public function down(): void - { - $this->table()->insert([ - 'value' => Uuid::uuid4(), - ]); - } - - public function allow(): bool - { - return false; - } - - protected function table(): Builder - { - return DB::table('environment'); - } -} diff --git a/tests/fixtures/app/named/actions/2021_12_23_165047_run_success.php b/tests/fixtures/app/named/actions/2021_12_23_165047_run_success.php deleted file mode 100644 index b5428663..00000000 --- a/tests/fixtures/app/named/actions/2021_12_23_165047_run_success.php +++ /dev/null @@ -1,35 +0,0 @@ -table()->insert([ - 'value' => Uuid::uuid4(), - ]); - } - - public function down(): void - { - $this->table()->insert([ - 'value' => Uuid::uuid4(), - ]); - } - - public function success(): void - { - $this->table()->insert([ - 'value' => Uuid::uuid4(), - ]); - } - - protected function table(): Builder - { - return DB::table('success'); - } -} diff --git a/tests/fixtures/app/named/actions/2021_12_23_184029_run_failed.php b/tests/fixtures/app/named/actions/2021_12_23_184029_run_failed.php deleted file mode 100644 index ef9f224a..00000000 --- a/tests/fixtures/app/named/actions/2021_12_23_184029_run_failed.php +++ /dev/null @@ -1,29 +0,0 @@ -table()->insert([ - 'value' => Uuid::uuid4(), - ]); - } - - protected function table(): Builder - { - return DB::table('success'); - } -} diff --git a/tests/fixtures/app/named/actions/2022_08_17_135147_test_before_enabled.php b/tests/fixtures/app/named/actions/2022_08_17_135147_test_before_enabled.php deleted file mode 100644 index 41a64b9f..00000000 --- a/tests/fixtures/app/named/actions/2022_08_17_135147_test_before_enabled.php +++ /dev/null @@ -1,30 +0,0 @@ -table()->insert([ - 'value' => Uuid::uuid4(), - ]); - } - - public function down(): void - { - $this->table()->insert([ - 'value' => Uuid::uuid4(), - ]); - } - - protected function table(): Builder - { - return DB::table('before'); - } -} diff --git a/tests/fixtures/app/named/actions/2022_08_17_135153_test_before_disabled.php b/tests/fixtures/app/named/actions/2022_08_17_135153_test_before_disabled.php deleted file mode 100644 index cd16a417..00000000 --- a/tests/fixtures/app/named/actions/2022_08_17_135153_test_before_disabled.php +++ /dev/null @@ -1,30 +0,0 @@ -table()->insert([ - 'value' => Uuid::uuid4(), - ]); - } - - public function down(): void - { - $this->table()->insert([ - 'value' => Uuid::uuid4(), - ]); - } - - protected function table(): Builder - { - return DB::table('before'); - } -} diff --git a/tests/fixtures/app/named/actions/sub_path/2021_12_15_205804_baz.php b/tests/fixtures/app/named/actions/sub_path/2021_12_15_205804_baz.php deleted file mode 100644 index 799e20d9..00000000 --- a/tests/fixtures/app/named/actions/sub_path/2021_12_15_205804_baz.php +++ /dev/null @@ -1,26 +0,0 @@ -table()->insert([ - 'value' => Uuid::uuid4(), - ]); - } - - public function down(): void - { - $this->table()->truncate(); - } - - protected function table(): Builder - { - return DB::table('test'); - } -} diff --git a/tests/fixtures/app/named/actions_failed/2021_12_23_165048_run_success_on_failed.php b/tests/fixtures/app/named/actions_failed/2021_12_23_165048_run_success_on_failed.php deleted file mode 100644 index dd5ef362..00000000 --- a/tests/fixtures/app/named/actions_failed/2021_12_23_165048_run_success_on_failed.php +++ /dev/null @@ -1,31 +0,0 @@ -table()->insert([ - 'value' => Uuid::uuid4(), - ]); - } - - protected function table(): Builder - { - return DB::table('success'); - } -} diff --git a/tests/fixtures/app/named/actions_failed/2021_12_23_184029_run_failed_failure.php b/tests/fixtures/app/named/actions_failed/2021_12_23_184029_run_failed_failure.php deleted file mode 100644 index 75c09925..00000000 --- a/tests/fixtures/app/named/actions_failed/2021_12_23_184029_run_failed_failure.php +++ /dev/null @@ -1,31 +0,0 @@ -table()->insert([ - 'value' => Uuid::uuid4(), - ]); - } - - protected function table(): Builder - { - return DB::table('failed'); - } -} diff --git a/tests/fixtures/app/named/stubs/2021_02_15_124237_test_success_transactions.stub b/tests/fixtures/app/named/stubs/2021_02_15_124237_test_success_transactions.stub deleted file mode 100644 index 515e6f1d..00000000 --- a/tests/fixtures/app/named/stubs/2021_02_15_124237_test_success_transactions.stub +++ /dev/null @@ -1,29 +0,0 @@ -table()->insert([ - $this->value(), - $this->value(), - $this->value(), - ]); - } - - protected function table() - { - return DB::table('transactions'); - } - - protected function value(): array - { - return ['value' => Uuid::uuid4()]; - } -} diff --git a/tests/fixtures/app/named/stubs/2021_02_15_124852_test_failed_transactions.stub b/tests/fixtures/app/named/stubs/2021_02_15_124852_test_failed_transactions.stub deleted file mode 100644 index afec5ac7..00000000 --- a/tests/fixtures/app/named/stubs/2021_02_15_124852_test_failed_transactions.stub +++ /dev/null @@ -1,31 +0,0 @@ -table()->insert([ - $this->value(), - $this->value(), - $this->value(), - ]); - - throw new Exception('Random message'); - } - - protected function table() - { - return DB::table('transactions'); - } - - protected function value(): array - { - return ['value' => Uuid::uuid4()]; - } -} diff --git a/tests/fixtures/app/named/stubs/make_example.stub b/tests/fixtures/app/named/stubs/make_example.stub deleted file mode 100644 index 2a53c390..00000000 --- a/tests/fixtures/app/named/stubs/make_example.stub +++ /dev/null @@ -1,16 +0,0 @@ - Date: Wed, 17 Aug 2022 23:11:16 +0300 Subject: [PATCH 002/153] Refactoring Fresh command --- src/Console/Fresh.php | 42 +++++++++++------------------------------- 1 file changed, 11 insertions(+), 31 deletions(-) diff --git a/src/Console/Fresh.php b/src/Console/Fresh.php index 189ce835..29ccbdfc 100644 --- a/src/Console/Fresh.php +++ b/src/Console/Fresh.php @@ -6,55 +6,35 @@ use DragonCode\LaravelActions\Concerns\Optionable; use DragonCode\LaravelActions\Constants\Names; -use Illuminate\Database\Console\Migrations\FreshCommand; +use DragonCode\LaravelActions\Constants\Options; use Illuminate\Support\Facades\Schema; -class Fresh extends FreshCommand +class Fresh extends Command { use Optionable; - /** - * The console command name. - * - * @var string - */ protected $name = Names::FRESH; - /** - * The console command description. - * - * @var string - */ protected $description = 'Drop and re-run all actions'; - public function handle() + public function process(): void { - if (! $this->confirmToProceed()) { - return 1; - } - - $database = $this->optionDatabase(); - - $this->dropTable(); - $this->migrate($database); - - return 0; + $this->drop(); + $this->migrate(); } - protected function dropTable(): void + protected function drop(): void { Schema::dropIfExists($this->getTableName()); } - protected function migrate(?string $database): void + protected function migrate(): void { - $this->call( - Names::MIGRATE, + $this->call(Names::MIGRATE, array_filter([ - '--database' => $database, - '--force' => true, - ]) - ); + '--' . Options::DATABASE => $this->optionDatabase(), + '--' . Options::FORCE => true, + ])); } protected function getTableName(): string From 67d0c5f7b17beccedcbfa9344da871f2f6b3ed12 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Thu, 18 Aug 2022 17:50:36 +0300 Subject: [PATCH 003/153] Refactored tests classes --- tests/Commands/CreatorTest.php | 57 ---------------- tests/Commands/FreshTest.php | 13 ++-- tests/Commands/InstallTest.php | 11 ++-- tests/Commands/MakeTest.php | 13 ++-- tests/Commands/MigrateTest.php | 112 +++++++++++++++----------------- tests/Commands/RefreshTest.php | 11 ++-- tests/Commands/ResetTest.php | 11 ++-- tests/Commands/RollbackTest.php | 75 +++++++++++---------- tests/Commands/StatusTest.php | 13 ++-- tests/Concerns/Database.php | 3 + tests/Concerns/Files.php | 2 +- tests/Concerns/Laraveable.php | 13 ---- tests/Concerns/Path.php | 11 ++++ tests/Concerns/Settings.php | 13 ---- tests/TestCase.php | 13 +--- 15 files changed, 149 insertions(+), 222 deletions(-) delete mode 100644 tests/Commands/CreatorTest.php delete mode 100644 tests/Concerns/Laraveable.php create mode 100644 tests/Concerns/Path.php delete mode 100644 tests/Concerns/Settings.php diff --git a/tests/Commands/CreatorTest.php b/tests/Commands/CreatorTest.php deleted file mode 100644 index c0ef5292..00000000 --- a/tests/Commands/CreatorTest.php +++ /dev/null @@ -1,57 +0,0 @@ -targetDirectory($filename); - - $this->assertFileDoesNotExist($path); - - $this->artisan('make:migration:action', compact('name'))->run(); - - $this->assertFileExists($path); - } - - public function testDuplicateOnPrev() - { - $this->assertTrue(true); - - return; - - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('A BarExample class already exists.'); - - $name = 'BarExample'; - - $this->artisan('make:migration:action', compact('name'))->run(); - $this->artisan('make:migration:action', compact('name'))->run(); - } - - public function testDuplicateOnLatest() - { - $this->assertTrue(true); - - return; - - $name = 'BarExample'; - - $time1 = date('Y_m_d_His'); - $this->artisan('make:migration:action', compact('name'))->run(); - - $time2 = date('Y_m_d_His'); - $this->artisan('make:migration:action', compact('name'))->run(); - - $this->assertFileExists($this->targetDirectory($time1 . '_bar_example.php')); - $this->assertFileExists($this->targetDirectory($time2 . '_bar_example.php')); - } -} diff --git a/tests/Commands/FreshTest.php b/tests/Commands/FreshTest.php index fe1192bd..209a4ac8 100644 --- a/tests/Commands/FreshTest.php +++ b/tests/Commands/FreshTest.php @@ -4,26 +4,29 @@ namespace Tests\Commands; +use DragonCode\LaravelActions\Constants\Names; use Tests\TestCase; class FreshTest extends TestCase { - public function testFreshCommand() + public function testFreshCommand(): void { $this->assertDatabaseDoesntTable($this->table); - $this->artisan('migrate:actions:install')->run(); + $this->artisan(Names::INSTALL)->run(); $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 0); - $this->artisan('make:migration:action', ['name' => 'Fresh'])->run(); - $this->artisan('migrate:actions')->run(); + $this->artisan(Names::MAKE, ['name' => 'Fresh'])->run(); + $this->artisan(Names::MIGRATE)->run(); + $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 1); - $this->artisan('migrate:actions:fresh')->run(); + $this->artisan(Names::FRESH)->run(); + $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 1); $this->assertDatabaseMigrationHas($this->table, 'fresh'); } diff --git a/tests/Commands/InstallTest.php b/tests/Commands/InstallTest.php index 6153895f..d27cfd99 100644 --- a/tests/Commands/InstallTest.php +++ b/tests/Commands/InstallTest.php @@ -2,24 +2,23 @@ namespace Tests\Commands; +use DragonCode\LaravelActions\Constants\Names; use Tests\TestCase; class InstallTest extends TestCase { - public function testRepositoryNotFound() + public function testNotFound(): void { $this->assertDatabaseDoesntTable($this->table); - $this->hasTermwind() - ? $this->artisan('migrate:actions:status') - : $this->artisan('migrate:actions:status')->expectsOutput('Actions table not found.'); + $this->artisan(Names::STATUS)->expectsOutput('Actions table not found.'); } - public function testRepository() + public function testCreate(): void { $this->assertDatabaseDoesntTable($this->table); - $this->artisan('migrate:actions:install')->run(); + $this->artisan(Names::INSTALL)->run(); $this->assertDatabaseHasTable($this->table); } diff --git a/tests/Commands/MakeTest.php b/tests/Commands/MakeTest.php index a968634a..8b1c4bee 100644 --- a/tests/Commands/MakeTest.php +++ b/tests/Commands/MakeTest.php @@ -2,6 +2,7 @@ namespace Tests\Commands; +use DragonCode\LaravelActions\Constants\Names; use Tests\TestCase; class MakeTest extends TestCase @@ -10,17 +11,15 @@ public function testMakingFiles() { $name = 'MakeExample'; - $filename = date('Y_m_d_His') . '_make_example.php'; - - $path = database_path('actions/' . $filename); + $path = $this->actionsPath(date('Y_m_d_His') . '_make_example.php'); $this->assertFileDoesNotExist($path); - $this->artisan('make:migration:action', compact('name'))->run(); + $this->artisan(Names::MAKE, compact('name'))->run(); $this->assertFileExists($path); - $expected = __DIR__ . '/../fixtures/app/anonymous/stubs/make_example.stub'; + $expected = __DIR__ . '/../fixtures/app/stubs/make_example.stub'; $this->assertEquals( file_get_contents($expected), @@ -30,11 +29,11 @@ public function testMakingFiles() public function testAutoName() { - $path = database_path('actions/' . date('Y_m_d_His') . '_auto.php'); + $path = $this->actionsPath(date('Y_m_d_His') . '_auto.php'); $this->assertFileDoesNotExist($path); - $this->artisan('make:migration:action')->run(); + $this->artisan(Names::MAKE)->run(); $this->assertFileExists($path); } diff --git a/tests/Commands/MigrateTest.php b/tests/Commands/MigrateTest.php index 1e6b717c..4cd81462 100644 --- a/tests/Commands/MigrateTest.php +++ b/tests/Commands/MigrateTest.php @@ -2,6 +2,7 @@ namespace Tests\Commands; +use DragonCode\LaravelActions\Constants\Names; use Exception; use Illuminate\Support\Str; use Tests\TestCase; @@ -13,13 +14,13 @@ public function testMigrationCommand() { $this->assertDatabaseDoesntTable($this->table); - $this->artisan('migrate:actions:install')->run(); + $this->artisan(Names::INSTALL)->run(); $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 0); - $this->artisan('make:migration:action', ['name' => 'TestMigration'])->run(); - $this->artisan('migrate:actions')->run(); + $this->artisan(Names::MAKE, ['name' => 'TestMigration'])->run(); + $this->artisan(Names::MIGRATE)->run(); $this->assertDatabaseCount($this->table, 1); $this->assertDatabaseMigrationHas($this->table, 'test_migration'); @@ -31,27 +32,27 @@ public function testOnce() $table = 'every_time'; - $this->artisan('migrate:actions:install')->run(); + $this->artisan(Names::INSTALL)->run(); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, $table); - $this->artisan('migrate:actions')->run(); + $this->artisan(Names::MIGRATE)->run(); $this->assertDatabaseCount($table, 1); $this->assertDatabaseCount($this->table, 10); $this->assertDatabaseMigrationDoesntLike($this->table, $table); - $this->artisan('migrate:actions')->run(); + $this->artisan(Names::MIGRATE)->run(); $this->assertDatabaseCount($table, 2); $this->assertDatabaseCount($this->table, 10); $this->assertDatabaseMigrationDoesntLike($this->table, $table); - $this->artisan('migrate:actions')->run(); + $this->artisan(Names::MIGRATE)->run(); $this->assertDatabaseCount($table, 3); $this->assertDatabaseCount($this->table, 10); $this->assertDatabaseMigrationDoesntLike($this->table, $table); - $this->artisan('migrate:actions')->run(); + $this->artisan(Names::MIGRATE)->run(); $this->assertDatabaseCount($table, 4); $this->assertDatabaseCount($this->table, 10); @@ -64,12 +65,12 @@ public function testSuccessTransaction() $table = 'transactions'; - $this->artisan('migrate:actions:install')->run(); + $this->artisan(Names::INSTALL)->run(); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, $table); - $this->artisan('migrate:actions')->run(); + $this->artisan(Names::MIGRATE)->run(); $this->assertDatabaseCount($table, 3); $this->assertDatabaseCount($this->table, 1); @@ -82,16 +83,15 @@ public function testFailedTransaction() $table = 'transactions'; - $this->artisan('migrate:actions:install')->run(); + $this->artisan(Names::INSTALL)->run(); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, $table); try { - $this->artisan('migrate:actions')->run(); - } - catch (Exception $e) { + $this->artisan(Names::MIGRATE)->run(); + } catch (Exception $e) { $this->assertSame(Exception::class, get_class($e)); $this->assertSame('Random message', $e->getMessage()); } @@ -107,7 +107,7 @@ public function testSingleEnvironment() $table = 'environment'; - $this->artisan('migrate:actions:install')->run(); + $this->artisan(Names::INSTALL)->run(); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); @@ -116,7 +116,7 @@ public function testSingleEnvironment() $this->assertDatabaseMigrationDoesntLike($this->table, 'run_on_testing'); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_except_production'); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_except_testing'); - $this->artisan('migrate:actions')->run(); + $this->artisan(Names::MIGRATE)->run(); $this->assertDatabaseCount($table, 5); $this->assertDatabaseCount($this->table, 10); @@ -125,7 +125,7 @@ public function testSingleEnvironment() $this->assertDatabaseMigrationHas($this->table, 'run_on_testing'); $this->assertDatabaseMigrationHas($this->table, 'run_except_production'); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_except_testing'); - $this->artisan('migrate:actions')->run(); + $this->artisan(Names::MIGRATE)->run(); $this->assertDatabaseCount($table, 5); $this->assertDatabaseCount($this->table, 10); @@ -142,7 +142,7 @@ public function testManyEnvironments() $table = 'environment'; - $this->artisan('migrate:actions:install')->run(); + $this->artisan(Names::INSTALL)->run(); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); @@ -153,7 +153,7 @@ public function testManyEnvironments() $this->assertDatabaseMigrationDoesntLike($this->table, 'run_except_production'); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_except_testing'); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_except_many_environments'); - $this->artisan('migrate:actions')->run(); + $this->artisan(Names::MIGRATE)->run(); $this->assertDatabaseCount($table, 5); $this->assertDatabaseCount($this->table, 10); @@ -164,7 +164,7 @@ public function testManyEnvironments() $this->assertDatabaseMigrationHas($this->table, 'run_except_production'); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_except_testing'); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_except_many_environments'); - $this->artisan('migrate:actions')->run(); + $this->artisan(Names::MIGRATE)->run(); $this->assertDatabaseCount($table, 5); $this->assertDatabaseCount($this->table, 10); @@ -183,19 +183,19 @@ public function testAllow() $table = 'environment'; - $this->artisan('migrate:actions:install')->run(); + $this->artisan(Names::INSTALL)->run(); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_allow'); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_disallow'); - $this->artisan('migrate:actions')->run(); + $this->artisan(Names::MIGRATE)->run(); $this->assertDatabaseCount($table, 5); $this->assertDatabaseCount($this->table, 10); $this->assertDatabaseMigrationHas($this->table, 'run_allow'); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_disallow'); - $this->artisan('migrate:actions')->run(); + $this->artisan(Names::MIGRATE)->run(); $this->assertDatabaseCount($table, 5); $this->assertDatabaseCount($this->table, 10); @@ -209,12 +209,12 @@ public function testUpSuccess() $table = 'success'; - $this->artisan('migrate:actions:install')->run(); + $this->artisan(Names::INSTALL)->run(); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_success'); - $this->artisan('migrate:actions')->run(); + $this->artisan(Names::MIGRATE)->run(); $this->assertDatabaseCount($table, 2); $this->assertDatabaseCount($this->table, 10); @@ -227,12 +227,12 @@ public function testUpSuccessOnFailed() $table = 'success'; - $this->artisan('migrate:actions:install')->run(); + $this->artisan(Names::INSTALL)->run(); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_success_on_failed'); - $this->artisan('migrate:actions')->run(); + $this->artisan(Names::MIGRATE)->run(); $this->assertDatabaseCount($table, 2); $this->assertDatabaseCount($this->table, 10); @@ -241,9 +241,8 @@ public function testUpSuccessOnFailed() try { $this->copySuccessFailureMethod(); - $this->artisan('migrate:actions')->run(); - } - catch (Throwable $e) { + $this->artisan(Names::MIGRATE)->run(); + } catch (Throwable $e) { $this->assertInstanceOf(Exception::class, $e); $this->assertSame('Custom exception', $e->getMessage()); @@ -262,12 +261,12 @@ public function testUpFailed() $table = 'failed'; - $this->artisan('migrate:actions:install')->run(); + $this->artisan(Names::INSTALL)->run(); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_failed'); - $this->artisan('migrate:actions')->run(); + $this->artisan(Names::MIGRATE)->run(); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 10); @@ -280,12 +279,12 @@ public function testUpFailedOnException() $table = 'failed'; - $this->artisan('migrate:actions:install')->run(); + $this->artisan(Names::INSTALL)->run(); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_failed_failure'); - $this->artisan('migrate:actions')->run(); + $this->artisan(Names::MIGRATE)->run(); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 10); @@ -294,9 +293,8 @@ public function testUpFailedOnException() try { $this->copyFailedMethod(); - $this->artisan('migrate:actions')->run(); - } - catch (Throwable $e) { + $this->artisan(Names::MIGRATE)->run(); + } catch (Throwable $e) { $this->assertInstanceOf(Exception::class, $e); $this->assertSame('Custom exception', $e->getMessage()); @@ -317,12 +315,12 @@ public function testPathAsFileWithExtension() $path = 'sub_path/2021_12_15_205804_baz.php'; - $this->artisan('migrate:actions:install')->run(); + $this->artisan(Names::INSTALL)->run(); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'baz'); - $this->artisan('migrate:actions', ['--path' => $path])->run(); + $this->artisan(Names::MIGRATE, ['--path' => $path])->run(); $this->assertDatabaseCount($table, 1); $this->assertDatabaseCount($this->table, 1); @@ -337,12 +335,12 @@ public function testPathAsFileWithoutExtension() $path = 'sub_path/2021_12_15_205804_baz'; - $this->artisan('migrate:actions:install')->run(); + $this->artisan(Names::INSTALL)->run(); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'baz'); - $this->artisan('migrate:actions', ['--path' => $path])->run(); + $this->artisan(Names::MIGRATE, ['--path' => $path])->run(); $this->assertDatabaseCount($table, 1); $this->assertDatabaseCount($this->table, 1); @@ -357,12 +355,12 @@ public function testPathAsDirectory() $path = 'sub_path'; - $this->artisan('migrate:actions:install')->run(); + $this->artisan(Names::INSTALL)->run(); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'baz'); - $this->artisan('migrate:actions', ['--path' => $path])->run(); + $this->artisan(Names::MIGRATE, ['--path' => $path])->run(); $this->assertDatabaseCount($table, 1); $this->assertDatabaseCount($this->table, 1); @@ -373,13 +371,11 @@ public function testMigrationNotFound() { $this->assertDatabaseDoesntTable($this->table); - $this->artisan('migrate:actions:install')->run(); + $this->artisan(Names::INSTALL)->run(); $this->assertDatabaseHasTable($this->table); - $this->hasTermwind() - ? $this->artisan('migrate:actions:status') - : $this->artisan('migrate:actions:status')->expectsOutput('No actions found'); + $this->artisan(Names::STATUS)->expectsOutput('No actions found'); } public function testDisabledBefore() @@ -388,19 +384,19 @@ public function testDisabledBefore() $table = 'before'; - $this->artisan('migrate:actions:install')->run(); + $this->artisan(Names::INSTALL)->run(); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'test_before_enabled'); $this->assertDatabaseMigrationDoesntLike($this->table, 'test_before_disabled'); - $this->artisan('migrate:actions')->run(); + $this->artisan(Names::MIGRATE)->run(); $this->assertDatabaseCount($table, 2); $this->assertDatabaseCount($this->table, 10); $this->assertDatabaseMigrationHas($this->table, 'test_before_enabled'); $this->assertDatabaseMigrationHas($this->table, 'test_before_disabled'); - $this->artisan('migrate:actions')->run(); + $this->artisan(Names::MIGRATE)->run(); $this->assertDatabaseCount($table, 2); $this->assertDatabaseCount($this->table, 10); @@ -414,19 +410,19 @@ public function testEnabledBefore() $table = 'before'; - $this->artisan('migrate:actions:install')->run(); + $this->artisan(Names::INSTALL)->run(); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'test_before_enabled'); $this->assertDatabaseMigrationDoesntLike($this->table, 'test_before_disabled'); - $this->artisan('migrate:actions', ['--before' => true])->run(); + $this->artisan(Names::MIGRATE, ['--before' => true])->run(); $this->assertDatabaseCount($table, 1); $this->assertDatabaseCount($this->table, 9); $this->assertDatabaseMigrationHas($this->table, 'test_before_enabled'); $this->assertDatabaseMigrationDoesntLike($this->table, 'test_before_disabled'); - $this->artisan('migrate:actions', ['--before' => true])->run(); + $this->artisan(Names::MIGRATE, ['--before' => true])->run(); $this->assertDatabaseCount($table, 1); $this->assertDatabaseCount($this->table, 9); @@ -440,31 +436,31 @@ public function testMixedBefore() $table = 'before'; - $this->artisan('migrate:actions:install')->run(); + $this->artisan(Names::INSTALL)->run(); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'test_before_enabled'); $this->assertDatabaseMigrationDoesntLike($this->table, 'test_before_disabled'); - $this->artisan('migrate:actions', ['--before' => true])->run(); + $this->artisan(Names::MIGRATE, ['--before' => true])->run(); $this->assertDatabaseCount($table, 1); $this->assertDatabaseCount($this->table, 9); $this->assertDatabaseMigrationHas($this->table, 'test_before_enabled'); $this->assertDatabaseMigrationDoesntLike($this->table, 'test_before_disabled'); - $this->artisan('migrate:actions', ['--before' => true])->run(); + $this->artisan(Names::MIGRATE, ['--before' => true])->run(); $this->assertDatabaseCount($table, 1); $this->assertDatabaseCount($this->table, 9); $this->assertDatabaseMigrationHas($this->table, 'test_before_enabled'); $this->assertDatabaseMigrationDoesntLike($this->table, 'test_before_disabled'); - $this->artisan('migrate:actions')->run(); + $this->artisan(Names::MIGRATE)->run(); $this->assertDatabaseCount($table, 2); $this->assertDatabaseCount($this->table, 10); $this->assertDatabaseMigrationHas($this->table, 'test_before_enabled'); $this->assertDatabaseMigrationHas($this->table, 'test_before_disabled'); - $this->artisan('migrate:actions')->run(); + $this->artisan(Names::MIGRATE)->run(); $this->assertDatabaseCount($table, 2); $this->assertDatabaseCount($this->table, 10); diff --git a/tests/Commands/RefreshTest.php b/tests/Commands/RefreshTest.php index 3586449c..c51e519b 100644 --- a/tests/Commands/RefreshTest.php +++ b/tests/Commands/RefreshTest.php @@ -2,6 +2,7 @@ namespace Tests\Commands; +use DragonCode\LaravelActions\Constants\Names; use Tests\TestCase; class RefreshTest extends TestCase @@ -10,18 +11,20 @@ public function testRefreshCommand() { $this->assertDatabaseDoesntTable($this->table); - $this->artisan('migrate:actions:install')->run(); + $this->artisan(Names::INSTALL)->run(); $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 0); - $this->artisan('make:migration:action', ['name' => 'Refresh'])->run(); - $this->artisan('migrate:actions')->run(); + $this->artisan(Names::MAKE, ['name' => 'Refresh'])->run(); + $this->artisan(Names::MIGRATE)->run(); + $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 1); - $this->artisan('migrate:actions:refresh')->run(); + $this->artisan(Names::REFRESH)->run(); + $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 1); $this->assertDatabaseMigrationHas($this->table, 'refresh'); } diff --git a/tests/Commands/ResetTest.php b/tests/Commands/ResetTest.php index be9d18f1..ec2d7376 100644 --- a/tests/Commands/ResetTest.php +++ b/tests/Commands/ResetTest.php @@ -2,6 +2,7 @@ namespace Tests\Commands; +use DragonCode\LaravelActions\Constants\Names; use Tests\TestCase; class ResetTest extends TestCase @@ -10,19 +11,21 @@ public function testResetCommand() { $this->assertDatabaseDoesntTable($this->table); - $this->artisan('migrate:actions:install')->run(); + $this->artisan(Names::INSTALL)->run(); $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 0); - $this->artisan('make:migration:action', ['name' => 'Reset'])->run(); - $this->artisan('migrate:actions')->run(); + $this->artisan(Names::MAKE, ['name' => 'Reset'])->run(); + $this->artisan(Names::MIGRATE)->run(); + $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 1); $this->assertDatabaseMigrationHas($this->table, 'reset'); - $this->artisan('migrate:actions:reset')->run(); + $this->artisan(Names::RESET)->run(); + $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'reset'); } diff --git a/tests/Commands/RollbackTest.php b/tests/Commands/RollbackTest.php index 5728f857..1d65b5dd 100644 --- a/tests/Commands/RollbackTest.php +++ b/tests/Commands/RollbackTest.php @@ -2,6 +2,7 @@ namespace Tests\Commands; +use DragonCode\LaravelActions\Constants\Names; use Exception; use Illuminate\Support\Str; use Tests\TestCase; @@ -13,32 +14,36 @@ public function testRollbackCommand() { $this->assertDatabaseDoesntTable($this->table); - $this->artisan('migrate:actions:install')->run(); + $this->artisan(Names::INSTALL)->run(); $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 0); - $this->artisan('make:migration:action', ['name' => 'RollbackOne'])->run(); - $this->artisan('make:migration:action', ['name' => 'RollbackTwo'])->run(); - $this->artisan('migrate:actions')->run(); + $this->artisan(Names::MAKE, ['name' => 'RollbackOne'])->run(); + $this->artisan(Names::MAKE, ['name' => 'RollbackTwo'])->run(); + $this->artisan(Names::MIGRATE)->run(); + $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 2); $this->assertDatabaseMigrationHas($this->table, 'rollback_one'); $this->assertDatabaseMigrationHas($this->table, 'rollback_two'); $this->assertDatabaseMigrationDoesntLike($this->table, 'rollback_tree'); - $this->artisan('migrate:actions:rollback')->run(); + $this->artisan(Names::ROLLBACK)->run(); + $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 0); - $this->artisan('migrate:actions')->run(); + $this->artisan(Names::MIGRATE)->run(); + $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 2); - $this->artisan('make:migration:action', ['name' => 'RollbackTree'])->run(); - $this->artisan('migrate:actions')->run(); + $this->artisan(Names::MAKE, ['name' => 'RollbackTree'])->run(); + $this->artisan(Names::MIGRATE)->run(); + $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 3); $this->assertDatabaseMigrationHas($this->table, 'rollback_one'); @@ -52,7 +57,7 @@ public function testEnvironment() $table = 'environment'; - $this->artisan('migrate:actions:install')->run(); + $this->artisan(Names::MIGRATE)->run(); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); @@ -60,7 +65,7 @@ public function testEnvironment() $this->assertDatabaseMigrationDoesntLike($this->table, 'run_on_production'); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_on_testing'); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_on_many_environments'); - $this->artisan('migrate:actions')->run(); + $this->artisan(Names::MIGRATE)->run(); $this->assertDatabaseCount($table, 5); $this->assertDatabaseCount($this->table, 10); @@ -68,9 +73,9 @@ public function testEnvironment() $this->assertDatabaseMigrationDoesntLike($this->table, 'run_on_production'); $this->assertDatabaseMigrationHas($this->table, 'run_on_testing'); $this->assertDatabaseMigrationHas($this->table, 'run_on_many_environments'); - $this->artisan('migrate:actions')->run(); + $this->artisan(Names::MIGRATE)->run(); - $this->artisan('migrate:actions:rollback')->run(); + $this->artisan(Names::ROLLBACK)->run(); $this->assertDatabaseCount($table, 10); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_on_all'); @@ -85,18 +90,18 @@ public function testDownSuccess() $table = 'success'; - $this->artisan('migrate:actions:install')->run(); + $this->artisan(Names::MIGRATE)->run(); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_success'); - $this->artisan('migrate:actions')->run(); + $this->artisan(Names::MIGRATE)->run(); $this->assertDatabaseCount($table, 2); $this->assertDatabaseCount($this->table, 10); $this->assertDatabaseMigrationHas($this->table, 'run_success'); - $this->artisan('migrate:actions:rollback')->run(); + $this->artisan(Names::ROLLBACK)->run(); $this->assertDatabaseCount($table, 4); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_success'); @@ -108,12 +113,12 @@ public function testDownSuccessOnFailed() $table = 'success'; - $this->artisan('migrate:actions:install')->run(); + $this->artisan(Names::MIGRATE)->run(); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_success_on_failed'); - $this->artisan('migrate:actions')->run(); + $this->artisan(Names::MIGRATE)->run(); $this->assertDatabaseCount($table, 2); $this->assertDatabaseCount($this->table, 10); @@ -124,9 +129,8 @@ public function testDownSuccessOnFailed() $this->table()->insert(['migration' => '2021_12_23_165048_run_success_on_failed', 'batch' => 999]); - $this->artisan('migrate:actions:rollback')->run(); - } - catch (Throwable $e) { + $this->artisan(Names::ROLLBACK)->run(); + } catch (Throwable $e) { $this->assertInstanceOf(Exception::class, $e); $this->assertSame('Custom exception', $e->getMessage()); @@ -145,18 +149,18 @@ public function testDownFailed() $table = 'failed'; - $this->artisan('migrate:actions:install')->run(); + $this->artisan(Names::MIGRATE)->run(); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_failed'); - $this->artisan('migrate:actions')->run(); + $this->artisan(Names::MIGRATE)->run(); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 10); $this->assertDatabaseMigrationHas($this->table, 'run_failed'); - $this->artisan('migrate:actions:rollback')->run(); + $this->artisan(Names::ROLLBACK)->run(); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_failed'); @@ -168,12 +172,12 @@ public function testUpFailedOnException() $table = 'failed'; - $this->artisan('migrate:actions:install')->run(); + $this->artisan(Names::MIGRATE)->run(); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_failed_failure'); - $this->artisan('migrate:actions')->run(); + $this->artisan(Names::MIGRATE)->run(); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 10); @@ -184,9 +188,8 @@ public function testUpFailedOnException() $this->table()->insert(['migration' => '2021_12_23_184029_run_failed_failure', 'batch' => 999]); - $this->artisan('migrate:actions:rollback')->run(); - } - catch (Throwable $e) { + $this->artisan(Names::ROLLBACK)->run(); + } catch (Throwable $e) { $this->assertInstanceOf(Exception::class, $e); $this->assertSame('Custom exception', $e->getMessage()); @@ -205,21 +208,21 @@ public function testDisabledBefore() $table = 'before'; - $this->artisan('migrate:actions:install')->run(); + $this->artisan(Names::MIGRATE)->run(); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'test_before_enabled'); $this->assertDatabaseMigrationDoesntLike($this->table, 'test_before_disabled'); - $this->artisan('migrate:actions')->run(); + $this->artisan(Names::MIGRATE)->run(); $this->assertDatabaseCount($table, 2); $this->assertDatabaseCount($this->table, 10); $this->assertDatabaseMigrationHas($this->table, 'test_before_enabled'); $this->assertDatabaseMigrationHas($this->table, 'test_before_disabled'); - $this->artisan('migrate:actions')->run(); + $this->artisan(Names::MIGRATE)->run(); - $this->artisan('migrate:actions:rollback')->run(); + $this->artisan(Names::ROLLBACK)->run(); $this->assertDatabaseCount($table, 4); $this->assertDatabaseCount($this->table, 0); @@ -233,21 +236,21 @@ public function testEnabledBefore() $table = 'before'; - $this->artisan('migrate:actions:install')->run(); + $this->artisan(Names::MIGRATE)->run(); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'test_before_enabled'); $this->assertDatabaseMigrationDoesntLike($this->table, 'test_before_disabled'); - $this->artisan('migrate:actions', ['--before' => true])->run(); + $this->artisan(Names::MIGRATE, ['--before' => true])->run(); $this->assertDatabaseCount($table, 1); $this->assertDatabaseCount($this->table, 9); $this->assertDatabaseMigrationHas($this->table, 'test_before_enabled'); $this->assertDatabaseMigrationDoesntLike($this->table, 'test_before_disabled'); - $this->artisan('migrate:actions', ['--before' => true])->run(); + $this->artisan(Names::MIGRATE, ['--before' => true])->run(); - $this->artisan('migrate:actions:rollback')->run(); + $this->artisan(Names::ROLLBACK)->run(); $this->assertDatabaseCount($table, 2); $this->assertDatabaseCount($this->table, 0); diff --git a/tests/Commands/StatusTest.php b/tests/Commands/StatusTest.php index 4b788462..d92aa7a0 100644 --- a/tests/Commands/StatusTest.php +++ b/tests/Commands/StatusTest.php @@ -2,6 +2,7 @@ namespace Tests\Commands; +use DragonCode\LaravelActions\Constants\Names; use Tests\TestCase; class StatusTest extends TestCase @@ -10,21 +11,19 @@ public function testStatusCommand() { $this->assertDatabaseDoesntTable($this->table); - $this->artisan('migrate:actions:install')->run(); + $this->artisan(Names::INSTALL)->run(); $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 0); - $this->is6x() - ? $this->artisan('migrate:actions:status')->run() - : $this->artisan('migrate:actions:status')->expectsTable([], [])->run(); + $this->artisan(Names::STATUS)->expectsTable([], [])->run(); - $this->artisan('make:migration:action', ['name' => 'Status'])->run(); - $this->artisan('migrate:actions')->run(); + $this->artisan(Names::MAKE, ['name' => 'Status'])->run(); + $this->artisan(Names::MIGRATE)->run(); $this->assertDatabaseCount($this->table, 1); - $this->artisan('migrate:actions:status')->run(); + $this->artisan(Names::STATUS)->run(); $this->assertDatabaseMigrationHas($this->table, 'status'); } diff --git a/tests/Concerns/Database.php b/tests/Concerns/Database.php index 50fa5fb0..c61f5fa1 100644 --- a/tests/Concerns/Database.php +++ b/tests/Concerns/Database.php @@ -6,9 +6,12 @@ trait Database { protected $database = 'testing'; + protected $table = 'foo_actions'; + protected function setDatabase($app): void { $app['config']->set('database.default', $this->database); + $app['config']->set('database.actions', $this->table); $app['config']->set('database.connections.' . $this->database, [ 'driver' => 'sqlite', diff --git a/tests/Concerns/Files.php b/tests/Concerns/Files.php index 0b88e8c4..5c551181 100644 --- a/tests/Concerns/Files.php +++ b/tests/Concerns/Files.php @@ -55,7 +55,7 @@ protected function copyFailedTransaction(): void protected function targetDirectory(?string $path = null): string { - $dir = database_path('actions'); + $dir = $this->actionsPath('actions'); File::ensureDirectoryExists($dir); diff --git a/tests/Concerns/Laraveable.php b/tests/Concerns/Laraveable.php deleted file mode 100644 index c8e62047..00000000 --- a/tests/Concerns/Laraveable.php +++ /dev/null @@ -1,13 +0,0 @@ -set('database.actions', $this->table); - } -} diff --git a/tests/TestCase.php b/tests/TestCase.php index 7e1820de..2dd2b11b 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -3,7 +3,6 @@ namespace Tests; use DragonCode\LaravelActions\ServiceProvider; -use Illuminate\Console\View\Components\Factory as Components; use Illuminate\Database\Query\Builder; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Support\Facades\DB; @@ -11,17 +10,15 @@ use Tests\Concerns\AssertDatabase; use Tests\Concerns\Database; use Tests\Concerns\Files; -use Tests\Concerns\Laraveable; -use Tests\Concerns\Settings; +use Tests\Concerns\Path; abstract class TestCase extends BaseTestCase { use AssertDatabase; use Database; use Files; - use Laraveable; + use Path; use RefreshDatabase; - use Settings; protected function setUp(): void { @@ -40,7 +37,6 @@ protected function getEnvironmentSetUp($app) { parent::getEnvironmentSetUp($app); - $this->setTable($app); $this->setDatabase($app); } @@ -48,9 +44,4 @@ protected function table(): Builder { return DB::table($this->table); } - - protected function hasTermwind(): bool - { - return class_exists(Components::class); - } } From 78034e8e35fb0a37a8e714f8a816d1fed40070b7 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Thu, 18 Aug 2022 18:17:21 +0300 Subject: [PATCH 004/153] Refactored test concerns --- ..._175524_create_migration_actions_table.php | 30 ++++++++++++++++++ ..._180137_change_migration_actions_table.php | 28 +++++++++++++++++ ..._175524_create_migration_actions_table.php | 31 +++++++++++++++++++ ..._180137_change_migration_actions_table.php | 29 +++++++++++++++++ src/Concerns/Migrations.php | 11 +++++++ src/Concerns/Versionable.php | 13 ++++++++ src/ServiceProvider.php | 10 ++++++ tests/Concerns/AssertDatabase.php | 15 +++------ tests/Concerns/Database.php | 10 +++--- tests/Concerns/Files.php | 12 +++---- tests/TestCase.php | 2 ++ .../2020_12_07_164624_create_test_table.php | 19 ++++++++++++ ...1_01_02_022431_create_every_time_table.php | 19 ++++++++++++ ...02_15_124419_create_transactions_table.php | 19 ++++++++++++ ..._05_24_122027_create_environment_table.php | 19 ++++++++++++ ...2021_12_23_165218_create_success_table.php | 19 ++++++++++++ .../2021_12_23_184434_create_failed_table.php | 19 ++++++++++++ .../2022_08_17_150549_create_before_table.php | 19 ++++++++++++ .../2020_12_07_164624_create_test_table.php | 0 ...1_01_02_022431_create_every_time_table.php | 0 ...02_15_124419_create_transactions_table.php | 0 ..._05_24_122027_create_environment_table.php | 0 ...2021_12_23_165218_create_success_table.php | 0 .../2021_12_23_184434_create_failed_table.php | 0 .../2022_08_17_150549_create_before_table.php | 0 25 files changed, 302 insertions(+), 22 deletions(-) create mode 100644 database/migrations/anonymous/2022_08_18_175524_create_migration_actions_table.php create mode 100644 database/migrations/anonymous/2022_08_18_180137_change_migration_actions_table.php create mode 100644 database/migrations/named/2022_08_18_175524_create_migration_actions_table.php create mode 100644 database/migrations/named/2022_08_18_180137_change_migration_actions_table.php create mode 100644 src/Concerns/Migrations.php create mode 100644 src/Concerns/Versionable.php create mode 100644 tests/fixtures/migrations/anonymous/2020_12_07_164624_create_test_table.php create mode 100644 tests/fixtures/migrations/anonymous/2021_01_02_022431_create_every_time_table.php create mode 100644 tests/fixtures/migrations/anonymous/2021_02_15_124419_create_transactions_table.php create mode 100644 tests/fixtures/migrations/anonymous/2021_05_24_122027_create_environment_table.php create mode 100644 tests/fixtures/migrations/anonymous/2021_12_23_165218_create_success_table.php create mode 100644 tests/fixtures/migrations/anonymous/2021_12_23_184434_create_failed_table.php create mode 100644 tests/fixtures/migrations/anonymous/2022_08_17_150549_create_before_table.php rename tests/fixtures/migrations/{ => named}/2020_12_07_164624_create_test_table.php (100%) rename tests/fixtures/migrations/{ => named}/2021_01_02_022431_create_every_time_table.php (100%) rename tests/fixtures/migrations/{ => named}/2021_02_15_124419_create_transactions_table.php (100%) rename tests/fixtures/migrations/{ => named}/2021_05_24_122027_create_environment_table.php (100%) rename tests/fixtures/migrations/{ => named}/2021_12_23_165218_create_success_table.php (100%) rename tests/fixtures/migrations/{ => named}/2021_12_23_184434_create_failed_table.php (100%) rename tests/fixtures/migrations/{ => named}/2022_08_17_150549_create_before_table.php (100%) diff --git a/database/migrations/anonymous/2022_08_18_175524_create_migration_actions_table.php b/database/migrations/anonymous/2022_08_18_175524_create_migration_actions_table.php new file mode 100644 index 00000000..9d9b763a --- /dev/null +++ b/database/migrations/anonymous/2022_08_18_175524_create_migration_actions_table.php @@ -0,0 +1,30 @@ +table())) { + return; + } + + Schema::create($this->table(), function (Blueprint $table) { + $table->id(); + + $table->string('migration'); + + $table->integer('batch'); + }); + } + + public function down() + { + Schema::dropIfExists($this->table()); + } +}; diff --git a/database/migrations/anonymous/2022_08_18_180137_change_migration_actions_table.php b/database/migrations/anonymous/2022_08_18_180137_change_migration_actions_table.php new file mode 100644 index 00000000..ab2199de --- /dev/null +++ b/database/migrations/anonymous/2022_08_18_180137_change_migration_actions_table.php @@ -0,0 +1,28 @@ +table(), function (Blueprint $table) { + $table->renameColumn('migration', 'action'); + + $table->unsignedInteger('batch')->change(); + }); + } + + public function down() + { + Schema::table($this->table(), function (Blueprint $table) { + $table->renameColumn('action', 'migration'); + + $table->integer('batch')->change(); + }); + } +}; diff --git a/database/migrations/named/2022_08_18_175524_create_migration_actions_table.php b/database/migrations/named/2022_08_18_175524_create_migration_actions_table.php new file mode 100644 index 00000000..bfb03b29 --- /dev/null +++ b/database/migrations/named/2022_08_18_175524_create_migration_actions_table.php @@ -0,0 +1,31 @@ +table())) { + return; + } + + Schema::create($this->table(), function (Blueprint $table) { + $table->id(); + + $table->string('migration'); + + $table->integer('batch'); + }); + } + + public function down() + { + Schema::dropIfExists($this->table()); + } +} diff --git a/database/migrations/named/2022_08_18_180137_change_migration_actions_table.php b/database/migrations/named/2022_08_18_180137_change_migration_actions_table.php new file mode 100644 index 00000000..a6edd8d6 --- /dev/null +++ b/database/migrations/named/2022_08_18_180137_change_migration_actions_table.php @@ -0,0 +1,29 @@ +table(), function (Blueprint $table) { + $table->renameColumn('migration', 'action'); + + $table->unsignedInteger('batch')->change(); + }); + } + + public function down() + { + Schema::table($this->table(), function (Blueprint $table) { + $table->renameColumn('action', 'migration'); + + $table->integer('batch')->change(); + }); + } +} diff --git a/src/Concerns/Migrations.php b/src/Concerns/Migrations.php new file mode 100644 index 00000000..ec71e6f8 --- /dev/null +++ b/src/Concerns/Migrations.php @@ -0,0 +1,11 @@ +app->runningInConsole()) { $this->registerCommands(); $this->registerAbout(); + $this->registerMigrations(); } } @@ -31,4 +34,11 @@ protected function registerCommands(): void Console\Status::class, ]); } + + protected function registerMigrations(): void + { + $this->allowAnonymousMigrations() + ? $this->loadMigrationsFrom(__DIR__ . '/../database/migrations/anonymous') + : $this->loadMigrationsFrom(__DIR__ . '/../database/migrations/named'); + } } diff --git a/tests/Concerns/AssertDatabase.php b/tests/Concerns/AssertDatabase.php index 7d21b25d..a3a3780e 100644 --- a/tests/Concerns/AssertDatabase.php +++ b/tests/Concerns/AssertDatabase.php @@ -8,13 +8,6 @@ /** @mixin \Tests\TestCase */ trait AssertDatabase { - protected function assertDatabaseCount($table, int $count, $connection = null): void - { - $actual = DB::connection($connection)->table($table)->count(); - - $this->assertEquals($count, $actual); - } - protected function assertDatabaseHasTable(string $table): void { $this->assertTrue( @@ -31,14 +24,14 @@ protected function assertDatabaseDoesntTable(string $table): void protected function assertDatabaseMigrationHas(string $table, $value, $connection = null): void { - $this->assertDatabaseHasLike($table, 'migration', $value, $connection); + $this->assertDatabaseHasLike($table, 'action', $value, $connection); } protected function assertDatabaseHasLike(string $table, string $column, $value, $connection = null): void { $exists = DB::connection($connection) ->table($table) - ->whereRaw("{$column} like '%$value%'") + ->whereRaw("$column like '%$value%'") ->exists(); $this->assertTrue($exists); @@ -46,14 +39,14 @@ protected function assertDatabaseHasLike(string $table, string $column, $value, protected function assertDatabaseMigrationDoesntLike(string $table, $value, $connection = null): void { - $this->assertDatabaseDoesntLike($table, 'migration', $value, $connection); + $this->assertDatabaseDoesntLike($table, 'action', $value, $connection); } protected function assertDatabaseDoesntLike(string $table, string $column, $value, $connection = null): void { $exists = DB::connection($connection) ->table($table) - ->whereRaw("{$column} like '%$value%'") + ->whereRaw("$column like '%$value%'") ->doesntExist(); $this->assertTrue($exists); diff --git a/tests/Concerns/Database.php b/tests/Concerns/Database.php index c61f5fa1..877fba88 100644 --- a/tests/Concerns/Database.php +++ b/tests/Concerns/Database.php @@ -4,9 +4,9 @@ trait Database { - protected $database = 'testing'; + protected string $database = 'testing'; - protected $table = 'foo_actions'; + protected string $table = 'foo_actions'; protected function setDatabase($app): void { @@ -30,8 +30,8 @@ protected function freshDatabase(): void protected function loadMigrations(): void { - $this->loadMigrationsFrom( - __DIR__ . '/../fixtures/migrations' - ); + $this->allowAnonymousMigrations() + ? $this->loadMigrationsFrom(__DIR__ . '/../fixtures/migrations/anonymous') + : $this->loadMigrationsFrom(__DIR__ . '/../fixtures/migrations/named'); } } diff --git a/tests/Concerns/Files.php b/tests/Concerns/Files.php index 5c551181..4d893c92 100644 --- a/tests/Concerns/Files.php +++ b/tests/Concerns/Files.php @@ -16,7 +16,7 @@ protected function freshFiles(): void protected function copyFiles(): void { File::copyDirectory( - __DIR__ . '/../fixtures/app/anonymous/actions', + __DIR__ . '/../fixtures/app/actions', $this->targetDirectory() ); } @@ -24,7 +24,7 @@ protected function copyFiles(): void protected function copySuccessFailureMethod() { File::copy( - __DIR__ . '/../fixtures/app/anonymous/actions_failed/2021_12_23_165048_run_success_on_failed.php', + __DIR__ . '/../fixtures/app/actions_failed/2021_12_23_165048_run_success_on_failed.php', $this->targetDirectory('2021_12_23_165048_run_success_on_failed.php') ); } @@ -32,7 +32,7 @@ protected function copySuccessFailureMethod() protected function copyFailedMethod() { File::copy( - __DIR__ . '/../fixtures/app/anonymous/actions_failed/2021_12_23_184029_run_failed_failure.php', + __DIR__ . '/../fixtures/app/actions_failed/2021_12_23_184029_run_failed_failure.php', $this->targetDirectory('2021_12_23_184029_run_failed_failure.php') ); } @@ -40,7 +40,7 @@ protected function copyFailedMethod() protected function copySuccessTransaction(): void { File::copy( - __DIR__ . '/../fixtures/app/anonymous/stubs/2021_02_15_124237_test_success_transactions.stub', + __DIR__ . '/../fixtures/app/stubs/2021_02_15_124237_test_success_transactions.stub', $this->targetDirectory('2021_02_15_124237_test_success_transactions.php') ); } @@ -48,14 +48,14 @@ protected function copySuccessTransaction(): void protected function copyFailedTransaction(): void { File::copy( - __DIR__ . '/../fixtures/app/anonymous/stubs/2021_02_15_124852_test_failed_transactions.stub', + __DIR__ . '/../fixtures/app/stubs/2021_02_15_124852_test_failed_transactions.stub', $this->targetDirectory('2021_02_15_124852_test_failed_transactions.php') ); } protected function targetDirectory(?string $path = null): string { - $dir = $this->actionsPath('actions'); + $dir = $this->actionsPath(); File::ensureDirectoryExists($dir); diff --git a/tests/TestCase.php b/tests/TestCase.php index 2dd2b11b..4f49add0 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -2,6 +2,7 @@ namespace Tests; +use DragonCode\LaravelActions\Concerns\Versionable; use DragonCode\LaravelActions\ServiceProvider; use Illuminate\Database\Query\Builder; use Illuminate\Foundation\Testing\RefreshDatabase; @@ -19,6 +20,7 @@ abstract class TestCase extends BaseTestCase use Files; use Path; use RefreshDatabase; + use Versionable; protected function setUp(): void { diff --git a/tests/fixtures/migrations/anonymous/2020_12_07_164624_create_test_table.php b/tests/fixtures/migrations/anonymous/2020_12_07_164624_create_test_table.php new file mode 100644 index 00000000..46e2de50 --- /dev/null +++ b/tests/fixtures/migrations/anonymous/2020_12_07_164624_create_test_table.php @@ -0,0 +1,19 @@ +uuid('value')->unique(); + }); + } + + public function down() + { + Schema::dropIfExists('test'); + } +}; diff --git a/tests/fixtures/migrations/anonymous/2021_01_02_022431_create_every_time_table.php b/tests/fixtures/migrations/anonymous/2021_01_02_022431_create_every_time_table.php new file mode 100644 index 00000000..426eb55c --- /dev/null +++ b/tests/fixtures/migrations/anonymous/2021_01_02_022431_create_every_time_table.php @@ -0,0 +1,19 @@ +uuid('value'); + }); + } + + public function down() + { + Schema::dropIfExists('every_time'); + } +}; diff --git a/tests/fixtures/migrations/anonymous/2021_02_15_124419_create_transactions_table.php b/tests/fixtures/migrations/anonymous/2021_02_15_124419_create_transactions_table.php new file mode 100644 index 00000000..cb8920cc --- /dev/null +++ b/tests/fixtures/migrations/anonymous/2021_02_15_124419_create_transactions_table.php @@ -0,0 +1,19 @@ +uuid('value'); + }); + } + + public function down() + { + Schema::dropIfExists('transactions'); + } +}; diff --git a/tests/fixtures/migrations/anonymous/2021_05_24_122027_create_environment_table.php b/tests/fixtures/migrations/anonymous/2021_05_24_122027_create_environment_table.php new file mode 100644 index 00000000..c89fa4a4 --- /dev/null +++ b/tests/fixtures/migrations/anonymous/2021_05_24_122027_create_environment_table.php @@ -0,0 +1,19 @@ +uuid('value'); + }); + } + + public function down() + { + Schema::dropIfExists('environment'); + } +}; diff --git a/tests/fixtures/migrations/anonymous/2021_12_23_165218_create_success_table.php b/tests/fixtures/migrations/anonymous/2021_12_23_165218_create_success_table.php new file mode 100644 index 00000000..666e481c --- /dev/null +++ b/tests/fixtures/migrations/anonymous/2021_12_23_165218_create_success_table.php @@ -0,0 +1,19 @@ +string('value'); + }); + } + + public function down() + { + Schema::dropIfExists('success'); + } +}; diff --git a/tests/fixtures/migrations/anonymous/2021_12_23_184434_create_failed_table.php b/tests/fixtures/migrations/anonymous/2021_12_23_184434_create_failed_table.php new file mode 100644 index 00000000..a37c5f7e --- /dev/null +++ b/tests/fixtures/migrations/anonymous/2021_12_23_184434_create_failed_table.php @@ -0,0 +1,19 @@ +string('value'); + }); + } + + public function down() + { + Schema::dropIfExists('failed'); + } +}; diff --git a/tests/fixtures/migrations/anonymous/2022_08_17_150549_create_before_table.php b/tests/fixtures/migrations/anonymous/2022_08_17_150549_create_before_table.php new file mode 100644 index 00000000..7f724bd4 --- /dev/null +++ b/tests/fixtures/migrations/anonymous/2022_08_17_150549_create_before_table.php @@ -0,0 +1,19 @@ +string('value'); + }); + } + + public function down() + { + Schema::dropIfExists('before'); + } +}; diff --git a/tests/fixtures/migrations/2020_12_07_164624_create_test_table.php b/tests/fixtures/migrations/named/2020_12_07_164624_create_test_table.php similarity index 100% rename from tests/fixtures/migrations/2020_12_07_164624_create_test_table.php rename to tests/fixtures/migrations/named/2020_12_07_164624_create_test_table.php diff --git a/tests/fixtures/migrations/2021_01_02_022431_create_every_time_table.php b/tests/fixtures/migrations/named/2021_01_02_022431_create_every_time_table.php similarity index 100% rename from tests/fixtures/migrations/2021_01_02_022431_create_every_time_table.php rename to tests/fixtures/migrations/named/2021_01_02_022431_create_every_time_table.php diff --git a/tests/fixtures/migrations/2021_02_15_124419_create_transactions_table.php b/tests/fixtures/migrations/named/2021_02_15_124419_create_transactions_table.php similarity index 100% rename from tests/fixtures/migrations/2021_02_15_124419_create_transactions_table.php rename to tests/fixtures/migrations/named/2021_02_15_124419_create_transactions_table.php diff --git a/tests/fixtures/migrations/2021_05_24_122027_create_environment_table.php b/tests/fixtures/migrations/named/2021_05_24_122027_create_environment_table.php similarity index 100% rename from tests/fixtures/migrations/2021_05_24_122027_create_environment_table.php rename to tests/fixtures/migrations/named/2021_05_24_122027_create_environment_table.php diff --git a/tests/fixtures/migrations/2021_12_23_165218_create_success_table.php b/tests/fixtures/migrations/named/2021_12_23_165218_create_success_table.php similarity index 100% rename from tests/fixtures/migrations/2021_12_23_165218_create_success_table.php rename to tests/fixtures/migrations/named/2021_12_23_165218_create_success_table.php diff --git a/tests/fixtures/migrations/2021_12_23_184434_create_failed_table.php b/tests/fixtures/migrations/named/2021_12_23_184434_create_failed_table.php similarity index 100% rename from tests/fixtures/migrations/2021_12_23_184434_create_failed_table.php rename to tests/fixtures/migrations/named/2021_12_23_184434_create_failed_table.php diff --git a/tests/fixtures/migrations/2022_08_17_150549_create_before_table.php b/tests/fixtures/migrations/named/2022_08_17_150549_create_before_table.php similarity index 100% rename from tests/fixtures/migrations/2022_08_17_150549_create_before_table.php rename to tests/fixtures/migrations/named/2022_08_17_150549_create_before_table.php From 603ba199bfd3e96d8603eb56c91965b64bd04434 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Thu, 18 Aug 2022 18:18:14 +0300 Subject: [PATCH 005/153] Renamed actions namespace --- resources/stubs/action.stub | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/stubs/action.stub b/resources/stubs/action.stub index 09847ca5..ddbc46bc 100644 --- a/resources/stubs/action.stub +++ b/resources/stubs/action.stub @@ -1,6 +1,6 @@ Date: Thu, 18 Aug 2022 18:19:59 +0300 Subject: [PATCH 006/153] Refactored GitTest --- tests/Services/GitTest.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/Services/GitTest.php b/tests/Services/GitTest.php index cb87d6bb..a1247d16 100644 --- a/tests/Services/GitTest.php +++ b/tests/Services/GitTest.php @@ -4,20 +4,25 @@ namespace Tests\Services; -use DragonCode\LaravelActions\Facades\Git; +use DragonCode\LaravelActions\Support\Git; use Tests\TestCase; class GitTest extends TestCase { public function testCurrentBranchNull() { - $this->assertNull(Git::currentBranch(__DIR__)); + $this->assertNull($this->git()->currentBranch(__DIR__)); } public function testCurrentBranch() { - $branch = Git::currentBranch(__DIR__ . '/../../.git'); + $branch = $this->git()->currentBranch(__DIR__ . '/../../.git'); $this->assertIsString($branch); } + + protected function git(): Git + { + return new Git(); + } } From 68519b1f0ccd17cdcb2ee56a83b39955ed33bd51 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Thu, 18 Aug 2022 18:24:54 +0300 Subject: [PATCH 007/153] Refactored migrations --- ..._175524_create_migration_actions_table.php | 29 +--------------- ..._180137_change_migration_actions_table.php | 27 +-------------- .../base/BaseChangeMigrationActionsTable.php | 31 +++++++++++++++++ .../base/BaseCreateMigrationActionsTable.php | 33 +++++++++++++++++++ ..._175524_create_migration_actions_table.php | 30 +---------------- ..._180137_change_migration_actions_table.php | 28 +--------------- 6 files changed, 68 insertions(+), 110 deletions(-) create mode 100644 database/migrations/base/BaseChangeMigrationActionsTable.php create mode 100644 database/migrations/base/BaseCreateMigrationActionsTable.php diff --git a/database/migrations/anonymous/2022_08_18_175524_create_migration_actions_table.php b/database/migrations/anonymous/2022_08_18_175524_create_migration_actions_table.php index 9d9b763a..64db0892 100644 --- a/database/migrations/anonymous/2022_08_18_175524_create_migration_actions_table.php +++ b/database/migrations/anonymous/2022_08_18_175524_create_migration_actions_table.php @@ -1,30 +1,3 @@ table())) { - return; - } - - Schema::create($this->table(), function (Blueprint $table) { - $table->id(); - - $table->string('migration'); - - $table->integer('batch'); - }); - } - - public function down() - { - Schema::dropIfExists($this->table()); - } -}; +return new class extends BaseCreateMigrationActionsTable { }; diff --git a/database/migrations/anonymous/2022_08_18_180137_change_migration_actions_table.php b/database/migrations/anonymous/2022_08_18_180137_change_migration_actions_table.php index ab2199de..a0305742 100644 --- a/database/migrations/anonymous/2022_08_18_180137_change_migration_actions_table.php +++ b/database/migrations/anonymous/2022_08_18_180137_change_migration_actions_table.php @@ -1,28 +1,3 @@ table(), function (Blueprint $table) { - $table->renameColumn('migration', 'action'); - - $table->unsignedInteger('batch')->change(); - }); - } - - public function down() - { - Schema::table($this->table(), function (Blueprint $table) { - $table->renameColumn('action', 'migration'); - - $table->integer('batch')->change(); - }); - } -}; +return new class extends BaseChangeMigrationActionsTable { }; diff --git a/database/migrations/base/BaseChangeMigrationActionsTable.php b/database/migrations/base/BaseChangeMigrationActionsTable.php new file mode 100644 index 00000000..a47f84be --- /dev/null +++ b/database/migrations/base/BaseChangeMigrationActionsTable.php @@ -0,0 +1,31 @@ +table(), function (Blueprint $table) { + $table->renameColumn('migration', 'action'); + + $table->unsignedInteger('batch')->change(); + }); + } + + public function down() + { + Schema::table($this->table(), function (Blueprint $table) { + $table->renameColumn('action', 'migration'); + + $table->integer('batch')->change(); + }); + } +} + +; diff --git a/database/migrations/base/BaseCreateMigrationActionsTable.php b/database/migrations/base/BaseCreateMigrationActionsTable.php new file mode 100644 index 00000000..cb78d6b2 --- /dev/null +++ b/database/migrations/base/BaseCreateMigrationActionsTable.php @@ -0,0 +1,33 @@ +table())) { + return; + } + + Schema::create($this->table(), function (Blueprint $table) { + $table->id(); + + $table->string('migration'); + + $table->integer('batch'); + }); + } + + public function down() + { + Schema::dropIfExists($this->table()); + } +} + +; diff --git a/database/migrations/named/2022_08_18_175524_create_migration_actions_table.php b/database/migrations/named/2022_08_18_175524_create_migration_actions_table.php index bfb03b29..84147d85 100644 --- a/database/migrations/named/2022_08_18_175524_create_migration_actions_table.php +++ b/database/migrations/named/2022_08_18_175524_create_migration_actions_table.php @@ -1,31 +1,3 @@ table())) { - return; - } - - Schema::create($this->table(), function (Blueprint $table) { - $table->id(); - - $table->string('migration'); - - $table->integer('batch'); - }); - } - - public function down() - { - Schema::dropIfExists($this->table()); - } -} +class CreateMigrationActionsTable extends BaseCreateMigrationActionsTable { } diff --git a/database/migrations/named/2022_08_18_180137_change_migration_actions_table.php b/database/migrations/named/2022_08_18_180137_change_migration_actions_table.php index a6edd8d6..55c98edf 100644 --- a/database/migrations/named/2022_08_18_180137_change_migration_actions_table.php +++ b/database/migrations/named/2022_08_18_180137_change_migration_actions_table.php @@ -1,29 +1,3 @@ table(), function (Blueprint $table) { - $table->renameColumn('migration', 'action'); - - $table->unsignedInteger('batch')->change(); - }); - } - - public function down() - { - Schema::table($this->table(), function (Blueprint $table) { - $table->renameColumn('action', 'migration'); - - $table->integer('batch')->change(); - }); - } -} +class ChangeMigrationActionsTable extends BaseChangeMigrationActionsTable { } From ae23234143e259b32af33fd94b2ff0f396a38382 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Thu, 18 Aug 2022 18:30:26 +0300 Subject: [PATCH 008/153] Updated About command --- src/Concerns/About.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Concerns/About.php b/src/Concerns/About.php index 99ee8dad..fc7b571f 100644 --- a/src/Concerns/About.php +++ b/src/Concerns/About.php @@ -4,6 +4,7 @@ namespace DragonCode\LaravelActions\Concerns; +use Composer\InstalledVersions; use Illuminate\Foundation\Console\AboutCommand; trait About @@ -11,9 +12,14 @@ trait About protected function registerAbout(): void { if (class_exists(AboutCommand::class)) { - AboutCommand::add('Laravel Migration Actions', fn () => [ - 'Version' => '3.0.0', + AboutCommand::add('Migration Actions', fn () => [ + 'Version' => $this->getPackageVersion(), ]); } } + + protected function getPackageVersion(): string + { + return InstalledVersions::getPrettyVersion('dragon-code/laravel-migration-actions'); + } } From f9742ff40d73c78c8ebb7ef3654fec7fa5ed9601 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Thu, 18 Aug 2022 18:42:02 +0300 Subject: [PATCH 009/153] Refactored concerns --- composer.json | 1 + .../base/BaseChangeMigrationActionsTable.php | 4 ++-- .../base/BaseCreateMigrationActionsTable.php | 4 ++-- src/Concerns/Argumentable.php | 11 +++++------ src/Concerns/Artisan.php | 4 ++-- src/Concerns/Database.php | 14 ++------------ src/Concerns/Migrations.php | 11 ----------- src/Concerns/Optionable.php | 19 +++++++++++++++++-- src/Concerns/Path.php | 11 +++++++++++ src/Console/Command.php | 2 ++ src/Constants/Options.php | 2 ++ src/Support/Git.php | 3 +++ tests/Commands/MakeTest.php | 4 ++-- tests/Concerns/Files.php | 2 +- tests/TestCase.php | 2 +- 15 files changed, 53 insertions(+), 41 deletions(-) delete mode 100644 src/Concerns/Migrations.php create mode 100644 src/Concerns/Path.php diff --git a/composer.json b/composer.json index b9b158bd..bddb6c25 100644 --- a/composer.json +++ b/composer.json @@ -28,6 +28,7 @@ "php": "^7.3 || ^8.0", "dragon-code/contracts": "^2.15", "dragon-code/laravel-support": "^3.3", + "dragon-code/support": "^6.3", "illuminate/console": "^6.0 || ^7.0 || ^8.0 || ^9.0", "illuminate/database": "^6.0 || ^7.0 || ^8.0 || ^9.0", "illuminate/support": "^6.0 || ^7.0 || ^8.0 || ^9.0", diff --git a/database/migrations/base/BaseChangeMigrationActionsTable.php b/database/migrations/base/BaseChangeMigrationActionsTable.php index a47f84be..68a31f7b 100644 --- a/database/migrations/base/BaseChangeMigrationActionsTable.php +++ b/database/migrations/base/BaseChangeMigrationActionsTable.php @@ -1,13 +1,13 @@ argument('name')) { - return trim($name); + if ($name = $this->argument('name')) { + return trim((string) $name); } return $this->makeName(); @@ -30,6 +29,6 @@ protected function getAutoPrefix(): string protected function getGitBranchName(): ?string { - return Git::currentBranch(base_path('.git')); + return Git::make()->currentBranch(base_path('.git')); } } diff --git a/src/Concerns/Artisan.php b/src/Concerns/Artisan.php index 5cf56103..d25af9c4 100644 --- a/src/Concerns/Artisan.php +++ b/src/Concerns/Artisan.php @@ -4,7 +4,7 @@ namespace DragonCode\LaravelActions\Concerns; -use Illuminate\Support\Facades\Artisan as ArtisanSupport; +use Illuminate\Support\Facades\Artisan as Command; trait Artisan { @@ -18,6 +18,6 @@ trait Artisan */ protected function artisan(string $command, array $parameters = []): void { - ArtisanSupport::call($command, $parameters); + Command::call($command, $parameters); } } diff --git a/src/Concerns/Database.php b/src/Concerns/Database.php index b8d8acae..b6e76bc1 100644 --- a/src/Concerns/Database.php +++ b/src/Concerns/Database.php @@ -2,20 +2,10 @@ namespace DragonCode\LaravelActions\Concerns; -/** @mixin \Illuminate\Database\Console\Migrations\BaseCommand */ trait Database { - protected function getMigrationPath(): string + protected function table(): string { - return $this->laravel->databasePath('actions'); - } - - protected function getMigrationPaths(): array - { - if ($paths = $this->optionPath()) { - return $paths; - } - - return [$this->getMigrationPath()]; + return config('database.actions', 'migration_actions'); } } diff --git a/src/Concerns/Migrations.php b/src/Concerns/Migrations.php deleted file mode 100644 index ec71e6f8..00000000 --- a/src/Concerns/Migrations.php +++ /dev/null @@ -1,11 +0,0 @@ -hasOption(Options::FORCE) && $this->option(Options::FORCE); + return $this->optionHas(Options::FORCE); } protected function optionBefore(): bool @@ -40,7 +40,7 @@ protected function optionPath(): ?array return $path; } - $filename = $this->getMigrationPath() . DIRECTORY_SEPARATOR . $path; + $filename = $this->getActionsPath($path); if (is_dir($filename) || file_exists($filename)) { return $filename; @@ -52,4 +52,19 @@ protected function optionPath(): ?array return null; } + + /** + * Determine if the given path(s) are pre-resolved "real" paths. + * + * @return bool + */ + protected function usingRealPath(): bool + { + return $this->optionHas(Options::REALPATH); + } + + protected function optionHas(string $key): bool + { + return $this->hasOption($key) && $this->option($key); + } } diff --git a/src/Concerns/Path.php b/src/Concerns/Path.php new file mode 100644 index 00000000..f37ad215 --- /dev/null +++ b/src/Concerns/Path.php @@ -0,0 +1,11 @@ +getGitPath($path)) { diff --git a/tests/Commands/MakeTest.php b/tests/Commands/MakeTest.php index 8b1c4bee..78e49e9b 100644 --- a/tests/Commands/MakeTest.php +++ b/tests/Commands/MakeTest.php @@ -11,7 +11,7 @@ public function testMakingFiles() { $name = 'MakeExample'; - $path = $this->actionsPath(date('Y_m_d_His') . '_make_example.php'); + $path = $this->getActionsPath(date('Y_m_d_His') . '_make_example.php'); $this->assertFileDoesNotExist($path); @@ -29,7 +29,7 @@ public function testMakingFiles() public function testAutoName() { - $path = $this->actionsPath(date('Y_m_d_His') . '_auto.php'); + $path = $this->getActionsPath(date('Y_m_d_His') . '_auto.php'); $this->assertFileDoesNotExist($path); diff --git a/tests/Concerns/Files.php b/tests/Concerns/Files.php index 4d893c92..1f14ede6 100644 --- a/tests/Concerns/Files.php +++ b/tests/Concerns/Files.php @@ -55,7 +55,7 @@ protected function copyFailedTransaction(): void protected function targetDirectory(?string $path = null): string { - $dir = $this->actionsPath(); + $dir = $this->getActionsPath(); File::ensureDirectoryExists($dir); diff --git a/tests/TestCase.php b/tests/TestCase.php index 4f49add0..8182fed5 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -2,6 +2,7 @@ namespace Tests; +use DragonCode\LaravelActions\Concerns\Path; use DragonCode\LaravelActions\Concerns\Versionable; use DragonCode\LaravelActions\ServiceProvider; use Illuminate\Database\Query\Builder; @@ -11,7 +12,6 @@ use Tests\Concerns\AssertDatabase; use Tests\Concerns\Database; use Tests\Concerns\Files; -use Tests\Concerns\Path; abstract class TestCase extends BaseTestCase { From a99837c505c7d4b8de961ee1d367f490499bb53a Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Thu, 18 Aug 2022 20:01:42 +0300 Subject: [PATCH 010/153] Update About command --- src/Concerns/About.php | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/Concerns/About.php b/src/Concerns/About.php index fc7b571f..e6a754f6 100644 --- a/src/Concerns/About.php +++ b/src/Concerns/About.php @@ -5,6 +5,8 @@ namespace DragonCode\LaravelActions\Concerns; use Composer\InstalledVersions; +use DragonCode\Support\Facades\Helpers\Arr; +use DragonCode\Support\Facades\Helpers\Str; use Illuminate\Foundation\Console\AboutCommand; trait About @@ -12,14 +14,29 @@ trait About protected function registerAbout(): void { if (class_exists(AboutCommand::class)) { - AboutCommand::add('Migration Actions', fn () => [ + AboutCommand::add($this->getPackageName(), fn () => [ 'Version' => $this->getPackageVersion(), ]); } } + protected function getPackageName(): string + { + return Str::of($this->getPackageValue('name')) + ->after('/') + ->snake() + ->replace('_', ' ') + ->title() + ->toString(); + } + protected function getPackageVersion(): string { - return InstalledVersions::getPrettyVersion('dragon-code/laravel-migration-actions'); + return $this->getPackageValue('pretty_version'); + } + + protected function getPackageValue(string $key): string + { + return Arr::get(InstalledVersions::getRootPackage(), $key); } } From 04d886a92434733d60bcc176166238a6f167de6f Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Thu, 18 Aug 2022 20:38:30 +0300 Subject: [PATCH 011/153] WIP WIP WIP --- .github/workflows/laravel-7.yml | 2 +- .github/workflows/laravel-8.yml | 2 +- composer.json | 20 +++++++++------- src/Concerns/Database.php | 2 +- src/Concerns/Optionable.php | 13 ++++++++++ src/Console/Command.php | 13 ++++++++-- src/Console/Fresh.php | 32 +++---------------------- src/Console/Install.php | 22 ++++------------- src/Processors/Creator.php | 42 +++++++++++++++++++++++++++++++++ src/Processors/Fresh.php | 36 ++++++++++++++++++++++++++++ src/Processors/Installer.php | 13 ++++++++++ src/Processors/Processor.php | 24 +++++++++++++++++++ src/Values/Options.php | 22 +++++++++++++++++ 13 files changed, 183 insertions(+), 60 deletions(-) create mode 100644 src/Processors/Creator.php create mode 100644 src/Processors/Fresh.php create mode 100644 src/Processors/Installer.php create mode 100644 src/Processors/Processor.php create mode 100644 src/Values/Options.php diff --git a/.github/workflows/laravel-7.yml b/.github/workflows/laravel-7.yml index 70765fb9..14a43437 100644 --- a/.github/workflows/laravel-7.yml +++ b/.github/workflows/laravel-7.yml @@ -8,7 +8,7 @@ jobs: strategy: fail-fast: true matrix: - php: [ "7.4", "8.0" ] + php: [ "8.0" ] laravel: [ "7.0" ] name: PHP ${{ matrix.php }} diff --git a/.github/workflows/laravel-8.yml b/.github/workflows/laravel-8.yml index d024d5dc..5fce019c 100644 --- a/.github/workflows/laravel-8.yml +++ b/.github/workflows/laravel-8.yml @@ -8,7 +8,7 @@ jobs: strategy: fail-fast: true matrix: - php: [ "7.4", "8.0", "8.1" ] + php: [ "8.0", "8.1" ] laravel: [ "8.0" ] name: PHP ${{ matrix.php }} diff --git a/composer.json b/composer.json index bddb6c25..3513d623 100644 --- a/composer.json +++ b/composer.json @@ -16,8 +16,7 @@ "authors": [ { "name": "Andrey Helldar", - "email": "helldar@dragon-code.pro", - "homepage": "https://github.com/andrey-helldar" + "email": "helldar@dragon-code.pro" } ], "support": { @@ -25,19 +24,22 @@ "source": "https://github.com/TheDragonCode/laravel-migration-actions" }, "require": { - "php": "^7.3 || ^8.0", + "php": "^8.0", + "composer-runtime-api": "^2.2", "dragon-code/contracts": "^2.15", "dragon-code/laravel-support": "^3.3", + "dragon-code/simple-dto": "^2.3", "dragon-code/support": "^6.3", - "illuminate/console": "^6.0 || ^7.0 || ^8.0 || ^9.0", - "illuminate/database": "^6.0 || ^7.0 || ^8.0 || ^9.0", - "illuminate/support": "^6.0 || ^7.0 || ^8.0 || ^9.0", - "symfony/console": "^4.3 || ^5.0 || ^6.0" + "illuminate/container": "^7.0 || ^8.0 || ^9.0", + "illuminate/console": "^7.0 || ^8.0 || ^9.0", + "illuminate/database": "^7.0 || ^8.0 || ^9.0", + "illuminate/support": "^7.0 || ^8.0 || ^9.0", + "symfony/console": "^5.0 || ^6.0" }, "require-dev": { "mockery/mockery": "^1.3.1", - "orchestra/testbench": "^4.0 || ^5.0 || ^6.0 || ^7.0", - "phpunit/phpunit": "^8.0 || ^9.0", + "orchestra/testbench": "^5.0 || ^6.0 || ^7.0", + "phpunit/phpunit": "^9.0", "ramsey/uuid": "^3.7 || ^4.0" }, "conflict": { diff --git a/src/Concerns/Database.php b/src/Concerns/Database.php index b6e76bc1..c05bee9c 100644 --- a/src/Concerns/Database.php +++ b/src/Concerns/Database.php @@ -4,7 +4,7 @@ trait Database { - protected function table(): string + protected function getTableName(): string { return config('database.actions', 'migration_actions'); } diff --git a/src/Concerns/Optionable.php b/src/Concerns/Optionable.php index d4d6549a..a24aee67 100644 --- a/src/Concerns/Optionable.php +++ b/src/Concerns/Optionable.php @@ -3,6 +3,7 @@ namespace DragonCode\LaravelActions\Concerns; use DragonCode\LaravelActions\Constants\Options; +use DragonCode\LaravelActions\Values\Options as OptionsDto; use Illuminate\Support\Str; /** @mixin \Illuminate\Console\Command */ @@ -67,4 +68,16 @@ protected function optionHas(string $key): bool { return $this->hasOption($key) && $this->option($key); } + + protected function optionDto(): OptionsDto + { + return OptionsDto::make([ + 'before' => $this->optionBefore(), + 'database' => $this->optionDatabase(), + 'force' => $this->optionForce(), + 'path' => $this->optionPath(), + 'realpath' => $this->usingRealPath(), + 'step' => $this->optionStep(), + ]); + } } diff --git a/src/Console/Command.php b/src/Console/Command.php index a22fa495..d76d2d13 100644 --- a/src/Console/Command.php +++ b/src/Console/Command.php @@ -8,7 +8,9 @@ use DragonCode\LaravelActions\Concerns\Optionable; use DragonCode\LaravelActions\Concerns\Path; use DragonCode\LaravelActions\Constants\Options; +use DragonCode\LaravelActions\Processors\Processor; use Illuminate\Console\Command as BaseCommand; +use Illuminate\Container\Container; use Symfony\Component\Console\Input\InputOption; abstract class Command extends BaseCommand @@ -17,7 +19,7 @@ abstract class Command extends BaseCommand use Infoable; use Path; - abstract protected function process(): void; + protected Processor|string $processor; public function handle(): int { @@ -25,11 +27,18 @@ public function handle(): int return 1; } - $this->process(); + $this->resolveProcessor()->handle(); return 0; } + protected function resolveProcessor(): Processor + { + return Container::getInstance()->make($this->processor, [ + 'options' => $this->optionDto(), + ]); + } + protected function confirmToProceed(): bool { if ($this->optionForce()) { diff --git a/src/Console/Fresh.php b/src/Console/Fresh.php index 29ccbdfc..4ee66fd0 100644 --- a/src/Console/Fresh.php +++ b/src/Console/Fresh.php @@ -4,41 +4,15 @@ namespace DragonCode\LaravelActions\Console; -use DragonCode\LaravelActions\Concerns\Optionable; use DragonCode\LaravelActions\Constants\Names; -use DragonCode\LaravelActions\Constants\Options; -use Illuminate\Support\Facades\Schema; +use DragonCode\LaravelActions\Processors\Fresh as FreshProcessor; +use DragonCode\LaravelActions\Processors\Processor; class Fresh extends Command { - use Optionable; - protected $name = Names::FRESH; protected $description = 'Drop and re-run all actions'; - public function process(): void - { - $this->drop(); - $this->migrate(); - } - - protected function drop(): void - { - Schema::dropIfExists($this->getTableName()); - } - - protected function migrate(): void - { - $this->call(Names::MIGRATE, - array_filter([ - '--' . Options::DATABASE => $this->optionDatabase(), - '--' . Options::FORCE => true, - ])); - } - - protected function getTableName(): string - { - return config('database.actions'); - } + protected Processor|string $processor = FreshProcessor::class; } diff --git a/src/Console/Install.php b/src/Console/Install.php index 9bf5869f..d17ce78a 100644 --- a/src/Console/Install.php +++ b/src/Console/Install.php @@ -2,27 +2,15 @@ namespace DragonCode\LaravelActions\Console; -use DragonCode\LaravelActions\Concerns\Database; -use DragonCode\LaravelActions\Concerns\Infoable; use DragonCode\LaravelActions\Constants\Names; -use Illuminate\Database\Console\Migrations\InstallCommand as BaseCommand; +use DragonCode\LaravelActions\Processors\Installer; +use DragonCode\LaravelActions\Processors\Processor; -class Install extends BaseCommand +class Install extends Command { - use Database; - use Infoable; - - /** - * The console command name. - * - * @var string - */ protected $name = Names::INSTALL; - /** - * The console command description. - * - * @var string - */ protected $description = 'Create the actions repository'; + + protected Processor|string $processor = Installer::class; } diff --git a/src/Processors/Creator.php b/src/Processors/Creator.php new file mode 100644 index 00000000..e68f015a --- /dev/null +++ b/src/Processors/Creator.php @@ -0,0 +1,42 @@ +ensureExists(); + } + + protected function create(string $name, string $path): void + { + $this->files->copy( + $this->getStub('action.stub'), + $this->getTargetFilename($name, $path) + ); + } + + protected function ensureExists(): void + { + $this->files->ensureDirectoryExists($this->getStub()); + } + + protected function getStub(?string $name = null): string + { + return __DIR__ . '/../../resources/stubs/' . $name; + } + + protected function getTargetFilename(string $name, string $path): string + { + return Str::of($name) + ->trim() + ->slug('_') + ->prepend(rtrim($path, '\\/') . '/') + ->toString(); + } +} diff --git a/src/Processors/Fresh.php b/src/Processors/Fresh.php new file mode 100644 index 00000000..df0b8c6f --- /dev/null +++ b/src/Processors/Fresh.php @@ -0,0 +1,36 @@ +drop(); + $this->migrate(); + } + + protected function drop(): void + { + Schema::dropIfExists($this->getTableName()); + } + + protected function migrate(): void + { + $this->artisan(Names::MIGRATE, $this->getMigrateParams()); + } + + protected function getMigrateParams(): array + { + return array_filter([ + '--' . Options::DATABASE => $this->options->database, + '--' . Options::FORCE => true, + ]); + } +} diff --git a/src/Processors/Installer.php b/src/Processors/Installer.php new file mode 100644 index 00000000..bf7b4d03 --- /dev/null +++ b/src/Processors/Installer.php @@ -0,0 +1,13 @@ + Date: Thu, 18 Aug 2022 21:19:45 +0300 Subject: [PATCH 012/153] =?UTF-8?q?WIP=20WIP=20WIP...=20=F0=9F=91=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Concerns/Infoable.php | 59 -------------- src/Concerns/Notifications.php | 24 ++++++ src/Console/Command.php | 4 +- src/Console/Install.php | 4 +- src/Console/Make.php | 4 +- src/Console/Migrate.php | 4 +- src/Console/Refresh.php | 4 +- src/Console/Reset.php | 4 +- src/Console/Rollback.php | 4 +- src/Console/Status.php | 4 +- src/Notifications/Basic.php | 25 ++++++ src/Notifications/Beautiful.php | 37 +++++++++ src/Notifications/Notification.php | 23 ++++++ src/Processors/Fresh.php | 7 +- src/Processors/Install.php | 15 ++++ src/Processors/Installer.php | 13 ---- src/Processors/Processor.php | 8 +- src/Repositories/ActionRepository.php | 108 ++++++++++++++++++++++++++ src/Support/Migrator.php | 35 +++------ 19 files changed, 268 insertions(+), 118 deletions(-) delete mode 100644 src/Concerns/Infoable.php create mode 100644 src/Concerns/Notifications.php create mode 100644 src/Notifications/Basic.php create mode 100644 src/Notifications/Beautiful.php create mode 100644 src/Notifications/Notification.php create mode 100644 src/Processors/Install.php delete mode 100644 src/Processors/Installer.php create mode 100644 src/Repositories/ActionRepository.php diff --git a/src/Concerns/Infoable.php b/src/Concerns/Infoable.php deleted file mode 100644 index febe1d7e..00000000 --- a/src/Concerns/Infoable.php +++ /dev/null @@ -1,59 +0,0 @@ -output) { - $string = Information::replace($string); - - $styled = $style ? "<$style>$string" : $string; - - $this->output->writeln($styled, $this->parsedVerbosity($verbosity)); - } - } - - /** - * Write a string as warning output. - * - * @param string $string - * @param int|string|null $verbosity - * - * @return void - */ - public function warn($string, $verbosity = null) - { - $this->line($string, 'warn', $verbosity); - } - - /** - * Write a string as standard output. - * - * @param string $message - */ - protected function note($message) - { - $this->line($message); - } - - protected function parsedVerbosity($verbosity = null): int - { - if (method_exists($this, 'parseVerbosity')) { - return $this->parseVerbosity($verbosity); - } - - return OutputInterface::VERBOSITY_NORMAL; - } -} diff --git a/src/Concerns/Notifications.php b/src/Concerns/Notifications.php new file mode 100644 index 00000000..e5cd8a2d --- /dev/null +++ b/src/Concerns/Notifications.php @@ -0,0 +1,24 @@ +notification)) { + return $this->notification; + } + + return $this->notification = class_exists(Factory::class) + ? new Beautiful($this->output) + : new Basic($this->output); + } +} diff --git a/src/Console/Command.php b/src/Console/Command.php index d76d2d13..ecc828c3 100644 --- a/src/Console/Command.php +++ b/src/Console/Command.php @@ -4,7 +4,7 @@ namespace DragonCode\LaravelActions\Console; -use DragonCode\LaravelActions\Concerns\Infoable; +use DragonCode\LaravelActions\Concerns\Notifications; use DragonCode\LaravelActions\Concerns\Optionable; use DragonCode\LaravelActions\Concerns\Path; use DragonCode\LaravelActions\Constants\Options; @@ -16,7 +16,7 @@ abstract class Command extends BaseCommand { use Optionable; - use Infoable; + use Notifications; use Path; protected Processor|string $processor; diff --git a/src/Console/Install.php b/src/Console/Install.php index d17ce78a..aa6e3c2c 100644 --- a/src/Console/Install.php +++ b/src/Console/Install.php @@ -3,7 +3,7 @@ namespace DragonCode\LaravelActions\Console; use DragonCode\LaravelActions\Constants\Names; -use DragonCode\LaravelActions\Processors\Installer; +use DragonCode\LaravelActions\Processors\Install as InstallProcessor; use DragonCode\LaravelActions\Processors\Processor; class Install extends Command @@ -12,5 +12,5 @@ class Install extends Command protected $description = 'Create the actions repository'; - protected Processor|string $processor = Installer::class; + protected Processor|string $processor = InstallProcessor::class; } diff --git a/src/Console/Make.php b/src/Console/Make.php index 9eb88666..9895adea 100644 --- a/src/Console/Make.php +++ b/src/Console/Make.php @@ -4,7 +4,7 @@ use DragonCode\LaravelActions\Concerns\Argumentable; use DragonCode\LaravelActions\Concerns\Database; -use DragonCode\LaravelActions\Concerns\Infoable; +use DragonCode\LaravelActions\Concerns\Notifications; use DragonCode\LaravelActions\Constants\Names; use Exception; use Illuminate\Database\Console\Migrations\BaseCommand; @@ -16,7 +16,7 @@ class Make extends BaseCommand { use Argumentable; use Database; - use Infoable; + use Notifications; /** * The console command name. diff --git a/src/Console/Migrate.php b/src/Console/Migrate.php index 3a53f88c..fafa6d0f 100644 --- a/src/Console/Migrate.php +++ b/src/Console/Migrate.php @@ -3,7 +3,7 @@ namespace DragonCode\LaravelActions\Console; use DragonCode\LaravelActions\Concerns\Database; -use DragonCode\LaravelActions\Concerns\Infoable; +use DragonCode\LaravelActions\Concerns\Notifications; use DragonCode\LaravelActions\Concerns\Optionable; use DragonCode\LaravelActions\Constants\Names; use Illuminate\Database\Console\Migrations\MigrateCommand as BaseCommand; @@ -11,7 +11,7 @@ class Migrate extends BaseCommand { use Database; - use Infoable; + use Notifications; use Optionable; /** diff --git a/src/Console/Refresh.php b/src/Console/Refresh.php index c789adcf..6c1640d0 100644 --- a/src/Console/Refresh.php +++ b/src/Console/Refresh.php @@ -3,7 +3,7 @@ namespace DragonCode\LaravelActions\Console; use DragonCode\LaravelActions\Concerns\Database; -use DragonCode\LaravelActions\Concerns\Infoable; +use DragonCode\LaravelActions\Concerns\Notifications; use DragonCode\LaravelActions\Concerns\Optionable; use DragonCode\LaravelActions\Constants\Names; use Illuminate\Console\Command as BaseCommand; @@ -16,7 +16,7 @@ class Refresh extends BaseCommand { use ConfirmableTrait; use Database; - use Infoable; + use Notifications; use Optionable; /** diff --git a/src/Console/Reset.php b/src/Console/Reset.php index a4658b8f..dc306c28 100644 --- a/src/Console/Reset.php +++ b/src/Console/Reset.php @@ -3,7 +3,7 @@ namespace DragonCode\LaravelActions\Console; use DragonCode\LaravelActions\Concerns\Database; -use DragonCode\LaravelActions\Concerns\Infoable; +use DragonCode\LaravelActions\Concerns\Notifications; use DragonCode\LaravelActions\Concerns\Optionable; use DragonCode\LaravelActions\Constants\Names; use DragonCode\LaravelActions\Support\Migrator; @@ -15,7 +15,7 @@ class Reset extends BaseCommand { use ConfirmableTrait; use Database; - use Infoable; + use Notifications; use Optionable; /** diff --git a/src/Console/Rollback.php b/src/Console/Rollback.php index 8bee9364..ff8ad6c9 100644 --- a/src/Console/Rollback.php +++ b/src/Console/Rollback.php @@ -3,7 +3,7 @@ namespace DragonCode\LaravelActions\Console; use DragonCode\LaravelActions\Concerns\Database; -use DragonCode\LaravelActions\Concerns\Infoable; +use DragonCode\LaravelActions\Concerns\Notifications; use DragonCode\LaravelActions\Concerns\Optionable; use DragonCode\LaravelActions\Constants\Names; use Illuminate\Database\Console\Migrations\RollbackCommand; @@ -12,7 +12,7 @@ class Rollback extends RollbackCommand { use Database; - use Infoable; + use Notifications; use Optionable; /** diff --git a/src/Console/Status.php b/src/Console/Status.php index aef015ac..18e5c0a3 100644 --- a/src/Console/Status.php +++ b/src/Console/Status.php @@ -3,7 +3,7 @@ namespace DragonCode\LaravelActions\Console; use DragonCode\LaravelActions\Concerns\Database; -use DragonCode\LaravelActions\Concerns\Infoable; +use DragonCode\LaravelActions\Concerns\Notifications; use DragonCode\LaravelActions\Concerns\Optionable; use DragonCode\LaravelActions\Constants\Names; use Illuminate\Database\Console\Migrations\StatusCommand as BaseCommand; @@ -11,7 +11,7 @@ class Status extends BaseCommand { use Database; - use Infoable; + use Notifications; use Optionable; /** diff --git a/src/Notifications/Basic.php b/src/Notifications/Basic.php new file mode 100644 index 00000000..d7235a7a --- /dev/null +++ b/src/Notifications/Basic.php @@ -0,0 +1,25 @@ +$string" : $string; + + $this->output->writeln($styled, $this->verbosity); + } + + public function info(string $string): void + { + $this->line($string, 'info'); + } + + public function warning(string $string): void + { + $this->line($string, 'warn'); + } +} diff --git a/src/Notifications/Beautiful.php b/src/Notifications/Beautiful.php new file mode 100644 index 00000000..c3005e66 --- /dev/null +++ b/src/Notifications/Beautiful.php @@ -0,0 +1,37 @@ +components()->line($style, $string, $this->verbosity); + } + + public function info(string $string): void + { + $this->components()->info($string, $this->verbosity); + } + + public function warning(string $string): void + { + $this->components()->warn($string, $this->verbosity); + } + + protected function components() + { + if (! is_null($this->components)) { + return $this->components; + } + + return $this->components = Container::getInstance()->make(Factory::class, ['output' => $this->output]); + } +} diff --git a/src/Notifications/Notification.php b/src/Notifications/Notification.php new file mode 100644 index 00000000..291e6143 --- /dev/null +++ b/src/Notifications/Notification.php @@ -0,0 +1,23 @@ +getTableName()); + $this->repository->deleteRepository(); + + $this->notification()->info('Action table deleted successfully.'); } protected function migrate(): void { $this->artisan(Names::MIGRATE, $this->getMigrateParams()); + + $this->notification()->info('Migration table created successfully.'); } protected function getMigrateParams(): array diff --git a/src/Processors/Install.php b/src/Processors/Install.php new file mode 100644 index 00000000..c048df03 --- /dev/null +++ b/src/Processors/Install.php @@ -0,0 +1,15 @@ +repository->createRepository(); + + $this->notification()->info('Actions table created successfully.'); + } +} diff --git a/src/Processors/Installer.php b/src/Processors/Installer.php deleted file mode 100644 index bf7b4d03..00000000 --- a/src/Processors/Installer.php +++ /dev/null @@ -1,13 +0,0 @@ -getOrderTable() + ->pluck('action') + ->all(); + } + + public function getByStep(?int $steps = null): array + { + return $this->getOrderTable('desc') + ->when($steps, fn (Query $builder) => $builder->take($steps)) + ->get() + ->all(); + } + + public function getLast(): array + { + return $this->getOrderTable('desc') + ->where('batch', $this->getLastBatchNumber()) + ->get() + ->all(); + } + + public function getNextBatchNumber(): int + { + return $this->getLastBatchNumber() + 1; + } + + public function getLastBatchNumber(): int + { + return $this->table()->max('batch') ?: 0; + } + + public function log(string $action, int $batch): void + { + $this->table()->insert(compact('action', 'batch')); + } + + public function delete(string $action): void + { + $this->table()->where(compact('action'))->delete(); + } + + public function createRepository(): void + { + $this->schema()->create($this->getTableName(), function (Blueprint $table) { + $table->id(); + + $table->string('action'); + + $table->unsignedInteger('batch'); + }); + } + + public function repositoryExists(): bool + { + return $this->schema()->hasTable($this->getTableName()); + } + + public function deleteRepository(): void + { + $this->schema()->dropIfExists($this->getTableName()); + } + + protected function getOrderTable(string $order = 'asc'): Query + { + return $this->table() + ->orderBy('batch', $order) + ->orderBy('action', $order); + } + + protected function schema(): Builder + { + return $this->getConnection()->getSchemaBuilder(); + } + + protected function getConnection(): ConnectionInterface + { + return $this->resolver->connection(); + } + + protected function table(): Query + { + return $this->getConnection()->table($this->getTableName())->useWritePdo(); + } +} diff --git a/src/Support/Migrator.php b/src/Support/Migrator.php index 6eefe326..8233d4fc 100644 --- a/src/Support/Migrator.php +++ b/src/Support/Migrator.php @@ -3,16 +3,14 @@ namespace DragonCode\LaravelActions\Support; use DragonCode\Contracts\LaravelActions\Actionable as ActionableContract; -use DragonCode\LaravelActions\Concerns\Anonymous; -use DragonCode\LaravelActions\Concerns\Infoable; +use DragonCode\LaravelActions\Concerns\Notifications; use Illuminate\Database\Migrations\Migrator as BaseMigrator; use Illuminate\Support\Facades\DB; use Throwable; class Migrator extends BaseMigrator { - use Infoable; - use Anonymous; + use Notifications; protected $is_before = false; @@ -48,16 +46,9 @@ protected function runUp($file, $batch, $pretend) // First we will resolve a "real" instance of the migration class from this // migration file name. Once we have the instances we can run the actual // command such as "up" or "down", or we can just simulate the action. - if ($this->allowAnonymous()) { - $migration = $this->resolvePath($file); + $migration = $this->resolvePath($file); - $name = $this->getMigrationName($file); - } - else { - $migration = $this->resolve( - $name = $this->getMigrationName($file) - ); - } + $name = $this->getMigrationName($file); if (! $this->allowEnvironment($migration)) { $this->note("Migrate: {$name} was skipped on this environment"); @@ -106,16 +97,9 @@ protected function runUp($file, $batch, $pretend) */ protected function runDown($file, $migration, $pretend) { - if ($this->allowAnonymous()) { - $instance = $this->resolvePath($file); + $instance = $this->resolvePath($file); - $name = $this->getMigrationName($file); - } - else { - $instance = $this->resolve( - $name = $this->getMigrationName($file) - ); - } + $name = $this->getMigrationName($file); if (! $this->allowEnvironment($instance)) { $this->note("Rolling back: {$name} was skipped on this environment"); @@ -190,7 +174,7 @@ protected function allowEnvironment(ActionableContract $migration): bool /** * Whether it is necessary to call database transactions at runtime. * - * @param \DragonCode\LaravelActions\Support\Actionable|object $migration + * @param \DragonCode\LaravelActions\Services\Actionable|object $migration * * @return bool */ @@ -202,7 +186,7 @@ protected function enabledTransactions(ActionableContract $migration): bool /** * The number of attempts to execute a request within a transaction before throwing an error. * - * @param \DragonCode\LaravelActions\Support\Actionable|object $migration + * @param \DragonCode\LaravelActions\Services\Actionable|object $migration * * @return int */ @@ -239,8 +223,7 @@ protected function runMigrationHandle(ActionableContract $migration, callable $h $handle($migration); $this->runSuccess($migration); - } - catch (Throwable $e) { + } catch (Throwable $e) { $this->runFailed($migration); throw $e; From 2325c1e632d5cf5cd2ff9a131435ea583b260eae Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Fri, 26 Aug 2022 17:04:26 +0300 Subject: [PATCH 013/153] Update files --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 3513d623..1eb13fed 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,8 @@ "authors": [ { "name": "Andrey Helldar", - "email": "helldar@dragon-code.pro" + "email": "helldar@dragon-code.pro", + "homepage": "https://github.com/andrey-helldar" } ], "support": { From 849bc4a7132a47a800b17af1e16b158d8a08b95f Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Thu, 8 Sep 2022 22:05:48 +0300 Subject: [PATCH 014/153] =?UTF-8?q?Update=20code-style=20=F0=9F=92=BB?= =?UTF-8?q?=F0=9F=92=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...022_08_18_175524_create_migration_actions_table.php | 4 +++- ...022_08_18_180137_change_migration_actions_table.php | 4 +++- .../base/BaseChangeMigrationActionsTable.php | 2 -- .../base/BaseCreateMigrationActionsTable.php | 2 -- ...022_08_18_175524_create_migration_actions_table.php | 4 +++- ...022_08_18_180137_change_migration_actions_table.php | 4 +++- src/Notifications/Notification.php | 10 +++++----- src/Processors/Processor.php | 8 ++++---- src/ServiceProvider.php | 1 - src/Support/Migrator.php | 3 ++- tests/Commands/MigrateTest.php | 9 ++++++--- tests/Commands/RollbackTest.php | 6 ++++-- .../anonymous/2020_12_07_164624_create_test_table.php | 3 ++- .../2021_01_02_022431_create_every_time_table.php | 3 ++- .../2021_02_15_124419_create_transactions_table.php | 3 ++- .../2021_05_24_122027_create_environment_table.php | 3 ++- .../2021_12_23_165218_create_success_table.php | 3 ++- .../2021_12_23_184434_create_failed_table.php | 3 ++- .../2022_08_17_150549_create_before_table.php | 3 ++- 19 files changed, 47 insertions(+), 31 deletions(-) diff --git a/database/migrations/anonymous/2022_08_18_175524_create_migration_actions_table.php b/database/migrations/anonymous/2022_08_18_175524_create_migration_actions_table.php index 64db0892..00e79d4a 100644 --- a/database/migrations/anonymous/2022_08_18_175524_create_migration_actions_table.php +++ b/database/migrations/anonymous/2022_08_18_175524_create_migration_actions_table.php @@ -1,3 +1,5 @@ table()); } } - -; diff --git a/database/migrations/named/2022_08_18_175524_create_migration_actions_table.php b/database/migrations/named/2022_08_18_175524_create_migration_actions_table.php index 84147d85..948001df 100644 --- a/database/migrations/named/2022_08_18_175524_create_migration_actions_table.php +++ b/database/migrations/named/2022_08_18_175524_create_migration_actions_table.php @@ -1,3 +1,5 @@ runSuccess($migration); - } catch (Throwable $e) { + } + catch (Throwable $e) { $this->runFailed($migration); throw $e; diff --git a/tests/Commands/MigrateTest.php b/tests/Commands/MigrateTest.php index 4cd81462..cc0b0931 100644 --- a/tests/Commands/MigrateTest.php +++ b/tests/Commands/MigrateTest.php @@ -91,7 +91,8 @@ public function testFailedTransaction() try { $this->artisan(Names::MIGRATE)->run(); - } catch (Exception $e) { + } + catch (Exception $e) { $this->assertSame(Exception::class, get_class($e)); $this->assertSame('Random message', $e->getMessage()); } @@ -242,7 +243,8 @@ public function testUpSuccessOnFailed() $this->copySuccessFailureMethod(); $this->artisan(Names::MIGRATE)->run(); - } catch (Throwable $e) { + } + catch (Throwable $e) { $this->assertInstanceOf(Exception::class, $e); $this->assertSame('Custom exception', $e->getMessage()); @@ -294,7 +296,8 @@ public function testUpFailedOnException() $this->copyFailedMethod(); $this->artisan(Names::MIGRATE)->run(); - } catch (Throwable $e) { + } + catch (Throwable $e) { $this->assertInstanceOf(Exception::class, $e); $this->assertSame('Custom exception', $e->getMessage()); diff --git a/tests/Commands/RollbackTest.php b/tests/Commands/RollbackTest.php index 1d65b5dd..bd02f4f1 100644 --- a/tests/Commands/RollbackTest.php +++ b/tests/Commands/RollbackTest.php @@ -130,7 +130,8 @@ public function testDownSuccessOnFailed() $this->table()->insert(['migration' => '2021_12_23_165048_run_success_on_failed', 'batch' => 999]); $this->artisan(Names::ROLLBACK)->run(); - } catch (Throwable $e) { + } + catch (Throwable $e) { $this->assertInstanceOf(Exception::class, $e); $this->assertSame('Custom exception', $e->getMessage()); @@ -189,7 +190,8 @@ public function testUpFailedOnException() $this->table()->insert(['migration' => '2021_12_23_184029_run_failed_failure', 'batch' => 999]); $this->artisan(Names::ROLLBACK)->run(); - } catch (Throwable $e) { + } + catch (Throwable $e) { $this->assertInstanceOf(Exception::class, $e); $this->assertSame('Custom exception', $e->getMessage()); diff --git a/tests/fixtures/migrations/anonymous/2020_12_07_164624_create_test_table.php b/tests/fixtures/migrations/anonymous/2020_12_07_164624_create_test_table.php index 46e2de50..837dc62a 100644 --- a/tests/fixtures/migrations/anonymous/2020_12_07_164624_create_test_table.php +++ b/tests/fixtures/migrations/anonymous/2020_12_07_164624_create_test_table.php @@ -4,7 +4,8 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration { +return new class () extends Migration +{ public function up() { Schema::create('test', function (Blueprint $table) { diff --git a/tests/fixtures/migrations/anonymous/2021_01_02_022431_create_every_time_table.php b/tests/fixtures/migrations/anonymous/2021_01_02_022431_create_every_time_table.php index 426eb55c..d9522b02 100644 --- a/tests/fixtures/migrations/anonymous/2021_01_02_022431_create_every_time_table.php +++ b/tests/fixtures/migrations/anonymous/2021_01_02_022431_create_every_time_table.php @@ -4,7 +4,8 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration { +return new class () extends Migration +{ public function up() { Schema::create('every_time', function (Blueprint $table) { diff --git a/tests/fixtures/migrations/anonymous/2021_02_15_124419_create_transactions_table.php b/tests/fixtures/migrations/anonymous/2021_02_15_124419_create_transactions_table.php index cb8920cc..833e4846 100644 --- a/tests/fixtures/migrations/anonymous/2021_02_15_124419_create_transactions_table.php +++ b/tests/fixtures/migrations/anonymous/2021_02_15_124419_create_transactions_table.php @@ -4,7 +4,8 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration { +return new class () extends Migration +{ public function up() { Schema::create('transactions', function (Blueprint $table) { diff --git a/tests/fixtures/migrations/anonymous/2021_05_24_122027_create_environment_table.php b/tests/fixtures/migrations/anonymous/2021_05_24_122027_create_environment_table.php index c89fa4a4..254a9b8b 100644 --- a/tests/fixtures/migrations/anonymous/2021_05_24_122027_create_environment_table.php +++ b/tests/fixtures/migrations/anonymous/2021_05_24_122027_create_environment_table.php @@ -4,7 +4,8 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration { +return new class () extends Migration +{ public function up() { Schema::create('environment', function (Blueprint $table) { diff --git a/tests/fixtures/migrations/anonymous/2021_12_23_165218_create_success_table.php b/tests/fixtures/migrations/anonymous/2021_12_23_165218_create_success_table.php index 666e481c..a96f2b24 100644 --- a/tests/fixtures/migrations/anonymous/2021_12_23_165218_create_success_table.php +++ b/tests/fixtures/migrations/anonymous/2021_12_23_165218_create_success_table.php @@ -4,7 +4,8 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration { +return new class () extends Migration +{ public function up() { Schema::create('success', function (Blueprint $table) { diff --git a/tests/fixtures/migrations/anonymous/2021_12_23_184434_create_failed_table.php b/tests/fixtures/migrations/anonymous/2021_12_23_184434_create_failed_table.php index a37c5f7e..493529ef 100644 --- a/tests/fixtures/migrations/anonymous/2021_12_23_184434_create_failed_table.php +++ b/tests/fixtures/migrations/anonymous/2021_12_23_184434_create_failed_table.php @@ -4,7 +4,8 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration { +return new class () extends Migration +{ public function up() { Schema::create('failed', function (Blueprint $table) { diff --git a/tests/fixtures/migrations/anonymous/2022_08_17_150549_create_before_table.php b/tests/fixtures/migrations/anonymous/2022_08_17_150549_create_before_table.php index 7f724bd4..0010b64b 100644 --- a/tests/fixtures/migrations/anonymous/2022_08_17_150549_create_before_table.php +++ b/tests/fixtures/migrations/anonymous/2022_08_17_150549_create_before_table.php @@ -4,7 +4,8 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration { +return new class () extends Migration +{ public function up() { Schema::create('before', function (Blueprint $table) { From 992bd48aa49ad37a3263ca0237208c4f8f05f5ee Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Thu, 8 Sep 2022 22:09:37 +0300 Subject: [PATCH 015/153] Merge `lint-check.yml` and `lint-fixer.yml` to `code-style.yml` --- .github/workflows/code-style.yml | 35 ++++++++++++++++++++++++++++++++ .github/workflows/lint-check.yml | 14 ------------- .github/workflows/lint-fixer.yml | 19 ----------------- 3 files changed, 35 insertions(+), 33 deletions(-) create mode 100644 .github/workflows/code-style.yml delete mode 100644 .github/workflows/lint-check.yml delete mode 100644 .github/workflows/lint-fixer.yml diff --git a/.github/workflows/code-style.yml b/.github/workflows/code-style.yml new file mode 100644 index 00000000..665db2e4 --- /dev/null +++ b/.github/workflows/code-style.yml @@ -0,0 +1,35 @@ +name: code-style + +on: + push: + pull_request: + +permissions: write-all + +jobs: + check: + if: ${{ ! (github.event_name == 'push' && github.ref == 'refs/heads/main') }} + + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Checking PHP Syntax + uses: TheDragonCode/codestyler@v2.6.2 + + fix: + if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} + + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Checking PHP Syntax + uses: TheDragonCode/codestyler@v2.6.2 + with: + github_token: ${{ secrets.COMPOSER_TOKEN }} + fix: true diff --git a/.github/workflows/lint-check.yml b/.github/workflows/lint-check.yml deleted file mode 100644 index cf847b8d..00000000 --- a/.github/workflows/lint-check.yml +++ /dev/null @@ -1,14 +0,0 @@ -name: "Code-Style Check" - -on: [ push, pull_request ] - -jobs: - check: - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v3 - - - name: Checking PHP Syntax - uses: TheDragonCode/codestyler@v2.6.2 diff --git a/.github/workflows/lint-fixer.yml b/.github/workflows/lint-fixer.yml deleted file mode 100644 index 1663da75..00000000 --- a/.github/workflows/lint-fixer.yml +++ /dev/null @@ -1,19 +0,0 @@ -name: "Code-Style Fixer" - -on: - push: - branches: [ main ] - -jobs: - fix: - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v3 - - - name: Checking PHP Syntax - uses: TheDragonCode/codestyler@v2.6.2 - with: - github_token: ${{ secrets.COMPOSER_TOKEN }} - fix: true From 7136c9a8a5ebfece3a97edd4affb5123ad02fa32 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Thu, 8 Sep 2022 22:31:23 +0300 Subject: [PATCH 016/153] Added Laravel 10 support --- .github/workflows/laravel-10.yml | 31 +++++++++++++++++++++++++++++++ composer.json | 16 ++++++++-------- 2 files changed, 39 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/laravel-10.yml diff --git a/.github/workflows/laravel-10.yml b/.github/workflows/laravel-10.yml new file mode 100644 index 00000000..8dd75cf6 --- /dev/null +++ b/.github/workflows/laravel-10.yml @@ -0,0 +1,31 @@ +name: "Laravel 10" +on: [ push ] + +jobs: + build: + runs-on: ubuntu-latest + + strategy: + fail-fast: true + matrix: + php: [ "8.1" ] + laravel: [ "10.0" ] + + name: PHP ${{ matrix.php }} + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: curl, mbstring, zip, pcntl, pdo, pdo_sqlite, iconv + coverage: none + + - name: Install dependencies + run: composer require --dev laravel/framework:^${{ matrix.laravel }} + + - name: Execute tests + run: sudo vendor/bin/phpunit diff --git a/composer.json b/composer.json index 1eb13fed..cf495441 100644 --- a/composer.json +++ b/composer.json @@ -28,26 +28,26 @@ "php": "^8.0", "composer-runtime-api": "^2.2", "dragon-code/contracts": "^2.15", - "dragon-code/laravel-support": "^3.3", + "dragon-code/laravel-support": "^3.4", "dragon-code/simple-dto": "^2.3", "dragon-code/support": "^6.3", - "illuminate/container": "^7.0 || ^8.0 || ^9.0", - "illuminate/console": "^7.0 || ^8.0 || ^9.0", - "illuminate/database": "^7.0 || ^8.0 || ^9.0", - "illuminate/support": "^7.0 || ^8.0 || ^9.0", + "illuminate/console": "^7.0 || ^8.0 || ^9.0 || ^10.0", + "illuminate/container": "^7.0 || ^8.0 || ^9.0 || ^10.0", + "illuminate/database": "^7.0 || ^8.0 || ^9.0 || ^10.0", + "illuminate/support": "^7.0 || ^8.0 || ^9.0 || ^10.0", "symfony/console": "^5.0 || ^6.0" }, "require-dev": { "mockery/mockery": "^1.3.1", - "orchestra/testbench": "^5.0 || ^6.0 || ^7.0", - "phpunit/phpunit": "^9.0", + "orchestra/testbench": "^5.0 || ^6.0 || ^7.0 || ^8.0", + "phpunit/phpunit": "^9.5", "ramsey/uuid": "^3.7 || ^4.0" }, "conflict": { "andrey-helldar/laravel-actions": "*", "dragon-code/laravel-actions": "*" }, - "minimum-stability": "stable", + "minimum-stability": "dev", "prefer-stable": true, "autoload": { "psr-4": { From ababd15432952b8f72a83f0b91578ea419145a13 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Thu, 8 Sep 2022 22:34:01 +0300 Subject: [PATCH 017/153] Fixed About command data --- src/Concerns/About.php | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/Concerns/About.php b/src/Concerns/About.php index e6a754f6..fe49c429 100644 --- a/src/Concerns/About.php +++ b/src/Concerns/About.php @@ -5,12 +5,13 @@ namespace DragonCode\LaravelActions\Concerns; use Composer\InstalledVersions; -use DragonCode\Support\Facades\Helpers\Arr; use DragonCode\Support\Facades\Helpers\Str; use Illuminate\Foundation\Console\AboutCommand; trait About { + protected string $package_name = 'dragon-code/laravel-migration-actions'; + protected function registerAbout(): void { if (class_exists(AboutCommand::class)) { @@ -22,7 +23,7 @@ protected function registerAbout(): void protected function getPackageName(): string { - return Str::of($this->getPackageValue('name')) + return Str::of($this->package_name) ->after('/') ->snake() ->replace('_', ' ') @@ -32,11 +33,6 @@ protected function getPackageName(): string protected function getPackageVersion(): string { - return $this->getPackageValue('pretty_version'); - } - - protected function getPackageValue(string $key): string - { - return Arr::get(InstalledVersions::getRootPackage(), $key); + return InstalledVersions::getPrettyVersion($this->package_name); } } From befcaa965b4d5731772f29725507ec676c5488f7 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Thu, 8 Sep 2022 22:47:05 +0300 Subject: [PATCH 018/153] Removed unused migrations --- ..._175524_create_migration_actions_table.php | 5 --- .../base/BaseChangeMigrationActionsTable.php | 4 +-- .../base/BaseCreateMigrationActionsTable.php | 31 ------------------- ..._175524_create_migration_actions_table.php | 5 --- 4 files changed, 2 insertions(+), 43 deletions(-) delete mode 100644 database/migrations/anonymous/2022_08_18_175524_create_migration_actions_table.php delete mode 100644 database/migrations/base/BaseCreateMigrationActionsTable.php delete mode 100644 database/migrations/named/2022_08_18_175524_create_migration_actions_table.php diff --git a/database/migrations/anonymous/2022_08_18_175524_create_migration_actions_table.php b/database/migrations/anonymous/2022_08_18_175524_create_migration_actions_table.php deleted file mode 100644 index 00e79d4a..00000000 --- a/database/migrations/anonymous/2022_08_18_175524_create_migration_actions_table.php +++ /dev/null @@ -1,5 +0,0 @@ -table(), function (Blueprint $table) { + Schema::table($this->getTableName(), function (Blueprint $table) { $table->renameColumn('migration', 'action'); $table->unsignedInteger('batch')->change(); @@ -20,7 +20,7 @@ public function up() public function down() { - Schema::table($this->table(), function (Blueprint $table) { + Schema::table($this->getTableName(), function (Blueprint $table) { $table->renameColumn('action', 'migration'); $table->integer('batch')->change(); diff --git a/database/migrations/base/BaseCreateMigrationActionsTable.php b/database/migrations/base/BaseCreateMigrationActionsTable.php deleted file mode 100644 index d9a0c5e9..00000000 --- a/database/migrations/base/BaseCreateMigrationActionsTable.php +++ /dev/null @@ -1,31 +0,0 @@ -table())) { - return; - } - - Schema::create($this->table(), function (Blueprint $table) { - $table->id(); - - $table->string('migration'); - - $table->integer('batch'); - }); - } - - public function down() - { - Schema::dropIfExists($this->table()); - } -} diff --git a/database/migrations/named/2022_08_18_175524_create_migration_actions_table.php b/database/migrations/named/2022_08_18_175524_create_migration_actions_table.php deleted file mode 100644 index 948001df..00000000 --- a/database/migrations/named/2022_08_18_175524_create_migration_actions_table.php +++ /dev/null @@ -1,5 +0,0 @@ - Date: Thu, 8 Sep 2022 22:47:13 +0300 Subject: [PATCH 019/153] Update action.stub --- resources/stubs/action.stub | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/resources/stubs/action.stub b/resources/stubs/action.stub index ddbc46bc..c8b05778 100644 --- a/resources/stubs/action.stub +++ b/resources/stubs/action.stub @@ -2,7 +2,8 @@ use DragonCode\LaravelActions\Services\Actionable; -return new class extends Actionable { +return new class () extends Actionable +{ /** * Run the actions. * From 658c441c13cab9abfa30027d77db34d10789a769 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Thu, 8 Sep 2022 22:50:31 +0300 Subject: [PATCH 020/153] Small refactoring --- src/Concerns/{Versionable.php => Anonymouses.php} | 2 +- src/ServiceProvider.php | 4 ++-- tests/TestCase.php | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) rename src/Concerns/{Versionable.php => Anonymouses.php} (92%) diff --git a/src/Concerns/Versionable.php b/src/Concerns/Anonymouses.php similarity index 92% rename from src/Concerns/Versionable.php rename to src/Concerns/Anonymouses.php index e3d741a1..1c549695 100644 --- a/src/Concerns/Versionable.php +++ b/src/Concerns/Anonymouses.php @@ -4,7 +4,7 @@ use DragonCode\LaravelSupport\Facades\AppVersion; -trait Versionable +trait Anonymouses { protected function allowAnonymousMigrations(): bool { diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index 701900e1..c0176165 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -3,13 +3,13 @@ namespace DragonCode\LaravelActions; use DragonCode\LaravelActions\Concerns\About; -use DragonCode\LaravelActions\Concerns\Versionable; +use DragonCode\LaravelActions\Concerns\Anonymouses; use Illuminate\Support\ServiceProvider as BaseServiceProvider; class ServiceProvider extends BaseServiceProvider { use About; - use Versionable; + use Anonymouses; public function boot(): void { diff --git a/tests/TestCase.php b/tests/TestCase.php index 8182fed5..bb044df2 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -3,7 +3,7 @@ namespace Tests; use DragonCode\LaravelActions\Concerns\Path; -use DragonCode\LaravelActions\Concerns\Versionable; +use DragonCode\LaravelActions\Concerns\Anonymouses; use DragonCode\LaravelActions\ServiceProvider; use Illuminate\Database\Query\Builder; use Illuminate\Foundation\Testing\RefreshDatabase; @@ -20,7 +20,7 @@ abstract class TestCase extends BaseTestCase use Files; use Path; use RefreshDatabase; - use Versionable; + use Anonymouses; protected function setUp(): void { From 4fd8e26004cd1935b22f22d75c94a0994f06e6c2 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Thu, 8 Sep 2022 22:50:58 +0300 Subject: [PATCH 021/153] Added Upgrade command --- src/Console/Upgrade.php | 18 ++++++++++++++++++ src/Constants/Names.php | 2 ++ src/ServiceProvider.php | 1 + 3 files changed, 21 insertions(+) create mode 100644 src/Console/Upgrade.php diff --git a/src/Console/Upgrade.php b/src/Console/Upgrade.php new file mode 100644 index 00000000..d56debd9 --- /dev/null +++ b/src/Console/Upgrade.php @@ -0,0 +1,18 @@ + Date: Thu, 8 Sep 2022 22:53:12 +0300 Subject: [PATCH 022/153] Fixed parameter initialization --- src/Concerns/Notifications.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Concerns/Notifications.php b/src/Concerns/Notifications.php index e5cd8a2d..f007fc79 100644 --- a/src/Concerns/Notifications.php +++ b/src/Concerns/Notifications.php @@ -9,7 +9,7 @@ trait Notifications { - protected Notification|null $notification; + protected ?Notification $notification = null; protected function notification(): Notification { From 06bc25d5acebd5e330a926a783efe4809d472c60 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Thu, 8 Sep 2022 22:54:15 +0300 Subject: [PATCH 023/153] Parameter typing changed --- src/Values/Options.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Values/Options.php b/src/Values/Options.php index 80d92960..fdff06d5 100644 --- a/src/Values/Options.php +++ b/src/Values/Options.php @@ -18,5 +18,5 @@ class Options extends DataTransferObject public bool $realpath = false; - public int|null $step = null; + public ?int $step = null; } From e9e47e71a6ccefba9a3bbef7157cf595c1548cbe Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Thu, 8 Sep 2022 23:00:18 +0300 Subject: [PATCH 024/153] Refactored Git support class --- src/Concerns/Argumentable.php | 2 +- src/Support/Git.php | 20 ++++++++++++++------ tests/Services/GitTest.php | 2 +- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/Concerns/Argumentable.php b/src/Concerns/Argumentable.php index 2b10b326..8ed30c92 100644 --- a/src/Concerns/Argumentable.php +++ b/src/Concerns/Argumentable.php @@ -29,6 +29,6 @@ protected function getAutoPrefix(): string protected function getGitBranchName(): ?string { - return Git::make()->currentBranch(base_path('.git')); + return Git::make()->currentBranch(base_path()); } } diff --git a/src/Support/Git.php b/src/Support/Git.php index d7a67cfa..c2f66d62 100644 --- a/src/Support/Git.php +++ b/src/Support/Git.php @@ -5,6 +5,8 @@ namespace DragonCode\LaravelActions\Support; use DragonCode\Support\Concerns\Makeable; +use DragonCode\Support\Facades\Filesystem\Directory; +use DragonCode\Support\Facades\Filesystem\Path; use Illuminate\Support\Str; class Git @@ -25,11 +27,6 @@ protected function exec(string $path, string $command): ?string return exec(sprintf('git --git-dir %s %s', $path, $command)); } - protected function resolvePath(string $path): ?string - { - return realpath($path) ?: null; - } - protected function getGitPath(?string $path): ?string { if ($path = $this->resolvePath($path)) { @@ -44,9 +41,20 @@ protected function getGitPath(?string $path): ?string protected function isGitDir(?string $path): bool { if ($path = rtrim($path, '/\\')) { - return Str::endsWith($path, '.git'); + return Directory::exists($path . DIRECTORY_SEPARATOR . '.git'); } return false; } + + protected function resolvePath(string $path): ?string + { + if ($path = realpath($path)) { + $path = rtrim($path, '\\/'); + + return Str::endsWith($path, '.git') ? Path::dirname($path) : $path; + } + + return null; + } } diff --git a/tests/Services/GitTest.php b/tests/Services/GitTest.php index a1247d16..b93e0d5e 100644 --- a/tests/Services/GitTest.php +++ b/tests/Services/GitTest.php @@ -16,7 +16,7 @@ public function testCurrentBranchNull() public function testCurrentBranch() { - $branch = $this->git()->currentBranch(__DIR__ . '/../../.git'); + $branch = $this->git()->currentBranch(__DIR__ . '/../../'); $this->assertIsString($branch); } From cfa059e561bc10c89f8c49b76567ca8d944ddac3 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Thu, 8 Sep 2022 23:05:43 +0300 Subject: [PATCH 025/153] Moved base database class to another namespace --- .../2022_08_18_180137_change_migration_actions_table.php | 4 +++- .../2022_08_18_180137_change_migration_actions_table.php | 4 +++- .../Database/BaseChangeMigrationColumn.php | 6 +++++- 3 files changed, 11 insertions(+), 3 deletions(-) rename database/migrations/base/BaseChangeMigrationActionsTable.php => src/Database/BaseChangeMigrationColumn.php (83%) diff --git a/database/migrations/anonymous/2022_08_18_180137_change_migration_actions_table.php b/database/migrations/anonymous/2022_08_18_180137_change_migration_actions_table.php index 71f9776c..467330e1 100644 --- a/database/migrations/anonymous/2022_08_18_180137_change_migration_actions_table.php +++ b/database/migrations/anonymous/2022_08_18_180137_change_migration_actions_table.php @@ -1,5 +1,7 @@ Date: Thu, 8 Sep 2022 23:10:15 +0300 Subject: [PATCH 026/153] Removed full stop --- src/Console/Command.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Console/Command.php b/src/Console/Command.php index ecc828c3..901eeccd 100644 --- a/src/Console/Command.php +++ b/src/Console/Command.php @@ -51,7 +51,7 @@ protected function confirmToProceed(): bool return true; } - $this->warn('Command canceled.'); + $this->warn('Command canceled'); return false; } From f0c717fff565b218007b6f6b7572e3a2876e78ae Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Thu, 8 Sep 2022 23:22:06 +0300 Subject: [PATCH 027/153] Added Make command --- src/Concerns/Composer.php | 22 ++++++++++ src/Console/Make.php | 87 ++------------------------------------- src/Processors/Make.php | 30 ++++++++++++++ src/Values/Options.php | 2 + 4 files changed, 58 insertions(+), 83 deletions(-) create mode 100644 src/Concerns/Composer.php create mode 100644 src/Processors/Make.php diff --git a/src/Concerns/Composer.php b/src/Concerns/Composer.php new file mode 100644 index 00000000..00a657f3 --- /dev/null +++ b/src/Concerns/Composer.php @@ -0,0 +1,22 @@ +composer)) { + return $this->composer; + } + + return $this->composer = Container::getInstance()->make(IlluminateComposer::class); + } +} diff --git a/src/Console/Make.php b/src/Console/Make.php index 9895adea..b61dbe2e 100644 --- a/src/Console/Make.php +++ b/src/Console/Make.php @@ -2,95 +2,16 @@ namespace DragonCode\LaravelActions\Console; -use DragonCode\LaravelActions\Concerns\Argumentable; -use DragonCode\LaravelActions\Concerns\Database; -use DragonCode\LaravelActions\Concerns\Notifications; use DragonCode\LaravelActions\Constants\Names; -use Exception; -use Illuminate\Database\Console\Migrations\BaseCommand; -use Illuminate\Database\Migrations\MigrationCreator; -use Illuminate\Support\Composer; -use Illuminate\Support\Str; +use DragonCode\LaravelActions\Processors\Make as MakeProcessor; +use DragonCode\LaravelActions\Processors\Processor; -class Make extends BaseCommand +class Make extends Command { - use Argumentable; - use Database; - use Notifications; - - /** - * The console command name. - * - * @var string - */ protected $signature = Names::MAKE . ' {name? : The name of the action}'; - /** - * The console command description. - * - * @var string - */ protected $description = 'Create a new action file'; - /** - * The migration creator instance. - * - * @var \Illuminate\Database\Migrations\MigrationCreator - */ - protected $creator; - - /** - * The Composer instance. - * - * @var \Illuminate\Support\Composer - */ - protected $composer; - - /** - * Create a new action install command instance. - * - * @param \Illuminate\Database\Migrations\MigrationCreator $creator - * @param \Illuminate\Support\Composer $composer - */ - public function __construct(MigrationCreator $creator, Composer $composer) - { - parent::__construct(); - - $this->creator = $creator; - $this->composer = $composer; - } - - /** - * Execute the console command. - * - * @throws Exception - */ - public function handle() - { - $this->writeMigration( - Str::snake($this->argumentName()) - ); - - $this->composer->dumpAutoloads(); - } - - /** - * Write the action file to disk. - * - * @param string $name - * - * @throws Exception - */ - protected function writeMigration(string $name) - { - $file = $this->creator->create( - $name, - $this->getMigrationPath() - ); - - $path = pathinfo($file, PATHINFO_FILENAME); - - $this->line("Created Action: {$path}"); - } + protected Processor|string $processor = MakeProcessor::class; } diff --git a/src/Processors/Make.php b/src/Processors/Make.php new file mode 100644 index 00000000..2057b033 --- /dev/null +++ b/src/Processors/Make.php @@ -0,0 +1,30 @@ +writeMigration( + Str::snake($this->options->name) + ); + + $this->composer()->dumpAutoloads(); + } + + protected function writeMigration(string $name) + { + File::copy(__DIR__ . '/../../resources/stubs/action.stub', base_path('actions/' . $name)); + + $this->notification()->info("Created Action: $name"); + } +} diff --git a/src/Values/Options.php b/src/Values/Options.php index fdff06d5..cc59e21e 100644 --- a/src/Values/Options.php +++ b/src/Values/Options.php @@ -19,4 +19,6 @@ class Options extends DataTransferObject public bool $realpath = false; public ?int $step = null; + + public ?string $name = null; } From d0558c70ecef011bcc0ead154220a4cf78d38988 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Fri, 9 Sep 2022 01:15:25 +0300 Subject: [PATCH 028/153] Update issue templates --- .github/ISSUE_TEMPLATE/bug_report.yml | 10 ++++---- .github/ISSUE_TEMPLATE/feature_request.yml | 28 +--------------------- 2 files changed, 5 insertions(+), 33 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index 35a98d65..dfc1470e 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -1,8 +1,6 @@ -name: Bug +name: Bug Report description: Report a bug or other issue -labels: '👓 needs review' - body: - type: markdown attributes: @@ -20,10 +18,10 @@ body: Tip: Use the `php artisan --version` command to get information for Laravel Framework. Tip: Use the `php -v` command to get information for PHP. value: | - - Migration Actions Version: - - Laravel Version: - PHP Version: - Database Driver & Version: + - Migration Actions Version: + - Laravel Version: validations: required: true @@ -50,4 +48,4 @@ body: - type: markdown attributes: value: | - ❤️ The Dragon Code? Please consider supporting our collective: https://opencollective.com/dragon-code + ❤️ The Dragon Code? Please consider supporting [`our collective`](https://opencollective.com/dragon-code). diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.yml index bbaac841..751fd8f2 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.yml +++ b/.github/ISSUE_TEMPLATE/feature_request.yml @@ -1,17 +1,7 @@ name: Feature Proposal description: Propose a new feature -labels: - - '💪 feature request' - body: - - type: markdown - attributes: - value: | - Thanks for taking the time to fill out this bug report! - - ⚠️Review existing issues to see whether someone else has already reported your issue. - - type: textarea id: description attributes: @@ -23,23 +13,7 @@ body: validations: required: true - - type: textarea - id: environment - attributes: - label: Environment - description: | - Tip: Use the `composer info dragon-code/laravel-migration-actions` command to get information for Laravel Lang. - Tip: Use the `php artisan --version` command to get information for your application. - Tip: Use the `php -v` command to get information for PHP. - value: | - - Migration Actions Version: - - Laravel Version: - - PHP Version: - - Database Driver & Version: - validations: - required: false - - type: markdown attributes: value: | - ❤️ The Dragon Code? Please consider supporting our collective: https://opencollective.com/dragon-code + ❤️ The Dragon Code? Please consider supporting [`our collective`](https://opencollective.com/dragon-code). From 9f2a6589e8c7f4d0bf3032bef5d2fd9a8a582873 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Fri, 9 Sep 2022 01:23:19 +0300 Subject: [PATCH 029/153] Update Laravel unit tests --- .github/workflows/laravel-10.yml | 31 ------------------- .github/workflows/laravel-7.yml | 31 ------------------- .github/workflows/laravel-9.yml | 31 ------------------- .../workflows/{laravel-8.yml => laravel.yml} | 12 +++++-- 4 files changed, 9 insertions(+), 96 deletions(-) delete mode 100644 .github/workflows/laravel-10.yml delete mode 100644 .github/workflows/laravel-7.yml delete mode 100644 .github/workflows/laravel-9.yml rename .github/workflows/{laravel-8.yml => laravel.yml} (70%) diff --git a/.github/workflows/laravel-10.yml b/.github/workflows/laravel-10.yml deleted file mode 100644 index 8dd75cf6..00000000 --- a/.github/workflows/laravel-10.yml +++ /dev/null @@ -1,31 +0,0 @@ -name: "Laravel 10" -on: [ push ] - -jobs: - build: - runs-on: ubuntu-latest - - strategy: - fail-fast: true - matrix: - php: [ "8.1" ] - laravel: [ "10.0" ] - - name: PHP ${{ matrix.php }} - - steps: - - name: Checkout code - uses: actions/checkout@v3 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php }} - extensions: curl, mbstring, zip, pcntl, pdo, pdo_sqlite, iconv - coverage: none - - - name: Install dependencies - run: composer require --dev laravel/framework:^${{ matrix.laravel }} - - - name: Execute tests - run: sudo vendor/bin/phpunit diff --git a/.github/workflows/laravel-7.yml b/.github/workflows/laravel-7.yml deleted file mode 100644 index 14a43437..00000000 --- a/.github/workflows/laravel-7.yml +++ /dev/null @@ -1,31 +0,0 @@ -name: "Laravel 7" -on: [ push ] - -jobs: - build: - runs-on: ubuntu-latest - - strategy: - fail-fast: true - matrix: - php: [ "8.0" ] - laravel: [ "7.0" ] - - name: PHP ${{ matrix.php }} - - steps: - - name: Checkout code - uses: actions/checkout@v3 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php }} - extensions: curl, mbstring, zip, pcntl, pdo, pdo_sqlite, iconv - coverage: none - - - name: Install dependencies - run: composer require --dev laravel/framework:^${{ matrix.laravel }} - - - name: Execute tests - run: sudo vendor/bin/phpunit diff --git a/.github/workflows/laravel-9.yml b/.github/workflows/laravel-9.yml deleted file mode 100644 index 508c7620..00000000 --- a/.github/workflows/laravel-9.yml +++ /dev/null @@ -1,31 +0,0 @@ -name: "Laravel 9" -on: [ push ] - -jobs: - build: - runs-on: ubuntu-latest - - strategy: - fail-fast: true - matrix: - php: [ "8.0", "8.1" ] - laravel: [ "9.0" ] - - name: PHP ${{ matrix.php }} - - steps: - - name: Checkout code - uses: actions/checkout@v3 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php }} - extensions: curl, mbstring, zip, pcntl, pdo, pdo_sqlite, iconv - coverage: none - - - name: Install dependencies - run: composer require --dev laravel/framework:^${{ matrix.laravel }} - - - name: Execute tests - run: sudo vendor/bin/phpunit diff --git a/.github/workflows/laravel-8.yml b/.github/workflows/laravel.yml similarity index 70% rename from .github/workflows/laravel-8.yml rename to .github/workflows/laravel.yml index 5fce019c..64d6f8f8 100644 --- a/.github/workflows/laravel-8.yml +++ b/.github/workflows/laravel.yml @@ -1,4 +1,4 @@ -name: "Laravel 8" +name: "Laravel 7" on: [ push ] jobs: @@ -8,10 +8,16 @@ jobs: strategy: fail-fast: true matrix: + laravel: [ "7.0", "8.0", "9.0", "10.0" ] php: [ "8.0", "8.1" ] - laravel: [ "8.0" ] + excludes: + - laravel: 7.0 + php: 8.1 - name: PHP ${{ matrix.php }} + - laravel: 10 + php: 8.0 + + name: Laravel ${{ matrix.laravel }}, PHP ${{ matrix.php }} steps: - name: Checkout code From 49442c25be16fdbf97c6a3a60d12724f15a78b5b Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Fri, 9 Sep 2022 01:24:18 +0300 Subject: [PATCH 030/153] Update Laravel unit tests --- .github/workflows/laravel.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/laravel.yml b/.github/workflows/laravel.yml index 64d6f8f8..afedb277 100644 --- a/.github/workflows/laravel.yml +++ b/.github/workflows/laravel.yml @@ -34,4 +34,4 @@ jobs: run: composer require --dev laravel/framework:^${{ matrix.laravel }} - name: Execute tests - run: sudo vendor/bin/phpunit + run: sudo vendor/bin/phpunit --ansi From 7e40b14c96902254309b32b7d015778c1d1b3799 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Fri, 9 Sep 2022 01:30:33 +0300 Subject: [PATCH 031/153] Update config file --- config/database.php | 45 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/config/database.php b/config/database.php index 1cda7188..28a7f7c7 100644 --- a/config/database.php +++ b/config/database.php @@ -3,14 +3,49 @@ return [ /* |-------------------------------------------------------------------------- - | Action Repository Table + | Actions Settings |-------------------------------------------------------------------------- | - | This table keeps track of all the migrations that have already run for - | your application. Using this information, we can determine which of - | the migrations on disk haven't actually been run in the database. + | This block controls the connection to the database, as well as the + | location of the action files in the project. | */ - 'actions' => 'migration_actions', + 'actions' => [ + /* + |-------------------------------------------------------------------------- + | Actions Repository Connection + |-------------------------------------------------------------------------- + | + | This option controls the database connection used to store the table + | of executed actions. + | + */ + + 'connection' => env('DB_CONNECTION'), + + /* + |-------------------------------------------------------------------------- + | Actions Repository Table + |-------------------------------------------------------------------------- + | + | This table keeps track of all the actions that have already run for + | your application. Using this information, we can determine which of + | the actions on disk haven't actually been run in the database. + | + */ + + 'table' => 'migration_actions', + + /* + |-------------------------------------------------------------------------- + | Actions Path + |-------------------------------------------------------------------------- + | + | This option defines the path to the action directory. + | + */ + + 'path' => base_path('actions'), + ], ]; From 86f776b8d72c271b38ddc5082f672af7c1e1f4ec Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Fri, 9 Sep 2022 01:37:00 +0300 Subject: [PATCH 032/153] Update ServiceProvider.php --- src/ServiceProvider.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index e86f391f..0b1b2538 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -1,5 +1,7 @@ Date: Fri, 9 Sep 2022 02:00:43 +0300 Subject: [PATCH 033/153] Prepared console commands --- src/Console/Command.php | 32 +++++++---- src/Console/Make.php | 10 +++- src/Console/Migrate.php | 75 ++++---------------------- src/Console/Refresh.php | 101 +++-------------------------------- src/Console/Reset.php | 83 +--------------------------- src/Console/Rollback.php | 63 +++------------------- src/Console/Status.php | 23 +++----- src/Console/Upgrade.php | 4 +- src/Constants/Options.php | 4 +- src/Processors/Processor.php | 15 ++---- 10 files changed, 72 insertions(+), 338 deletions(-) diff --git a/src/Console/Command.php b/src/Console/Command.php index 901eeccd..d4174f57 100644 --- a/src/Console/Command.php +++ b/src/Console/Command.php @@ -4,23 +4,22 @@ namespace DragonCode\LaravelActions\Console; -use DragonCode\LaravelActions\Concerns\Notifications; -use DragonCode\LaravelActions\Concerns\Optionable; -use DragonCode\LaravelActions\Concerns\Path; use DragonCode\LaravelActions\Constants\Options; use DragonCode\LaravelActions\Processors\Processor; +use DragonCode\Support\Facades\Helpers\Arr; use Illuminate\Console\Command as BaseCommand; use Illuminate\Container\Container; use Symfony\Component\Console\Input\InputOption; abstract class Command extends BaseCommand { - use Optionable; - use Notifications; - use Path; - protected Processor|string $processor; + protected array $options = [ + Options::CONNECTION, + Options::FORCE, + ]; + public function handle(): int { if (! $this->confirmToProceed()) { @@ -35,7 +34,9 @@ public function handle(): int protected function resolveProcessor(): Processor { return Container::getInstance()->make($this->processor, [ - 'options' => $this->optionDto(), + 'options' => $this->options(), + 'input' => $this->input, + 'output' => $this->output, ]); } @@ -57,11 +58,22 @@ protected function confirmToProceed(): bool } protected function getOptions(): array + { + return Arr::of($this->availableOptions()) + ->filter(fn (array $option) => in_array($option[0], $this->options)) + ->toArray(); + } + + protected function availableOptions(): array { return [ + [Options::BEFORE, null, InputOption::VALUE_NONE, 'Run actions marked as before'], + [Options::CONNECTION, null, InputOption::VALUE_OPTIONAL, 'The database connection to use'], [Options::FORCE, null, InputOption::VALUE_NONE, 'Force the operation to run when in production'], - - [Options::DATABASE, null, InputOption::VALUE_OPTIONAL, 'The database connection to use'], + [Options::NAME, null, InputOption::VALUE_OPTIONAL, 'The name of the action'], + [Options::PATH, '*', InputOption::VALUE_IS_ARRAY, 'The path(s) to the migrations files to be executed'], + [Options::REALPATH, null, InputOption::VALUE_NONE, 'Indicate any provided migration file paths are pre-resolved absolute paths'], + [Options::STEP, null, InputOption::VALUE_OPTIONAL, 'Force the actions to be run so they can be rolled back individually'], ]; } } diff --git a/src/Console/Make.php b/src/Console/Make.php index b61dbe2e..5c660b78 100644 --- a/src/Console/Make.php +++ b/src/Console/Make.php @@ -3,15 +3,21 @@ namespace DragonCode\LaravelActions\Console; use DragonCode\LaravelActions\Constants\Names; +use DragonCode\LaravelActions\Constants\Options; use DragonCode\LaravelActions\Processors\Make as MakeProcessor; use DragonCode\LaravelActions\Processors\Processor; class Make extends Command { - protected $signature = Names::MAKE - . ' {name? : The name of the action}'; + protected $signature = Names::MAKE; protected $description = 'Create a new action file'; protected Processor|string $processor = MakeProcessor::class; + + protected array $options = [ + Options::CONNECTION, + Options::FORCE, + Options::NAME, + ]; } diff --git a/src/Console/Migrate.php b/src/Console/Migrate.php index fafa6d0f..5c7894e6 100644 --- a/src/Console/Migrate.php +++ b/src/Console/Migrate.php @@ -2,74 +2,21 @@ namespace DragonCode\LaravelActions\Console; -use DragonCode\LaravelActions\Concerns\Database; -use DragonCode\LaravelActions\Concerns\Notifications; -use DragonCode\LaravelActions\Concerns\Optionable; use DragonCode\LaravelActions\Constants\Names; -use Illuminate\Database\Console\Migrations\MigrateCommand as BaseCommand; +use DragonCode\LaravelActions\Constants\Options; -class Migrate extends BaseCommand +class Migrate extends Command { - use Database; - use Notifications; - use Optionable; + protected $signature = Names::MIGRATE; - /** - * The console command name. - * - * @var string - */ - protected $signature = Names::MIGRATE - . ' {--database= : The database connection to use}' - . ' {--force : Force the operation to run when in production}' - . ' {--step : Force the actions to be run so they can be rolled back individually}' - . ' {--path=* : The path(s) to the migrations files to be executed}' - . ' {--realpath : Indicate any provided migration file paths are pre-resolved absolute paths}' - . ' {--before : Run actions marked as before}'; - - /** - * The console command description. - * - * @var string - */ protected $description = 'Run the actions'; - /** - * Execute the console command. - * - * @return int - */ - public function handle() - { - if (! $this->confirmToProceed()) { - return 1; - } - - $this->migrator->usingConnection($this->optionDatabase(), function () { - $this->prepareDatabase(); - - $this->migrator->setOutput($this->output) - ->run($this->getMigrationPaths(), [ - 'step' => $this->optionStep(), - 'before' => $this->optionBefore(), - ]); - }); - - return 0; - } - - /** - * Prepare the action database for running. - */ - protected function prepareDatabase(): void - { - if (! $this->migrator->repositoryExists()) { - $this->call( - Names::INSTALL, - array_filter([ - '--database' => $this->optionDatabase(), - ]) - ); - } - } + protected array $options = [ + Options::BEFORE, + Options::CONNECTION, + Options::FORCE, + Options::PATH, + Options::REALPATH, + Options::STEP, + ]; } diff --git a/src/Console/Refresh.php b/src/Console/Refresh.php index 6c1640d0..a1952136 100644 --- a/src/Console/Refresh.php +++ b/src/Console/Refresh.php @@ -2,105 +2,18 @@ namespace DragonCode\LaravelActions\Console; -use DragonCode\LaravelActions\Concerns\Database; -use DragonCode\LaravelActions\Concerns\Notifications; -use DragonCode\LaravelActions\Concerns\Optionable; use DragonCode\LaravelActions\Constants\Names; -use Illuminate\Console\Command as BaseCommand; -use Illuminate\Console\ConfirmableTrait; -use Illuminate\Contracts\Events\Dispatcher; -use Illuminate\Database\Events\DatabaseRefreshed; -use Symfony\Component\Console\Input\InputOption; +use DragonCode\LaravelActions\Constants\Options; -class Refresh extends BaseCommand +class Refresh extends Command { - use ConfirmableTrait; - use Database; - use Notifications; - use Optionable; - - /** - * The console command name. - * - * @var string - */ protected $name = Names::REFRESH; - /** - * The console command description. - * - * @var string - */ protected $description = 'Reset and re-run all actions'; - public function handle() - { - if (! $this->confirmToProceed()) { - return 1; - } - - $database = $this->optionDatabase(); - $step = $this->optionStep(0); - - $step > 0 - ? $this->runRollback($database, $step) - : $this->runReset($database); - - $this->call(Names::MIGRATE, array_filter([ - '--database' => $database, - '--force' => true, - ])); - - if ($this->laravel->bound(Dispatcher::class) && class_exists(DatabaseRefreshed::class)) { - $this->laravel[Dispatcher::class]->dispatch( - new DatabaseRefreshed() - ); - } - - return 0; - } - - /** - * Run the rollback command. - * - * @param string|null $database - * @param int|null $step - */ - protected function runRollback(?string $database, ?int $step) - { - $this->call(Names::ROLLBACK, array_filter([ - '--database' => $database, - '--step' => $step, - '--force' => true, - ])); - } - - /** - * Run the reset command. - * - * @param string|null $database - */ - protected function runReset(?string $database) - { - $this->call(Names::RESET, array_filter([ - '--database' => $database, - '--force' => true, - ])); - } - - /** - * Get the console command options. - * - * @return array - */ - protected function getOptions(): array - { - return [ - ['database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use'], - - ['force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production'], - - ['step', null, InputOption::VALUE_OPTIONAL, 'The number of actions to be reverted & re-run'], - ]; - } + protected array $options = [ + Options::CONNECTION, + Options::FORCE, + Options::STEP, + ]; } diff --git a/src/Console/Reset.php b/src/Console/Reset.php index dc306c28..e8b29aaf 100644 --- a/src/Console/Reset.php +++ b/src/Console/Reset.php @@ -2,92 +2,11 @@ namespace DragonCode\LaravelActions\Console; -use DragonCode\LaravelActions\Concerns\Database; -use DragonCode\LaravelActions\Concerns\Notifications; -use DragonCode\LaravelActions\Concerns\Optionable; use DragonCode\LaravelActions\Constants\Names; -use DragonCode\LaravelActions\Support\Migrator; -use Illuminate\Console\ConfirmableTrait; -use Illuminate\Database\Console\Migrations\BaseCommand; -use Symfony\Component\Console\Input\InputOption; -class Reset extends BaseCommand +class Reset extends Command { - use ConfirmableTrait; - use Database; - use Notifications; - use Optionable; - - /** - * The console command name. - * - * @var string - */ protected $name = Names::RESET; - /** - * The console command description. - * - * @var string - */ protected $description = 'Rollback all database actions'; - - /** - * The migrator instance. - * - * @var \DragonCode\LaravelActions\Support\Migrator - */ - protected $migrator; - - /** - * Create a new migration rollback command instance. - * - * @param \DragonCode\LaravelActions\Support\Migrator $migrator - */ - public function __construct(Migrator $migrator) - { - parent::__construct(); - - $this->migrator = $migrator; - } - - /** - * Execute the console command. - * - * @return int|void - */ - public function handle() - { - if (! $this->confirmToProceed()) { - return 1; - } - - return $this->migrator->usingConnection($this->optionDatabase(), function () { - if (! $this->migrator->repositoryExists()) { - $this->comment('Actions table not found.'); - - return 1; - } - - $this->migrator->setOutput($this->output)->reset( - $this->getMigrationPaths() - ); - - return 0; - }); - } - - /** - * Get the console command options. - * - * @return array - */ - protected function getOptions(): array - { - return [ - ['database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use'], - - ['force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production'], - ]; - } } diff --git a/src/Console/Rollback.php b/src/Console/Rollback.php index ff8ad6c9..2b6a3123 100644 --- a/src/Console/Rollback.php +++ b/src/Console/Rollback.php @@ -2,67 +2,18 @@ namespace DragonCode\LaravelActions\Console; -use DragonCode\LaravelActions\Concerns\Database; -use DragonCode\LaravelActions\Concerns\Notifications; -use DragonCode\LaravelActions\Concerns\Optionable; use DragonCode\LaravelActions\Constants\Names; -use Illuminate\Database\Console\Migrations\RollbackCommand; -use Symfony\Component\Console\Input\InputOption; +use DragonCode\LaravelActions\Constants\Options; -class Rollback extends RollbackCommand +class Rollback extends Command { - use Database; - use Notifications; - use Optionable; - - /** - * The console command name. - * - * @var string - */ protected $name = Names::ROLLBACK; - /** - * The console command description. - * - * @var string - */ protected $description = 'Rollback the last database action'; - /** - * Execute the console command. - * - * @return int - */ - public function handle() - { - if (! $this->confirmToProceed()) { - return 1; - } - - $this->migrator->usingConnection($this->optionDatabase(), function () { - $this->migrator->setOutput($this->output)->rollback( - $this->getMigrationPaths(), - ['step' => $this->optionStep()] - ); - }); - - return 0; - } - - /** - * Get the console command options. - * - * @return array - */ - protected function getOptions() - { - return [ - ['database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use'], - - ['force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production'], - - ['step', null, InputOption::VALUE_OPTIONAL, 'The number of actions to be reverted'], - ]; - } + protected array $options = [ + Options::CONNECTION, + Options::FORCE, + Options::STEP, + ]; } diff --git a/src/Console/Status.php b/src/Console/Status.php index 18e5c0a3..c6c764b9 100644 --- a/src/Console/Status.php +++ b/src/Console/Status.php @@ -2,29 +2,18 @@ namespace DragonCode\LaravelActions\Console; -use DragonCode\LaravelActions\Concerns\Database; -use DragonCode\LaravelActions\Concerns\Notifications; -use DragonCode\LaravelActions\Concerns\Optionable; use DragonCode\LaravelActions\Constants\Names; +use DragonCode\LaravelActions\Constants\Options; use Illuminate\Database\Console\Migrations\StatusCommand as BaseCommand; class Status extends BaseCommand { - use Database; - use Notifications; - use Optionable; - - /** - * The console command name. - * - * @var string - */ protected $name = Names::STATUS; - /** - * The console command description. - * - * @var string - */ protected $description = 'Show the status of each action'; + + protected array $options = [ + Options::CONNECTION, + Options::BEFORE, + ]; } diff --git a/src/Console/Upgrade.php b/src/Console/Upgrade.php index d56debd9..ffee6fea 100644 --- a/src/Console/Upgrade.php +++ b/src/Console/Upgrade.php @@ -5,8 +5,8 @@ namespace DragonCode\LaravelActions\Console; use DragonCode\LaravelActions\Constants\Names; -use DragonCode\LaravelActions\Processors\Install as InstallProcessor; use DragonCode\LaravelActions\Processors\Processor; +use DragonCode\LaravelActions\Processors\Upgrade as UpgradeProcessor; class Upgrade extends Command { @@ -14,5 +14,5 @@ class Upgrade extends Command protected $description = 'Action structure upgrade from version 2 to 3'; - protected Processor|string $processor = InstallProcessor::class; + protected Processor|string $processor = UpgradeProcessor::class; } diff --git a/src/Constants/Options.php b/src/Constants/Options.php index b0b87bd4..c7e9ebcf 100644 --- a/src/Constants/Options.php +++ b/src/Constants/Options.php @@ -8,10 +8,12 @@ class Options { public const BEFORE = 'before'; - public const DATABASE = 'database'; + public const CONNECTION = 'database'; public const FORCE = 'force'; + public const NAME = 'name'; + public const PATH = 'path'; public const REALPATH = 'realpath'; diff --git a/src/Processors/Processor.php b/src/Processors/Processor.php index 9ed2015d..69fb4ffb 100644 --- a/src/Processors/Processor.php +++ b/src/Processors/Processor.php @@ -5,24 +5,19 @@ namespace DragonCode\LaravelActions\Processors; use DragonCode\LaravelActions\Concerns\Artisan; -use DragonCode\LaravelActions\Concerns\Database; -use DragonCode\LaravelActions\Concerns\Notifications; -use DragonCode\LaravelActions\Repositories\ActionRepository; -use DragonCode\LaravelActions\Values\Options; -use Illuminate\Filesystem\Filesystem; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; abstract class Processor { use Artisan; - use Database; - use Notifications; abstract public function handle(); public function __construct( - protected Options $options, - protected Filesystem $files, - protected ActionRepository $repository + protected array $options, + protected InputInterface $input, + protected OutputInterface $output ) { } } From 8fa678521a6c2ba68847e8652645ac4de4b56cf9 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Fri, 9 Sep 2022 22:57:11 +0300 Subject: [PATCH 034/153] Update Optionable.php --- src/Concerns/Optionable.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/Concerns/Optionable.php b/src/Concerns/Optionable.php index a24aee67..977b1151 100644 --- a/src/Concerns/Optionable.php +++ b/src/Concerns/Optionable.php @@ -19,9 +19,14 @@ protected function optionBefore(): bool return $this->option(Options::BEFORE); } - protected function optionDatabase(): ?string + protected function optionConnection(): ?string { - return $this->option(Options::DATABASE); + return $this->option(Options::CONNECTION); + } + + protected function optionName(): ?string + { + return $this->option(Options::NAME); } protected function optionStep(?int $default = null): ?int @@ -54,11 +59,6 @@ protected function optionPath(): ?array return null; } - /** - * Determine if the given path(s) are pre-resolved "real" paths. - * - * @return bool - */ protected function usingRealPath(): bool { return $this->optionHas(Options::REALPATH); @@ -73,8 +73,9 @@ protected function optionDto(): OptionsDto { return OptionsDto::make([ 'before' => $this->optionBefore(), - 'database' => $this->optionDatabase(), + 'database' => $this->optionConnection(), 'force' => $this->optionForce(), + 'name' => $this->optionName(), 'path' => $this->optionPath(), 'realpath' => $this->usingRealPath(), 'step' => $this->optionStep(), From 49ca8944f31c2df8d5f072834f0e1a77328a529e Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Fri, 9 Sep 2022 22:57:21 +0300 Subject: [PATCH 035/153] Update console commands --- src/Console/Command.php | 2 +- src/Console/Migrate.php | 4 ++++ src/Console/Refresh.php | 4 ++++ src/Console/Reset.php | 4 ++++ src/Console/Rollback.php | 4 ++++ src/Console/Status.php | 7 +++++-- 6 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/Console/Command.php b/src/Console/Command.php index d4174f57..b8654781 100644 --- a/src/Console/Command.php +++ b/src/Console/Command.php @@ -46,7 +46,7 @@ protected function confirmToProceed(): bool return true; } - $this->warn('Application in production'); + $this->warn('Application in production!'); if ($this->confirm('Do you really wish to run this command?')) { return true; diff --git a/src/Console/Migrate.php b/src/Console/Migrate.php index 5c7894e6..234b4a52 100644 --- a/src/Console/Migrate.php +++ b/src/Console/Migrate.php @@ -4,6 +4,8 @@ use DragonCode\LaravelActions\Constants\Names; use DragonCode\LaravelActions\Constants\Options; +use DragonCode\LaravelActions\Processors\Migrate as MigrateProcessor; +use DragonCode\LaravelActions\Processors\Processor; class Migrate extends Command { @@ -11,6 +13,8 @@ class Migrate extends Command protected $description = 'Run the actions'; + protected Processor|string $processor = MigrateProcessor::class; + protected array $options = [ Options::BEFORE, Options::CONNECTION, diff --git a/src/Console/Refresh.php b/src/Console/Refresh.php index a1952136..64d97914 100644 --- a/src/Console/Refresh.php +++ b/src/Console/Refresh.php @@ -4,6 +4,8 @@ use DragonCode\LaravelActions\Constants\Names; use DragonCode\LaravelActions\Constants\Options; +use DragonCode\LaravelActions\Processors\Processor; +use DragonCode\LaravelActions\Processors\Refresh as RefreshProcessor; class Refresh extends Command { @@ -11,6 +13,8 @@ class Refresh extends Command protected $description = 'Reset and re-run all actions'; + protected Processor|string $processor = RefreshProcessor::class; + protected array $options = [ Options::CONNECTION, Options::FORCE, diff --git a/src/Console/Reset.php b/src/Console/Reset.php index e8b29aaf..bcd38f19 100644 --- a/src/Console/Reset.php +++ b/src/Console/Reset.php @@ -3,10 +3,14 @@ namespace DragonCode\LaravelActions\Console; use DragonCode\LaravelActions\Constants\Names; +use DragonCode\LaravelActions\Processors\Processor; +use DragonCode\LaravelActions\Processors\Reset as ResetProcessor; class Reset extends Command { protected $name = Names::RESET; protected $description = 'Rollback all database actions'; + + protected Processor|string $processor = ResetProcessor::class; } diff --git a/src/Console/Rollback.php b/src/Console/Rollback.php index 2b6a3123..8ff2c8e7 100644 --- a/src/Console/Rollback.php +++ b/src/Console/Rollback.php @@ -4,6 +4,8 @@ use DragonCode\LaravelActions\Constants\Names; use DragonCode\LaravelActions\Constants\Options; +use DragonCode\LaravelActions\Processors\Processor; +use DragonCode\LaravelActions\Processors\Rollback as RollbackProcessor; class Rollback extends Command { @@ -11,6 +13,8 @@ class Rollback extends Command protected $description = 'Rollback the last database action'; + protected Processor|string $processor = RollbackProcessor::class; + protected array $options = [ Options::CONNECTION, Options::FORCE, diff --git a/src/Console/Status.php b/src/Console/Status.php index c6c764b9..f0447b08 100644 --- a/src/Console/Status.php +++ b/src/Console/Status.php @@ -4,14 +4,17 @@ use DragonCode\LaravelActions\Constants\Names; use DragonCode\LaravelActions\Constants\Options; -use Illuminate\Database\Console\Migrations\StatusCommand as BaseCommand; +use DragonCode\LaravelActions\Processors\Processor; +use DragonCode\LaravelActions\Processors\Status as StatusProcessor; -class Status extends BaseCommand +class Status extends Command { protected $name = Names::STATUS; protected $description = 'Show the status of each action'; + protected Processor|string $processor = StatusProcessor::class; + protected array $options = [ Options::CONNECTION, Options::BEFORE, From 463bf1b169b262cac55512220b0d4af54f54d168 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Fri, 9 Sep 2022 22:57:32 +0300 Subject: [PATCH 036/153] Added Config helper --- src/Helpers/Config.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/Helpers/Config.php diff --git a/src/Helpers/Config.php b/src/Helpers/Config.php new file mode 100644 index 00000000..9cc4a6d5 --- /dev/null +++ b/src/Helpers/Config.php @@ -0,0 +1,25 @@ + Date: Fri, 9 Sep 2022 22:57:50 +0300 Subject: [PATCH 037/153] Update Processors --- src/Processors/Fresh.php | 25 ++++++++++--------------- src/Processors/Install.php | 20 ++++++++++++++++++-- src/Processors/Make.php | 21 --------------------- src/Processors/Migrate.php | 9 +++++++++ src/Processors/Processor.php | 27 +++++++++++++++++++++++---- src/Processors/Refresh.php | 9 +++++++++ src/Processors/Reset.php | 9 +++++++++ src/Processors/Rollback.php | 9 +++++++++ src/Processors/Status.php | 9 +++++++++ src/Processors/Upgrade.php | 9 +++++++++ 10 files changed, 105 insertions(+), 42 deletions(-) create mode 100644 src/Processors/Migrate.php create mode 100644 src/Processors/Refresh.php create mode 100644 src/Processors/Reset.php create mode 100644 src/Processors/Rollback.php create mode 100644 src/Processors/Status.php create mode 100644 src/Processors/Upgrade.php diff --git a/src/Processors/Fresh.php b/src/Processors/Fresh.php index 6a626672..7b47f394 100644 --- a/src/Processors/Fresh.php +++ b/src/Processors/Fresh.php @@ -9,31 +9,26 @@ class Fresh extends Processor { - public function handle() + public function handle(): void { $this->drop(); - $this->migrate(); + $this->create(); } protected function drop(): void { - $this->repository->deleteRepository(); + if ($this->repository->repositoryExists()) { + $this->repository->deleteRepository(); - $this->notification()->info('Action table deleted successfully.'); + $this->notification->info('Actions repository successfully deleted.'); + } } - protected function migrate(): void + protected function create(): void { - $this->artisan(Names::MIGRATE, $this->getMigrateParams()); - - $this->notification()->info('Migration table created successfully.'); - } - - protected function getMigrateParams(): array - { - return array_filter([ - '--' . Options::DATABASE => $this->options->database, - '--' . Options::FORCE => true, + $this->artisan(Names::INSTALL, [ + '--' . Options::CONNECTION => $this->options->connection, + '--' . Options::FORCE => $this->options->force, ]); } } diff --git a/src/Processors/Install.php b/src/Processors/Install.php index c048df03..ba118424 100644 --- a/src/Processors/Install.php +++ b/src/Processors/Install.php @@ -6,10 +6,26 @@ class Install extends Processor { - public function handle() + public function handle(): void + { + if ($this->exists()) { + $this->notification->warning('Action repository already exists.'); + + return; + } + + $this->create(); + } + + protected function exists(): bool + { + return $this->repository->repositoryExists(); + } + + protected function create(): void { $this->repository->createRepository(); - $this->notification()->info('Actions table created successfully.'); + $this->notification->info('Action repository successfully created.'); } } diff --git a/src/Processors/Make.php b/src/Processors/Make.php index 2057b033..8d70f13d 100644 --- a/src/Processors/Make.php +++ b/src/Processors/Make.php @@ -4,27 +4,6 @@ namespace DragonCode\LaravelActions\Processors; -use DragonCode\LaravelActions\Concerns\Composer; -use DragonCode\Support\Facades\Filesystem\File; -use DragonCode\Support\Facades\Helpers\Str; - class Make extends Processor { - use Composer; - - public function handle() - { - $this->writeMigration( - Str::snake($this->options->name) - ); - - $this->composer()->dumpAutoloads(); - } - - protected function writeMigration(string $name) - { - File::copy(__DIR__ . '/../../resources/stubs/action.stub', base_path('actions/' . $name)); - - $this->notification()->info("Created Action: $name"); - } } diff --git a/src/Processors/Migrate.php b/src/Processors/Migrate.php new file mode 100644 index 00000000..6a705ad1 --- /dev/null +++ b/src/Processors/Migrate.php @@ -0,0 +1,9 @@ +bootNotification($this->output); + } + + protected function bootNotification(OutputInterface $output): Notification + { + $this->notification = class_exists(Factory::class) + ? new Beautiful($output) + : new Basic($output); } } diff --git a/src/Processors/Refresh.php b/src/Processors/Refresh.php new file mode 100644 index 00000000..7bbeaa68 --- /dev/null +++ b/src/Processors/Refresh.php @@ -0,0 +1,9 @@ + Date: Fri, 9 Sep 2022 22:58:16 +0300 Subject: [PATCH 038/153] Removed unnecessary processor --- src/Processors/Creator.php | 42 -------------------------------------- 1 file changed, 42 deletions(-) delete mode 100644 src/Processors/Creator.php diff --git a/src/Processors/Creator.php b/src/Processors/Creator.php deleted file mode 100644 index e68f015a..00000000 --- a/src/Processors/Creator.php +++ /dev/null @@ -1,42 +0,0 @@ -ensureExists(); - } - - protected function create(string $name, string $path): void - { - $this->files->copy( - $this->getStub('action.stub'), - $this->getTargetFilename($name, $path) - ); - } - - protected function ensureExists(): void - { - $this->files->ensureDirectoryExists($this->getStub()); - } - - protected function getStub(?string $name = null): string - { - return __DIR__ . '/../../resources/stubs/' . $name; - } - - protected function getTargetFilename(string $name, string $path): string - { - return Str::of($name) - ->trim() - ->slug('_') - ->prepend(rtrim($path, '\\/') . '/') - ->toString(); - } -} From 95cab58b9cc9a80099e77d48681f303a3ed7111c Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Fri, 9 Sep 2022 22:58:26 +0300 Subject: [PATCH 039/153] Updated ActionRepository.php --- src/Repositories/ActionRepository.php | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/Repositories/ActionRepository.php b/src/Repositories/ActionRepository.php index 59c657bf..fef1b7b9 100644 --- a/src/Repositories/ActionRepository.php +++ b/src/Repositories/ActionRepository.php @@ -4,7 +4,7 @@ namespace DragonCode\LaravelActions\Repositories; -use DragonCode\LaravelActions\Concerns\Database; +use DragonCode\LaravelActions\Helpers\Config; use Illuminate\Database\ConnectionInterface; use Illuminate\Database\ConnectionResolverInterface as Resolver; use Illuminate\Database\Query\Builder as Query; @@ -13,10 +13,9 @@ class ActionRepository { - use Database; - public function __construct( - protected Resolver $resolver + protected Resolver $resolver, + protected Config $config ) { } @@ -50,7 +49,7 @@ public function getNextBatchNumber(): int public function getLastBatchNumber(): int { - return $this->table()->max('batch') ?: 0; + return (int) $this->table()->max('batch'); } public function log(string $action, int $batch): void @@ -65,7 +64,7 @@ public function delete(string $action): void public function createRepository(): void { - $this->schema()->create($this->getTableName(), function (Blueprint $table) { + $this->schema()->create($this->config->table(), function (Blueprint $table) { $table->id(); $table->string('action'); @@ -76,12 +75,12 @@ public function createRepository(): void public function repositoryExists(): bool { - return $this->schema()->hasTable($this->getTableName()); + return $this->schema()->hasTable($this->config->table()); } public function deleteRepository(): void { - $this->schema()->dropIfExists($this->getTableName()); + $this->schema()->dropIfExists($this->config->table()); } protected function getOrderTable(string $order = 'asc'): Query @@ -98,11 +97,13 @@ protected function schema(): Builder protected function getConnection(): ConnectionInterface { - return $this->resolver->connection(); + return $this->resolver->connection( + $this->config->connection() + ); } protected function table(): Query { - return $this->getConnection()->table($this->getTableName())->useWritePdo(); + return $this->getConnection()->table($this->config->table())->useWritePdo(); } } From 4f9cfef782ab3653830b66c3da92f2fee3787c93 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Fri, 9 Sep 2022 23:00:27 +0300 Subject: [PATCH 040/153] Updated `Actionable.php` and was renamed to `Action.php` --- src/{Services/Actionable.php => Action.php} | 16 ++++++++-------- .../app/actions/2020_12_07_153105_foo_bar.php | 4 ++-- .../app/actions/2021_01_02_020947_every_time.php | 6 +++--- .../app/actions/2021_05_24_120003_run_on_all.php | 4 ++-- ...021_05_24_120003_run_on_many_environments.php | 6 +++--- .../2021_05_24_120003_run_on_production.php | 6 +++--- .../actions/2021_05_24_120003_run_on_testing.php | 6 +++--- .../2021_06_07_132849_run_except_production.php | 6 +++--- .../2021_06_07_132917_run_except_testing.php | 6 +++--- ...06_07_134045_run_except_many_environments.php | 8 ++++---- .../app/actions/2021_10_26_143247_run_allow.php | 4 ++-- .../actions/2021_10_26_143304_run_disallow.php | 4 ++-- .../actions/2021_12_23_165047_run_success.php | 4 ++-- .../app/actions/2021_12_23_184029_run_failed.php | 4 ++-- .../2022_08_17_135147_test_before_enabled.php | 6 +++--- .../2022_08_17_135153_test_before_disabled.php | 6 +++--- .../actions/sub_path/2021_12_15_205804_baz.php | 4 ++-- .../2021_12_23_165048_run_success_on_failed.php | 4 ++-- .../2021_12_23_184029_run_failed_failure.php | 4 ++-- 19 files changed, 54 insertions(+), 54 deletions(-) rename src/{Services/Actionable.php => Action.php} (88%) diff --git a/src/Services/Actionable.php b/src/Action.php similarity index 88% rename from src/Services/Actionable.php rename to src/Action.php index d3038cad..dd7741a1 100644 --- a/src/Services/Actionable.php +++ b/src/Action.php @@ -1,13 +1,13 @@ Date: Fri, 9 Sep 2022 23:06:10 +0300 Subject: [PATCH 041/153] Update Git.php --- src/Helpers/Config.php | 5 ++++ src/Helpers/Git.php | 38 ++++++++++++++++++++++++++ src/Support/Git.php | 60 ------------------------------------------ 3 files changed, 43 insertions(+), 60 deletions(-) create mode 100644 src/Helpers/Git.php delete mode 100644 src/Support/Git.php diff --git a/src/Helpers/Config.php b/src/Helpers/Config.php index 9cc4a6d5..f2155789 100644 --- a/src/Helpers/Config.php +++ b/src/Helpers/Config.php @@ -22,4 +22,9 @@ public function path(?string $path = null): string return rtrim($directory, '\\/') . DIRECTORY_SEPARATOR . ltrim((string) $path, '\\/'); } + + public function gitPath(): string + { + return base_path(); + } } diff --git a/src/Helpers/Git.php b/src/Helpers/Git.php new file mode 100644 index 00000000..b2a3de03 --- /dev/null +++ b/src/Helpers/Git.php @@ -0,0 +1,38 @@ +hasGitDirectory()) { + return $this->exec('rev-parse --abbrev-ref HEAD'); + } + + return null; + } + + protected function exec(string $command): ?string + { + return exec(sprintf('git --git-dir %s %s', $this->config->gitPath(), $command)); + } + + protected function hasGitDirectory(): bool + { + if ($path = rtrim($this->config->gitPath(), '/\\')) { + return Directory::exists($path . DIRECTORY_SEPARATOR . '.git'); + } + + return false; + } +} diff --git a/src/Support/Git.php b/src/Support/Git.php deleted file mode 100644 index c2f66d62..00000000 --- a/src/Support/Git.php +++ /dev/null @@ -1,60 +0,0 @@ -getGitPath($path)) { - return $this->exec($path, 'rev-parse --abbrev-ref HEAD'); - } - - return null; - } - - protected function exec(string $path, string $command): ?string - { - return exec(sprintf('git --git-dir %s %s', $path, $command)); - } - - protected function getGitPath(?string $path): ?string - { - if ($path = $this->resolvePath($path)) { - if ($this->isGitDir($path)) { - return $path; - } - } - - return null; - } - - protected function isGitDir(?string $path): bool - { - if ($path = rtrim($path, '/\\')) { - return Directory::exists($path . DIRECTORY_SEPARATOR . '.git'); - } - - return false; - } - - protected function resolvePath(string $path): ?string - { - if ($path = realpath($path)) { - $path = rtrim($path, '\\/'); - - return Str::endsWith($path, '.git') ? Path::dirname($path) : $path; - } - - return null; - } -} From 3eee78118bab26642f04ff23fc9050c2964d45bd Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Fri, 9 Sep 2022 23:08:01 +0300 Subject: [PATCH 042/153] Removed unnecessary classes --- src/Concerns/Composer.php | 22 ------------- src/Concerns/Database.php | 11 ------- src/Concerns/Notifications.php | 24 -------------- src/Concerns/Path.php | 11 ------- src/Database/BaseChangeMigrationColumn.php | 33 ------------------- src/Support/MigrationCreator.php | 37 ---------------------- 6 files changed, 138 deletions(-) delete mode 100644 src/Concerns/Composer.php delete mode 100644 src/Concerns/Database.php delete mode 100644 src/Concerns/Notifications.php delete mode 100644 src/Concerns/Path.php delete mode 100644 src/Database/BaseChangeMigrationColumn.php delete mode 100644 src/Support/MigrationCreator.php diff --git a/src/Concerns/Composer.php b/src/Concerns/Composer.php deleted file mode 100644 index 00a657f3..00000000 --- a/src/Concerns/Composer.php +++ /dev/null @@ -1,22 +0,0 @@ -composer)) { - return $this->composer; - } - - return $this->composer = Container::getInstance()->make(IlluminateComposer::class); - } -} diff --git a/src/Concerns/Database.php b/src/Concerns/Database.php deleted file mode 100644 index c05bee9c..00000000 --- a/src/Concerns/Database.php +++ /dev/null @@ -1,11 +0,0 @@ -notification)) { - return $this->notification; - } - - return $this->notification = class_exists(Factory::class) - ? new Beautiful($this->output) - : new Basic($this->output); - } -} diff --git a/src/Concerns/Path.php b/src/Concerns/Path.php deleted file mode 100644 index f37ad215..00000000 --- a/src/Concerns/Path.php +++ /dev/null @@ -1,11 +0,0 @@ -getTableName(), function (Blueprint $table) { - $table->renameColumn('migration', 'action'); - - $table->unsignedInteger('batch')->change(); - }); - } - - public function down() - { - Schema::table($this->getTableName(), function (Blueprint $table) { - $table->renameColumn('action', 'migration'); - - $table->integer('batch')->change(); - }); - } -} diff --git a/src/Support/MigrationCreator.php b/src/Support/MigrationCreator.php deleted file mode 100644 index 93fa723e..00000000 --- a/src/Support/MigrationCreator.php +++ /dev/null @@ -1,37 +0,0 @@ -customStubPath = $custom_stub_path; - } - - public function create($name, $path, $table = null, $create = false) - { - $this->files->ensureDirectoryExists($path); - - return parent::create($name, $path, $table, $create); - } - - public function stubPath() - { - return realpath($this->customStubPath); - } - - protected function getStub($table, $create): string - { - return $this->files->get( - $this->stubPath() . '/action.stub' - ); - } -} From 40d842569dd02116e1579dad90924608d715dc44 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Fri, 9 Sep 2022 23:08:12 +0300 Subject: [PATCH 043/153] Revert tests --- tests/Services/GitTest.php | 2 +- tests/TestCase.php | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/Services/GitTest.php b/tests/Services/GitTest.php index b93e0d5e..9457a321 100644 --- a/tests/Services/GitTest.php +++ b/tests/Services/GitTest.php @@ -4,7 +4,7 @@ namespace Tests\Services; -use DragonCode\LaravelActions\Support\Git; +use DragonCode\LaravelActions\Helpers\Git; use Tests\TestCase; class GitTest extends TestCase diff --git a/tests/TestCase.php b/tests/TestCase.php index bb044df2..a173bd63 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -2,7 +2,6 @@ namespace Tests; -use DragonCode\LaravelActions\Concerns\Path; use DragonCode\LaravelActions\Concerns\Anonymouses; use DragonCode\LaravelActions\ServiceProvider; use Illuminate\Database\Query\Builder; @@ -18,7 +17,6 @@ abstract class TestCase extends BaseTestCase use AssertDatabase; use Database; use Files; - use Path; use RefreshDatabase; use Anonymouses; From 9f30f95acb498ca60fcfa38c462c626ac64c6f71 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Fri, 9 Sep 2022 23:10:00 +0300 Subject: [PATCH 044/153] WOW! Added Laravel 6 support --- .github/workflows/laravel.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/laravel.yml b/.github/workflows/laravel.yml index afedb277..365e9dac 100644 --- a/.github/workflows/laravel.yml +++ b/.github/workflows/laravel.yml @@ -8,9 +8,12 @@ jobs: strategy: fail-fast: true matrix: - laravel: [ "7.0", "8.0", "9.0", "10.0" ] + laravel: [ "6.0", "7.0", "8.0", "9.0", "10.0" ] php: [ "8.0", "8.1" ] excludes: + - laravel: 6.0 + php: 8.1 + - laravel: 7.0 php: 8.1 From f7631e321a6aa2c8a327a56d606a0b96c88a7cb5 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Fri, 9 Sep 2022 23:11:26 +0300 Subject: [PATCH 045/153] Update GitHub Actions --- .github/workflows/laravel.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/laravel.yml b/.github/workflows/laravel.yml index 365e9dac..f5623548 100644 --- a/.github/workflows/laravel.yml +++ b/.github/workflows/laravel.yml @@ -11,14 +11,14 @@ jobs: laravel: [ "6.0", "7.0", "8.0", "9.0", "10.0" ] php: [ "8.0", "8.1" ] excludes: - - laravel: 6.0 - php: 8.1 + - laravel: "6.0" + php: "8.1" - - laravel: 7.0 - php: 8.1 + - laravel: "7.0" + php: "8.1" - - laravel: 10 - php: 8.0 + - laravel: "10.0" + php: "8.0" name: Laravel ${{ matrix.laravel }}, PHP ${{ matrix.php }} From a48744422a5d06c23a2f0d51d07ddb5b2bf5fdcc Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Fri, 9 Sep 2022 23:12:09 +0300 Subject: [PATCH 046/153] Update GitHub Actions --- .github/workflows/laravel.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/laravel.yml b/.github/workflows/laravel.yml index f5623548..759fd47c 100644 --- a/.github/workflows/laravel.yml +++ b/.github/workflows/laravel.yml @@ -1,4 +1,4 @@ -name: "Laravel 7" +name: laravel on: [ push ] jobs: @@ -20,7 +20,7 @@ jobs: - laravel: "10.0" php: "8.0" - name: Laravel ${{ matrix.laravel }}, PHP ${{ matrix.php }} + name: ${{ matrix.laravel }}, php ${{ matrix.php }} steps: - name: Checkout code From 782de6edb7c356ecac22abad42830761151cad05 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Fri, 9 Sep 2022 23:12:33 +0300 Subject: [PATCH 047/153] Update GitHub Actions --- .github/workflows/laravel.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/laravel.yml b/.github/workflows/laravel.yml index 759fd47c..21bd758d 100644 --- a/.github/workflows/laravel.yml +++ b/.github/workflows/laravel.yml @@ -20,7 +20,7 @@ jobs: - laravel: "10.0" php: "8.0" - name: ${{ matrix.laravel }}, php ${{ matrix.php }} + name: Laravel ${{ matrix.laravel }}, PHP ${{ matrix.php }} steps: - name: Checkout code From bfda647e6d07742053c63d4b84559fb3f4531a47 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Fri, 9 Sep 2022 23:13:21 +0300 Subject: [PATCH 048/153] Fixed exclude matrix actions --- .github/workflows/laravel.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/laravel.yml b/.github/workflows/laravel.yml index 21bd758d..a0ab65f8 100644 --- a/.github/workflows/laravel.yml +++ b/.github/workflows/laravel.yml @@ -10,7 +10,7 @@ jobs: matrix: laravel: [ "6.0", "7.0", "8.0", "9.0", "10.0" ] php: [ "8.0", "8.1" ] - excludes: + exclude: - laravel: "6.0" php: "8.1" From 9685ceb481988f420f26e95a7a0182580531bac2 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Fri, 9 Sep 2022 23:15:34 +0300 Subject: [PATCH 049/153] Update composer.json --- composer.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index cf495441..ab6b3721 100644 --- a/composer.json +++ b/composer.json @@ -31,15 +31,15 @@ "dragon-code/laravel-support": "^3.4", "dragon-code/simple-dto": "^2.3", "dragon-code/support": "^6.3", - "illuminate/console": "^7.0 || ^8.0 || ^9.0 || ^10.0", - "illuminate/container": "^7.0 || ^8.0 || ^9.0 || ^10.0", - "illuminate/database": "^7.0 || ^8.0 || ^9.0 || ^10.0", - "illuminate/support": "^7.0 || ^8.0 || ^9.0 || ^10.0", - "symfony/console": "^5.0 || ^6.0" + "illuminate/console": "^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0", + "illuminate/container": "^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0", + "illuminate/database": "^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0", + "illuminate/support": "^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0", + "symfony/console": "^4.0 || ^5.0 || ^6.0" }, "require-dev": { "mockery/mockery": "^1.3.1", - "orchestra/testbench": "^5.0 || ^6.0 || ^7.0 || ^8.0", + "orchestra/testbench": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0", "phpunit/phpunit": "^9.5", "ramsey/uuid": "^3.7 || ^4.0" }, From ae3ba62526daabec5fb6b71f36d61fc4401ea694 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Fri, 9 Sep 2022 23:16:25 +0300 Subject: [PATCH 050/153] Update laravel.yml --- .github/workflows/laravel.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/laravel.yml b/.github/workflows/laravel.yml index a0ab65f8..6cf56916 100644 --- a/.github/workflows/laravel.yml +++ b/.github/workflows/laravel.yml @@ -37,4 +37,4 @@ jobs: run: composer require --dev laravel/framework:^${{ matrix.laravel }} - name: Execute tests - run: sudo vendor/bin/phpunit --ansi + run: sudo vendor/bin/phpunit From 907dfd1242df707d24dd490ee22f5376262b5a27 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Thu, 15 Sep 2022 23:22:22 +0300 Subject: [PATCH 051/153] Added BaseChangeMigrationColumn --- composer.json | 1 + src/Database/BaseChangeMigrationColumn.php | 50 ++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 src/Database/BaseChangeMigrationColumn.php diff --git a/composer.json b/composer.json index ab6b3721..dfd86d3a 100644 --- a/composer.json +++ b/composer.json @@ -27,6 +27,7 @@ "require": { "php": "^8.0", "composer-runtime-api": "^2.2", + "doctrine/dbal": "^2.13 || ^3.4", "dragon-code/contracts": "^2.15", "dragon-code/laravel-support": "^3.4", "dragon-code/simple-dto": "^2.3", diff --git a/src/Database/BaseChangeMigrationColumn.php b/src/Database/BaseChangeMigrationColumn.php new file mode 100644 index 00000000..5bf1ba99 --- /dev/null +++ b/src/Database/BaseChangeMigrationColumn.php @@ -0,0 +1,50 @@ +hasTable()) { + Schema::table($this->table(), function (Blueprint $table) { + $table->renameColumn('migration', 'action'); + + $table->unsignedInteger('batch')->change(); + }); + } + } + + public function down(): void + { + if ($this->hasTable()) { + Schema::table($this->table(), function (Blueprint $table) { + $table->renameColumn('action', 'migration'); + + $table->integer('batch')->change(); + }); + } + } + + protected function hasTable(): bool + { + return Schema::hasTable($this->table()); + } + + protected function table(): string + { + return $this->config->table(); + } +} From 6f127104e66c4a9ad4677c1d2d09d2924150409a Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Thu, 15 Sep 2022 23:22:43 +0300 Subject: [PATCH 052/153] Update Options DTO --- src/Values/Options.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Values/Options.php b/src/Values/Options.php index cc59e21e..9e409320 100644 --- a/src/Values/Options.php +++ b/src/Values/Options.php @@ -10,15 +10,15 @@ class Options extends DataTransferObject { public bool $before = false; - public ?string $database = null; + public ?string $connection = null; public bool $force = false; + public ?string $name = null; + public ?string $path = null; public bool $realpath = false; public ?int $step = null; - - public ?string $name = null; } From ed9b7b86cb9a43f459bdd6be92e171def59e34b5 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Thu, 15 Sep 2022 23:24:10 +0300 Subject: [PATCH 053/153] Trait was renamed to `Anonymous` from `Anonymouses` --- src/Concerns/{Anonymouses.php => Anonymous.php} | 2 +- src/ServiceProvider.php | 4 ++-- tests/TestCase.php | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) rename src/Concerns/{Anonymouses.php => Anonymous.php} (92%) diff --git a/src/Concerns/Anonymouses.php b/src/Concerns/Anonymous.php similarity index 92% rename from src/Concerns/Anonymouses.php rename to src/Concerns/Anonymous.php index 1c549695..5b957646 100644 --- a/src/Concerns/Anonymouses.php +++ b/src/Concerns/Anonymous.php @@ -4,7 +4,7 @@ use DragonCode\LaravelSupport\Facades\AppVersion; -trait Anonymouses +trait Anonymous { protected function allowAnonymousMigrations(): bool { diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index 0b1b2538..c6addcd1 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -5,13 +5,13 @@ namespace DragonCode\LaravelActions; use DragonCode\LaravelActions\Concerns\About; -use DragonCode\LaravelActions\Concerns\Anonymouses; +use DragonCode\LaravelActions\Concerns\Anonymous; use Illuminate\Support\ServiceProvider as BaseServiceProvider; class ServiceProvider extends BaseServiceProvider { use About; - use Anonymouses; + use Anonymous; public function boot(): void { diff --git a/tests/TestCase.php b/tests/TestCase.php index a173bd63..4ec6e9a6 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -2,7 +2,7 @@ namespace Tests; -use DragonCode\LaravelActions\Concerns\Anonymouses; +use DragonCode\LaravelActions\Concerns\Anonymous; use DragonCode\LaravelActions\ServiceProvider; use Illuminate\Database\Query\Builder; use Illuminate\Foundation\Testing\RefreshDatabase; @@ -18,7 +18,7 @@ abstract class TestCase extends BaseTestCase use Database; use Files; use RefreshDatabase; - use Anonymouses; + use Anonymous; protected function setUp(): void { From 321e1cfff78ed82a79fdc9b1125d949694f21cde Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Thu, 15 Sep 2022 23:27:58 +0300 Subject: [PATCH 054/153] Update Install processor --- src/Processors/Install.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Processors/Install.php b/src/Processors/Install.php index ba118424..ffbf384a 100644 --- a/src/Processors/Install.php +++ b/src/Processors/Install.php @@ -9,7 +9,7 @@ class Install extends Processor public function handle(): void { if ($this->exists()) { - $this->notification->warning('Action repository already exists.'); + $this->notification->warning('Actions repository already exists.'); return; } @@ -26,6 +26,6 @@ protected function create(): void { $this->repository->createRepository(); - $this->notification->info('Action repository successfully created.'); + $this->notification->info('Actions repository successfully created.'); } } From 78eea0d6bb0059083a405911a2372fa674f8d966 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Thu, 15 Sep 2022 23:49:10 +0300 Subject: [PATCH 055/153] Updated Make processor --- resources/stubs/action.stub | 4 +-- src/Processors/Make.php | 50 ++++++++++++++++++++++++++++++++++++ src/Processors/Processor.php | 4 ++- 3 files changed, 55 insertions(+), 3 deletions(-) diff --git a/resources/stubs/action.stub b/resources/stubs/action.stub index c8b05778..7ee86d78 100644 --- a/resources/stubs/action.stub +++ b/resources/stubs/action.stub @@ -1,8 +1,8 @@ getPath(); + + $this->ensureDirectory($path); + $this->create($path); + } + + protected function create(string $path): void + { + File::copy($this->stub, $path); + } + + protected function ensureDirectory(string $path): void + { + Directory::ensureDirectory( + Path::dirname($path) + ); + } + + protected function getPath(): string + { + $name = $this->getName(); + + return $this->options->realpath ? $name : $this->config->path($name); + } + + protected function getName(): string + { + $name = $this->options->name ?? $this->git->currentBranch() ?? $this->default_name; + + $directory = Path::dirname($name); + $filename = Str::of(Path::filename($name))->prepend($this->getTime())->end('.php'); + + return $directory . DIRECTORY_SEPARATOR . $filename; + } + + protected function getTime(): string + { + return date('Y_m_d_His_'); + } } diff --git a/src/Processors/Processor.php b/src/Processors/Processor.php index b146b90a..3af6132f 100644 --- a/src/Processors/Processor.php +++ b/src/Processors/Processor.php @@ -6,6 +6,7 @@ use DragonCode\LaravelActions\Concerns\Artisan; use DragonCode\LaravelActions\Helpers\Config; +use DragonCode\LaravelActions\Helpers\Git; use DragonCode\LaravelActions\Notifications\Basic; use DragonCode\LaravelActions\Notifications\Beautiful; use DragonCode\LaravelActions\Notifications\Notification; @@ -28,7 +29,8 @@ public function __construct( protected InputInterface $input, protected OutputInterface $output, protected Config $config, - protected ActionRepository $repository + protected ActionRepository $repository, + protected Git $git ) { $this->bootNotification($this->output); } From 3f35ac63207d241678c701694500ee170da01fc5 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Fri, 16 Sep 2022 01:18:35 +0300 Subject: [PATCH 056/153] Updated Migrate processor --- src/Helpers/Config.php | 18 +- src/Notifications/Basic.php | 15 ++ src/Notifications/Beautiful.php | 6 + src/Notifications/Notification.php | 3 + src/Processors/Migrate.php | 30 ++++ src/Processors/Processor.php | 23 +-- src/ServiceProvider.php | 12 ++ src/Services/Migrator.php | 125 ++++++++++++++ src/Support/Migrator.php | 253 ----------------------------- 9 files changed, 218 insertions(+), 267 deletions(-) create mode 100644 src/Services/Migrator.php delete mode 100644 src/Support/Migrator.php diff --git a/src/Helpers/Config.php b/src/Helpers/Config.php index f2155789..6f3e786b 100644 --- a/src/Helpers/Config.php +++ b/src/Helpers/Config.php @@ -4,21 +4,33 @@ namespace DragonCode\LaravelActions\Helpers; +use Illuminate\Config\Repository; + class Config { + public function __construct( + protected Repository $config + ) { + } + + public function environment(): ?string + { + return $this->config->get('app.env', 'production'); + } + public function connection(): ?string { - return config('database.actions.connection'); + return $this->config->get('database.actions.connection'); } public function table(): string { - return config('database.actions.table'); + return $this->config->get('database.actions.table'); } public function path(?string $path = null): string { - $directory = config('database.actions.path', base_path('actions')); + $directory = $this->config->get('database.actions.path', base_path('actions')); return rtrim($directory, '\\/') . DIRECTORY_SEPARATOR . ltrim((string) $path, '\\/'); } diff --git a/src/Notifications/Basic.php b/src/Notifications/Basic.php index d7235a7a..adf98d72 100644 --- a/src/Notifications/Basic.php +++ b/src/Notifications/Basic.php @@ -4,6 +4,8 @@ namespace DragonCode\LaravelActions\Notifications; +use Closure; + class Basic extends Notification { public function line(string $string, ?string $style = null): void @@ -22,4 +24,17 @@ public function warning(string $string): void { $this->line($string, 'warn'); } + + public function task(string $description, Closure $task): void + { + $this->info($description); + + $start = microtime(true); + + $task(); + + $run_time = number_format((microtime(true) - $start) * 1000, 2); + + $this->info("Migrated: {$run_time}ms"); + } } diff --git a/src/Notifications/Beautiful.php b/src/Notifications/Beautiful.php index c3005e66..22d3f5dc 100644 --- a/src/Notifications/Beautiful.php +++ b/src/Notifications/Beautiful.php @@ -4,6 +4,7 @@ namespace DragonCode\LaravelActions\Notifications; +use Closure; use Illuminate\Console\View\Components\Factory; use Illuminate\Container\Container; @@ -26,6 +27,11 @@ public function warning(string $string): void $this->components()->warn($string, $this->verbosity); } + public function task(string $description, Closure $task): void + { + $this->components()->task($description, $task); + } + protected function components() { if (! is_null($this->components)) { diff --git a/src/Notifications/Notification.php b/src/Notifications/Notification.php index e0c696e4..3b998f1a 100644 --- a/src/Notifications/Notification.php +++ b/src/Notifications/Notification.php @@ -4,6 +4,7 @@ namespace DragonCode\LaravelActions\Notifications; +use Closure; use Symfony\Component\Console\Output\OutputInterface; abstract class Notification @@ -16,6 +17,8 @@ abstract public function info(string $string): void; abstract public function warning(string $string): void; + abstract public function task(string $description, Closure $task): void; + public function __construct( protected OutputInterface $output ) { diff --git a/src/Processors/Migrate.php b/src/Processors/Migrate.php index 6a705ad1..454270cc 100644 --- a/src/Processors/Migrate.php +++ b/src/Processors/Migrate.php @@ -6,4 +6,34 @@ class Migrate extends Processor { + public function handle(): void + { + $batch = $this->getBatch(); + + $this->runEach($this->getNewFiles(), $batch); + } + + protected function runEach(array $files, int $batch): void + { + foreach ($files as $file) { + $this->run($file, $batch); + } + } + + protected function run(string $file, int $batch): void + { + $this->migrator->runUp($file, $batch, $this->options); + } + + protected function getNewFiles(): array + { + $completed = $this->repository->getCompleted(); + + return $this->getFiles(fn (string $file) => ! in_array($file, $completed)); + } + + protected function getBatch(): int + { + return $this->repository->getNextBatchNumber(); + } } diff --git a/src/Processors/Processor.php b/src/Processors/Processor.php index 3af6132f..2e1e9c8b 100644 --- a/src/Processors/Processor.php +++ b/src/Processors/Processor.php @@ -4,15 +4,16 @@ namespace DragonCode\LaravelActions\Processors; +use Closure; use DragonCode\LaravelActions\Concerns\Artisan; use DragonCode\LaravelActions\Helpers\Config; use DragonCode\LaravelActions\Helpers\Git; -use DragonCode\LaravelActions\Notifications\Basic; -use DragonCode\LaravelActions\Notifications\Beautiful; use DragonCode\LaravelActions\Notifications\Notification; use DragonCode\LaravelActions\Repositories\ActionRepository; +use DragonCode\LaravelActions\Services\Migrator; use DragonCode\LaravelActions\Values\Options; -use Illuminate\Console\View\Components\Factory; +use DragonCode\Support\Facades\Helpers\Arr; +use DragonCode\Support\Filesystem\File; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -20,8 +21,6 @@ abstract class Processor { use Artisan; - protected ?Notification $notification = null; - abstract public function handle(): void; public function __construct( @@ -30,15 +29,17 @@ public function __construct( protected OutputInterface $output, protected Config $config, protected ActionRepository $repository, - protected Git $git + protected Git $git, + protected File $file, + protected Migrator $migrator, + protected Notification $notification ) { - $this->bootNotification($this->output); } - protected function bootNotification(OutputInterface $output): Notification + protected function getFiles(Closure $filter): array { - $this->notification = class_exists(Factory::class) - ? new Beautiful($output) - : new Basic($output); + $files = $this->file->names($this->config->path(), $filter, true); + + return Arr::sort($files); } } diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index c6addcd1..5426e600 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -6,6 +6,10 @@ use DragonCode\LaravelActions\Concerns\About; use DragonCode\LaravelActions\Concerns\Anonymous; +use DragonCode\LaravelActions\Notifications\Basic; +use DragonCode\LaravelActions\Notifications\Beautiful; +use DragonCode\LaravelActions\Notifications\Notification; +use Illuminate\Console\View\Components\Factory; use Illuminate\Support\ServiceProvider as BaseServiceProvider; class ServiceProvider extends BaseServiceProvider @@ -19,6 +23,7 @@ public function boot(): void $this->registerCommands(); $this->registerAbout(); $this->registerMigrations(); + $this->registerNotifications(); } } @@ -43,4 +48,11 @@ protected function registerMigrations(): void ? $this->loadMigrationsFrom(__DIR__ . '/../database/migrations/anonymous') : $this->loadMigrationsFrom(__DIR__ . '/../database/migrations/named'); } + + protected function registerNotifications(): void + { + class_exists(Factory::class) + ? $this->app->bind(Notification::class, Beautiful::class) + : $this->app->bind(Notification::class, Basic::class); + } } diff --git a/src/Services/Migrator.php b/src/Services/Migrator.php new file mode 100644 index 00000000..1b0b90b3 --- /dev/null +++ b/src/Services/Migrator.php @@ -0,0 +1,125 @@ +resolve($file); + + if ($this->allowAction($action, $file, $options)) { + $this->runAction($action, $file, 'up'); + + if ($this->allowLogging($action)) { + $this->log($file, $batch); + } + } + } + + protected function runAction(Action $action, string $name, string $method): void + { + $callback = function () use ($action, $method) { + if (method_exists($action, $method)) { + try { + $action->enabledTransactions() + ? DB::transaction(fn () => $this->runMethod($action, $method), $action->transactionAttempts()) + : $this->runMethod($action, $method); + } + catch (\Throwable $e) { + $action->failed(); + + throw $e; + } + } + }; + + $this->notification->task("Action: $name", $callback); + } + + protected function runMethod(Action $action, string $method): void + { + $action->{$method}(); + + $action->success(); + } + + protected function log(string $name, int $batch): void + { + $this->repository->log($name, $batch); + } + + protected function allowAction(Action $action, string $name, Options $options): bool + { + if (! $this->allowEnvironment($action)) { + $this->notification->info("Action: $name was skipped on this environment"); + + return false; + } + + if (! $this->allowBefore($action, $options)) { + $this->notification->info("Action: $name was skipped by 'before' option"); + + return false; + } + + return true; + } + + protected function allowEnvironment(Action $action): bool + { + $env = $this->config->environment(); + + $on = $action->onEnvironment(); + $except = $action->exceptEnvironment(); + $allow = $action->allow(); + + if (! $allow) { + return false; + } + + if (! empty($on) && ! in_array($env, $on)) { + return false; + } + + return ! (! empty($except) && in_array($env, $except)); + } + + protected function allowBefore(Action $action, Options $options): bool + { + return $options->before && ! $action->hasBefore(); + } + + protected function allowLogging(Action $action): bool + { + return $action->isOnce(); + } + + protected function resolve(string $path): Action + { + if ($this->file->exists($path)) { + return require $path; + } + + throw new FileNotFoundException($path); + } +} diff --git a/src/Support/Migrator.php b/src/Support/Migrator.php deleted file mode 100644 index f0cb2332..00000000 --- a/src/Support/Migrator.php +++ /dev/null @@ -1,253 +0,0 @@ -resolver->getDefaultConnection(); - - $this->setConnection($name); - - return tap($callback(), function () use ($prev) { - $this->setConnection($prev); - }); - } - - public function runPending(array $migrations, array $options = []) - { - $this->is_before = $options['before'] ?? false; - - return parent::runPending($migrations, $options); - } - - /** - * Run "up" a migration instance. - * - * @param string $file - * @param int $batch - * @param bool $pretend - * - * @throws Throwable - */ - protected function runUp($file, $batch, $pretend) - { - // First we will resolve a "real" instance of the migration class from this - // migration file name. Once we have the instances we can run the actual - // command such as "up" or "down", or we can just simulate the action. - $migration = $this->resolvePath($file); - - $name = $this->getMigrationName($file); - - if (! $this->allowEnvironment($migration)) { - $this->note("Migrate: {$name} was skipped on this environment"); - - return; - } - - if ($this->disallowBefore($migration)) { - $this->note("Migrate: {$name} was omitted because the 'before' parameter is enabled."); - - return; - } - - if ($pretend) { - $this->pretendToRun($migration, 'up'); - - return; - } - - $this->note("Migrating: {$name}"); - - $startTime = microtime(true); - - $this->runMigration($migration, 'up'); - - $runTime = number_format((microtime(true) - $startTime) * 1000, 2); - - // Once we have run a migrations class, we will log that it was run in this - // repository so that we don't try to run it next time we do a migration - // in the application. A migration repository keeps the migrate order. - if ($this->allowLogging($migration)) { - $this->repository->log($name, $batch); - } - - $this->note("Migrated: {$name} ({$runTime}ms)"); - } - - /** - * Run "down" a migration instance. - * - * @param string $file - * @param object $migration - * @param bool $pretend - * - * @throws Throwable - */ - protected function runDown($file, $migration, $pretend) - { - $instance = $this->resolvePath($file); - - $name = $this->getMigrationName($file); - - if (! $this->allowEnvironment($instance)) { - $this->note("Rolling back: {$name} was skipped on this environment"); - - return; - } - - parent::runDown($file, $migration, $pretend); - } - - /** - * Starts the execution of code, starting database transactions, if necessary. - * - * @param object $migration - * @param string $method - * - * @throws Throwable - */ - protected function runMigration($migration, $method) - { - $this->runMigrationHandle($migration, function ($migration) use ($method) { - if ($this->enabledTransactions($migration)) { - DB::transaction(function () use ($migration, $method) { - parent::runMigration($migration, $method); - }, $this->transactionAttempts($migration)); - - return; - } - - parent::runMigration($migration, $method); - }); - } - - /** - * Whether it is necessary to record information about the execution in the database. - * - * @param \DragonCode\Contracts\LaravelActions\Actionable|object $migration - * - * @return bool - */ - protected function allowLogging(ActionableContract $migration): bool - { - return $migration->isOnce(); - } - - /** - * Whether the action needs to be executed in the current environment. - * - * @param \DragonCode\Contracts\LaravelActions\Actionable|object $migration - * - * @return bool - */ - protected function allowEnvironment(ActionableContract $migration): bool - { - $environment = config('app.env', 'production'); - - $on = $migration->onEnvironment(); - $except = $migration->exceptEnvironment(); - $allow = $migration->allow(); - - if (! $allow) { - return false; - } - - if (! empty($on) && ! in_array($environment, $on)) { - return false; - } - - return ! (! empty($except) && in_array($environment, $except)); - } - - /** - * Whether it is necessary to call database transactions at runtime. - * - * @param \DragonCode\LaravelActions\Services\Actionable|object $migration - * - * @return bool - */ - protected function enabledTransactions(ActionableContract $migration): bool - { - return $migration->enabledTransactions(); - } - - /** - * The number of attempts to execute a request within a transaction before throwing an error. - * - * @param \DragonCode\LaravelActions\Services\Actionable|object $migration - * - * @return int - */ - protected function transactionAttempts(ActionableContract $migration): int - { - $value = $migration->transactionAttempts(); - - return (int) abs($value); - } - - /** - * Defines a possible "pre-launch" of the action. - * - * @param \DragonCode\Contracts\LaravelActions\Actionable|object $migration - * - * @return bool - */ - protected function disallowBefore(ActionableContract $migration): bool - { - return $this->is_before && ! $migration->hasBefore(); - } - - /** - * @param \DragonCode\Contracts\LaravelActions\Actionable|object $migration - * @param callable $handle - * - * @throws Throwable - * - * @return void - */ - protected function runMigrationHandle(ActionableContract $migration, callable $handle) - { - try { - $handle($migration); - - $this->runSuccess($migration); - } - catch (Throwable $e) { - $this->runFailed($migration); - - throw $e; - } - } - - /** - * @param \DragonCode\Contracts\LaravelActions\Actionable|object $migration - * - * @return void - */ - protected function runSuccess(ActionableContract $migration): void - { - $migration->success(); - } - - /** - * @param \DragonCode\Contracts\LaravelActions\Actionable|object $migration - * - * @return void - */ - protected function runFailed(ActionableContract $migration): void - { - $migration->failed(); - } -} From cf71fab6f70d0d9cca2b77f255f9c30c62cafa6f Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Fri, 16 Sep 2022 01:18:42 +0300 Subject: [PATCH 057/153] Removed old file --- src/Concerns/Argumentable.php | 34 ---------------------------------- 1 file changed, 34 deletions(-) delete mode 100644 src/Concerns/Argumentable.php diff --git a/src/Concerns/Argumentable.php b/src/Concerns/Argumentable.php deleted file mode 100644 index 8ed30c92..00000000 --- a/src/Concerns/Argumentable.php +++ /dev/null @@ -1,34 +0,0 @@ -argument('name')) { - return trim((string) $name); - } - - return $this->makeName(); - } - - protected function makeName(): string - { - return $this->getAutoPrefix(); - } - - protected function getAutoPrefix(): string - { - return $this->getGitBranchName() ?: $this->auto_prefix; - } - - protected function getGitBranchName(): ?string - { - return Git::make()->currentBranch(base_path()); - } -} From 580c222ce76a259b17d8c0b7a511d86d269260b2 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Fri, 16 Sep 2022 01:22:26 +0300 Subject: [PATCH 058/153] Added the `runDown` method to `Migrator` --- src/Services/Migrator.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Services/Migrator.php b/src/Services/Migrator.php index 1b0b90b3..36c3843a 100644 --- a/src/Services/Migrator.php +++ b/src/Services/Migrator.php @@ -12,6 +12,7 @@ use DragonCode\Support\Exceptions\FileNotFoundException; use DragonCode\Support\Filesystem\File; use Illuminate\Support\Facades\DB; +use Throwable; class Migrator { @@ -36,6 +37,15 @@ public function runUp(string $file, int $batch, Options $options): void } } + public function runDown(string $file): void + { + $action = $this->resolve($file); + + $this->runAction($action, $file, 'down'); + + $this->deleteLog($file); + } + protected function runAction(Action $action, string $name, string $method): void { $callback = function () use ($action, $method) { @@ -45,7 +55,7 @@ protected function runAction(Action $action, string $name, string $method): void ? DB::transaction(fn () => $this->runMethod($action, $method), $action->transactionAttempts()) : $this->runMethod($action, $method); } - catch (\Throwable $e) { + catch (Throwable $e) { $action->failed(); throw $e; @@ -68,6 +78,11 @@ protected function log(string $name, int $batch): void $this->repository->log($name, $batch); } + protected function deleteLog(string $name): void + { + $this->repository->delete($name); + } + protected function allowAction(Action $action, string $name, Options $options): bool { if (! $this->allowEnvironment($action)) { From ce299eb2e81369b71bb6c00cec657e8de4583aad Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Sun, 2 Oct 2022 14:33:26 +0300 Subject: [PATCH 059/153] Added declare strict type to the stub file --- resources/stubs/action.stub | 2 ++ 1 file changed, 2 insertions(+) diff --git a/resources/stubs/action.stub b/resources/stubs/action.stub index 7ee86d78..bd0143f7 100644 --- a/resources/stubs/action.stub +++ b/resources/stubs/action.stub @@ -1,5 +1,7 @@ Date: Sun, 2 Oct 2022 14:35:37 +0300 Subject: [PATCH 060/153] Removed unnecessary method call --- src/Processors/Make.php | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/Processors/Make.php b/src/Processors/Make.php index b114a029..2d5f97e1 100644 --- a/src/Processors/Make.php +++ b/src/Processors/Make.php @@ -4,7 +4,6 @@ namespace DragonCode\LaravelActions\Processors; -use DragonCode\Support\Facades\Filesystem\Directory; use DragonCode\Support\Facades\Filesystem\File; use DragonCode\Support\Facades\Filesystem\Path; use DragonCode\Support\Facades\Helpers\Str; @@ -19,7 +18,6 @@ public function handle(): void { $path = $this->getPath(); - $this->ensureDirectory($path); $this->create($path); } @@ -28,13 +26,6 @@ protected function create(string $path): void File::copy($this->stub, $path); } - protected function ensureDirectory(string $path): void - { - Directory::ensureDirectory( - Path::dirname($path) - ); - } - protected function getPath(): string { $name = $this->getName(); From e6b3cf52b7c7b390ddde0ae59576a25c0426a4fc Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Sun, 2 Oct 2022 14:38:34 +0300 Subject: [PATCH 061/153] Refactored Make processor --- src/Processors/Make.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Processors/Make.php b/src/Processors/Make.php index 2d5f97e1..b7141dc6 100644 --- a/src/Processors/Make.php +++ b/src/Processors/Make.php @@ -35,12 +35,20 @@ protected function getPath(): string protected function getName(): string { - $name = $this->options->name ?? $this->git->currentBranch() ?? $this->default_name; + $branch = $this->getBranchName(); + $filename = $this->getFilename($branch); - $directory = Path::dirname($name); - $filename = Str::of(Path::filename($name))->prepend($this->getTime())->end('.php'); + return Path::dirname($branch) . DIRECTORY_SEPARATOR . $filename; + } - return $directory . DIRECTORY_SEPARATOR . $filename; + protected function getFilename(string $branch): string + { + return Str::of(Path::filename($branch))->prepend($this->getTime())->end('.php')->toString(); + } + + protected function getBranchName(): string + { + return $this->options->name ?? $this->git->currentBranch() ?? $this->default_name; } protected function getTime(): string From b612237e5340db19c3294d491a50bcdb58ca3839 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Sun, 2 Oct 2022 14:40:23 +0300 Subject: [PATCH 062/153] Update Migrate processor --- src/Processors/Migrate.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Processors/Migrate.php b/src/Processors/Migrate.php index 454270cc..4bb578ea 100644 --- a/src/Processors/Migrate.php +++ b/src/Processors/Migrate.php @@ -8,9 +8,7 @@ class Migrate extends Processor { public function handle(): void { - $batch = $this->getBatch(); - - $this->runEach($this->getNewFiles(), $batch); + $this->runEach($this->getNewFiles(), $this->getBatch()); } protected function runEach(array $files, int $batch): void From 11d595e417fc3d993934896e54fe23660202ca69 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Sun, 2 Oct 2022 15:05:50 +0300 Subject: [PATCH 063/153] Refactored Refresh processor --- src/Constants/Options.php | 2 +- src/Processors/Fresh.php | 2 +- src/Processors/Processor.php | 5 ++++ src/Processors/Refresh.php | 51 ++++++++++++++++++++++++++++++++++++ 4 files changed, 58 insertions(+), 2 deletions(-) diff --git a/src/Constants/Options.php b/src/Constants/Options.php index c7e9ebcf..3fdea976 100644 --- a/src/Constants/Options.php +++ b/src/Constants/Options.php @@ -8,7 +8,7 @@ class Options { public const BEFORE = 'before'; - public const CONNECTION = 'database'; + public const CONNECTION = 'connection'; public const FORCE = 'force'; diff --git a/src/Processors/Fresh.php b/src/Processors/Fresh.php index 7b47f394..0fb8b1ca 100644 --- a/src/Processors/Fresh.php +++ b/src/Processors/Fresh.php @@ -26,7 +26,7 @@ protected function drop(): void protected function create(): void { - $this->artisan(Names::INSTALL, [ + $this->runCommand(Names::INSTALL, [ '--' . Options::CONNECTION => $this->options->connection, '--' . Options::FORCE => $this->options->force, ]); diff --git a/src/Processors/Processor.php b/src/Processors/Processor.php index 2e1e9c8b..d1fed10b 100644 --- a/src/Processors/Processor.php +++ b/src/Processors/Processor.php @@ -42,4 +42,9 @@ protected function getFiles(Closure $filter): array return Arr::sort($files); } + + protected function runCommand(string $command, array $options = []): void + { + $this->artisan($command, array_filter($options)); + } } diff --git a/src/Processors/Refresh.php b/src/Processors/Refresh.php index 7bbeaa68..390bcf54 100644 --- a/src/Processors/Refresh.php +++ b/src/Processors/Refresh.php @@ -4,6 +4,57 @@ namespace DragonCode\LaravelActions\Processors; +use DragonCode\LaravelActions\Constants\Names; +use DragonCode\LaravelActions\Constants\Options; + class Refresh extends Processor { + public function handle(): void + { + $database = $this->options->connection; + $path = $this->options->path; + $realPath = $this->options->realpath; + $step = $this->options->step; + + $this->rollback($database, $path, $realPath, $step); + $this->runMigrate($database, $path, $realPath); + } + + protected function rollback(?string $connection, ?string $path, bool $realPath, ?int $step): void + { + (int) $step > 0 + ? $this->runRollback($connection, $path, $realPath, $step) + : $this->runReset($connection, $path, $realPath); + } + + protected function runRollback(?string $connection, ?string $path, bool $realPath, ?int $step): void + { + $this->runCommand(Names::ROLLBACK, [ + '--' . Options::CONNECTION => $connection, + '--' . Options::PATH => $path, + '--' . Options::REALPATH => $realPath, + '--' . Options::STEP => $step, + '--' . Options::FORCE => true, + ]); + } + + protected function runReset(?string $connection, ?string $path, bool $realPath): void + { + $this->runCommand(Names::RESET, [ + '--' . Options::CONNECTION => $connection, + '--' . Options::PATH => $path, + '--' . Options::REALPATH => $realPath, + '--' . Options::FORCE => true, + ]); + } + + protected function runMigrate(?string $connection, ?string $path, bool $realPath): void + { + $this->runCommand(Names::MIGRATE, [ + '--' . Options::CONNECTION => $connection, + '--' . Options::PATH => $path, + '--' . Options::REALPATH => $realPath, + '--' . Options::FORCE => true, + ]); + } } From c35eb2eb4f1da0a5797faeb0aeef2354df180bcc Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Sun, 2 Oct 2022 15:09:19 +0300 Subject: [PATCH 064/153] Upgrade codestyle: replace `snake_case` variables to `camelCase` --- src/Action.php | 8 ++++---- src/Concerns/About.php | 6 +++--- src/Processors/Make.php | 4 ++-- .../actions/2021_06_07_132849_run_except_production.php | 2 +- .../app/actions/2021_06_07_132917_run_except_testing.php | 2 +- .../2021_06_07_134045_run_except_many_environments.php | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Action.php b/src/Action.php index dd7741a1..0bf8d8c8 100644 --- a/src/Action.php +++ b/src/Action.php @@ -35,7 +35,7 @@ abstract class Action extends Migration implements Contract * * @var int */ - protected int $transaction_attempts = 1; + protected int $transactionAttempts = 1; /** * Determines which environment to run on. @@ -49,7 +49,7 @@ abstract class Action extends Migration implements Contract * * @var array|string|null */ - protected string|array|null $except_environment = null; + protected string|array|null $exceptEnvironment = null; /** * Defines a possible "pre-launch" of the action. @@ -95,7 +95,7 @@ public function enabledTransactions(): bool */ public function transactionAttempts(): int { - return $this->transaction_attempts; + return $this->transactionAttempts; } /** @@ -115,7 +115,7 @@ public function onEnvironment(): array */ public function exceptEnvironment(): array { - return Arr::wrap($this->except_environment); + return Arr::wrap($this->exceptEnvironment); } /** diff --git a/src/Concerns/About.php b/src/Concerns/About.php index fe49c429..4b0925d2 100644 --- a/src/Concerns/About.php +++ b/src/Concerns/About.php @@ -10,7 +10,7 @@ trait About { - protected string $package_name = 'dragon-code/laravel-migration-actions'; + protected string $packageName = 'dragon-code/laravel-migration-actions'; protected function registerAbout(): void { @@ -23,7 +23,7 @@ protected function registerAbout(): void protected function getPackageName(): string { - return Str::of($this->package_name) + return Str::of($this->packageName) ->after('/') ->snake() ->replace('_', ' ') @@ -33,6 +33,6 @@ protected function getPackageName(): string protected function getPackageVersion(): string { - return InstalledVersions::getPrettyVersion($this->package_name); + return InstalledVersions::getPrettyVersion($this->packageName); } } diff --git a/src/Processors/Make.php b/src/Processors/Make.php index b7141dc6..5e113ada 100644 --- a/src/Processors/Make.php +++ b/src/Processors/Make.php @@ -10,7 +10,7 @@ class Make extends Processor { - protected string $default_name = 'auto'; + protected string $defaultName = 'auto'; protected string $stub = __DIR__ . '/../../resources/stubs/action.stub'; @@ -48,7 +48,7 @@ protected function getFilename(string $branch): string protected function getBranchName(): string { - return $this->options->name ?? $this->git->currentBranch() ?? $this->default_name; + return $this->options->name ?? $this->git->currentBranch() ?? $this->defaultName; } protected function getTime(): string diff --git a/tests/fixtures/app/actions/2021_06_07_132849_run_except_production.php b/tests/fixtures/app/actions/2021_06_07_132849_run_except_production.php index eed5cae6..b247a99c 100644 --- a/tests/fixtures/app/actions/2021_06_07_132849_run_except_production.php +++ b/tests/fixtures/app/actions/2021_06_07_132849_run_except_production.php @@ -7,7 +7,7 @@ return new class () extends Action { - protected string|array|null $except_environment = 'production'; + protected string|array|null $exceptEnvironment = 'production'; public function up(): void { diff --git a/tests/fixtures/app/actions/2021_06_07_132917_run_except_testing.php b/tests/fixtures/app/actions/2021_06_07_132917_run_except_testing.php index 76eade75..ffc97ff4 100644 --- a/tests/fixtures/app/actions/2021_06_07_132917_run_except_testing.php +++ b/tests/fixtures/app/actions/2021_06_07_132917_run_except_testing.php @@ -7,7 +7,7 @@ return new class () extends Action { - protected string|array|null $except_environment = 'testing'; + protected string|array|null $exceptEnvironment = 'testing'; public function up(): void { diff --git a/tests/fixtures/app/actions/2021_06_07_134045_run_except_many_environments.php b/tests/fixtures/app/actions/2021_06_07_134045_run_except_many_environments.php index 751566b5..e0fcfd30 100644 --- a/tests/fixtures/app/actions/2021_06_07_134045_run_except_many_environments.php +++ b/tests/fixtures/app/actions/2021_06_07_134045_run_except_many_environments.php @@ -9,7 +9,7 @@ { protected string|array|null $environment = ['testing']; - protected string|array|null $except_environment = ['testing', 'production']; + protected string|array|null $exceptEnvironment = ['testing', 'production']; public function up(): void { From ace3c804094825fb1771648efb569b1d6da87fe1 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Sun, 2 Oct 2022 15:11:36 +0300 Subject: [PATCH 065/153] Update Command class --- src/Console/Command.php | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/src/Console/Command.php b/src/Console/Command.php index b8654781..7a2b05e9 100644 --- a/src/Console/Command.php +++ b/src/Console/Command.php @@ -8,11 +8,14 @@ use DragonCode\LaravelActions\Processors\Processor; use DragonCode\Support\Facades\Helpers\Arr; use Illuminate\Console\Command as BaseCommand; +use Illuminate\Console\ConfirmableTrait; use Illuminate\Container\Container; use Symfony\Component\Console\Input\InputOption; abstract class Command extends BaseCommand { + use ConfirmableTrait; + protected Processor|string $processor; protected array $options = [ @@ -40,23 +43,6 @@ protected function resolveProcessor(): Processor ]); } - protected function confirmToProceed(): bool - { - if ($this->optionForce()) { - return true; - } - - $this->warn('Application in production!'); - - if ($this->confirm('Do you really wish to run this command?')) { - return true; - } - - $this->warn('Command canceled'); - - return false; - } - protected function getOptions(): array { return Arr::of($this->availableOptions()) From 393d47c5e7edd7266e6b988705e038866e24585b Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Sun, 2 Oct 2022 15:22:05 +0300 Subject: [PATCH 066/153] Refactored Reset processor --- src/Processors/Refresh.php | 6 ++--- src/Processors/Reset.php | 54 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 3 deletions(-) diff --git a/src/Processors/Refresh.php b/src/Processors/Refresh.php index 390bcf54..cb238166 100644 --- a/src/Processors/Refresh.php +++ b/src/Processors/Refresh.php @@ -11,13 +11,13 @@ class Refresh extends Processor { public function handle(): void { - $database = $this->options->connection; + $connection = $this->options->connection; $path = $this->options->path; $realPath = $this->options->realpath; $step = $this->options->step; - $this->rollback($database, $path, $realPath, $step); - $this->runMigrate($database, $path, $realPath); + $this->rollback($connection, $path, $realPath, $step); + $this->runMigrate($connection, $path, $realPath); } protected function rollback(?string $connection, ?string $path, bool $realPath, ?int $step): void diff --git a/src/Processors/Reset.php b/src/Processors/Reset.php index fb39df25..64a162bf 100644 --- a/src/Processors/Reset.php +++ b/src/Processors/Reset.php @@ -4,6 +4,60 @@ namespace DragonCode\LaravelActions\Processors; +use DragonCode\LaravelActions\Constants\Names; +use DragonCode\LaravelActions\Constants\Options; + class Reset extends Processor { + public function handle(): void + { + if ($this->tableNotFound() || $this->nothingToRollback()) { + return; + } + + $this->reset( + $this->options->connection, + $this->options->path, + $this->options->realpath, + $this->count() + ); + } + + protected function reset(?string $connection, ?string $path, ?bool $realPath, ?int $step): void + { + $this->runCommand(Names::ROLLBACK, [ + '--' . Options::CONNECTION => $connection, + '--' . Options::PATH => $path, + '--' . Options::REALPATH => $realPath, + '--' . Options::STEP => $step, + '--' . Options::FORCE => true, + ]); + } + + protected function tableNotFound(): bool + { + if (! $this->repository->repositoryExists()) { + $this->notification->warning('Actions table not found'); + + return true; + } + + return false; + } + + protected function nothingToRollback(): bool + { + if ($this->count() <= 0) { + $this->notification->warning('Nothing to rollback'); + + return true; + } + + return false; + } + + protected function count(): int + { + return $this->repository->getLastBatchNumber(); + } } From 7fb04c0ef083c0097685db25ccd468f280663a22 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Sun, 2 Oct 2022 15:39:39 +0300 Subject: [PATCH 067/153] Refactored Rollback processor --- src/Processors/Reset.php | 28 +------------------ src/Processors/Rollback.php | 54 +++++++++++++++++++++++++++++++++++++ src/Services/Migrator.php | 6 ++--- 3 files changed, 57 insertions(+), 31 deletions(-) diff --git a/src/Processors/Reset.php b/src/Processors/Reset.php index 64a162bf..5965e9ab 100644 --- a/src/Processors/Reset.php +++ b/src/Processors/Reset.php @@ -11,10 +11,6 @@ class Reset extends Processor { public function handle(): void { - if ($this->tableNotFound() || $this->nothingToRollback()) { - return; - } - $this->reset( $this->options->connection, $this->options->path, @@ -34,30 +30,8 @@ protected function reset(?string $connection, ?string $path, ?bool $realPath, ?i ]); } - protected function tableNotFound(): bool - { - if (! $this->repository->repositoryExists()) { - $this->notification->warning('Actions table not found'); - - return true; - } - - return false; - } - - protected function nothingToRollback(): bool - { - if ($this->count() <= 0) { - $this->notification->warning('Nothing to rollback'); - - return true; - } - - return false; - } - protected function count(): int { - return $this->repository->getLastBatchNumber(); + return count($this->repository->getCompleted()); } } diff --git a/src/Processors/Rollback.php b/src/Processors/Rollback.php index d1507948..6a71a6d0 100644 --- a/src/Processors/Rollback.php +++ b/src/Processors/Rollback.php @@ -6,4 +6,58 @@ class Rollback extends Processor { + public function handle(): void + { + if ($this->tableNotFound() || $this->nothingToRollback()) { + return; + } + + $this->run($this->options->step); + } + + protected function run(?int $step): void + { + foreach ($this->getActions($step) as $row) { + $this->rollbackAction($row->action); + } + } + + protected function getActions(?int $step): array + { + return (int) $step > 0 + ? $this->repository->getByStep($step) + : $this->repository->getLast(); + } + + protected function rollbackAction(string $action): void + { + $this->migrator->runDown($action); + } + + protected function tableNotFound(): bool + { + if (! $this->repository->repositoryExists()) { + $this->notification->warning('Actions table not found'); + + return true; + } + + return false; + } + + protected function nothingToRollback(): bool + { + if ($this->count() <= 0) { + $this->notification->warning('Nothing to rollback'); + + return true; + } + + return false; + } + + protected function count(): int + { + return $this->repository->getLastBatchNumber(); + } } diff --git a/src/Services/Migrator.php b/src/Services/Migrator.php index 36c3843a..c4bed924 100644 --- a/src/Services/Migrator.php +++ b/src/Services/Migrator.php @@ -48,7 +48,7 @@ public function runDown(string $file): void protected function runAction(Action $action, string $name, string $method): void { - $callback = function () use ($action, $method) { + $this->notification->task("Action: $name", function () use ($action, $method) { if (method_exists($action, $method)) { try { $action->enabledTransactions() @@ -61,9 +61,7 @@ protected function runAction(Action $action, string $name, string $method): void throw $e; } } - }; - - $this->notification->task("Action: $name", $callback); + }); } protected function runMethod(Action $action, string $method): void From c156d29835be8c18cdbc57d40fc7e5a1b0664e39 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Sun, 2 Oct 2022 15:51:34 +0300 Subject: [PATCH 068/153] Refactored Status processor --- src/Notifications/Basic.php | 5 ++++ src/Notifications/Beautiful.php | 5 ++++ src/Notifications/Notification.php | 2 ++ src/Processors/Processor.php | 11 +++++++ src/Processors/Rollback.php | 11 ------- src/Processors/Status.php | 43 +++++++++++++++++++++++++++ src/Repositories/ActionRepository.php | 2 +- 7 files changed, 67 insertions(+), 12 deletions(-) diff --git a/src/Notifications/Basic.php b/src/Notifications/Basic.php index adf98d72..3d5c217c 100644 --- a/src/Notifications/Basic.php +++ b/src/Notifications/Basic.php @@ -37,4 +37,9 @@ public function task(string $description, Closure $task): void $this->info("Migrated: {$run_time}ms"); } + + public function twoColumn(string $first, string $second): void + { + $this->info($first . ' .......... ' . $second); + } } diff --git a/src/Notifications/Beautiful.php b/src/Notifications/Beautiful.php index 22d3f5dc..089fa79a 100644 --- a/src/Notifications/Beautiful.php +++ b/src/Notifications/Beautiful.php @@ -32,6 +32,11 @@ public function task(string $description, Closure $task): void $this->components()->task($description, $task); } + public function twoColumn(string $first, string $second): void + { + $this->components()->twoColumnDetail($first, $second, $this->verbosity); + } + protected function components() { if (! is_null($this->components)) { diff --git a/src/Notifications/Notification.php b/src/Notifications/Notification.php index 3b998f1a..df3d0800 100644 --- a/src/Notifications/Notification.php +++ b/src/Notifications/Notification.php @@ -19,6 +19,8 @@ abstract public function warning(string $string): void; abstract public function task(string $description, Closure $task): void; + abstract public function twoColumn(string $first, string $second): void; + public function __construct( protected OutputInterface $output ) { diff --git a/src/Processors/Processor.php b/src/Processors/Processor.php index d1fed10b..1b7a875b 100644 --- a/src/Processors/Processor.php +++ b/src/Processors/Processor.php @@ -47,4 +47,15 @@ protected function runCommand(string $command, array $options = []): void { $this->artisan($command, array_filter($options)); } + + protected function tableNotFound(): bool + { + if (! $this->repository->repositoryExists()) { + $this->notification->warning('Actions table not found'); + + return true; + } + + return false; + } } diff --git a/src/Processors/Rollback.php b/src/Processors/Rollback.php index 6a71a6d0..ec464caa 100644 --- a/src/Processors/Rollback.php +++ b/src/Processors/Rollback.php @@ -34,17 +34,6 @@ protected function rollbackAction(string $action): void $this->migrator->runDown($action); } - protected function tableNotFound(): bool - { - if (! $this->repository->repositoryExists()) { - $this->notification->warning('Actions table not found'); - - return true; - } - - return false; - } - protected function nothingToRollback(): bool { if ($this->count() <= 0) { diff --git a/src/Processors/Status.php b/src/Processors/Status.php index 6440746f..00bdd27b 100644 --- a/src/Processors/Status.php +++ b/src/Processors/Status.php @@ -4,6 +4,49 @@ namespace DragonCode\LaravelActions\Processors; +use DragonCode\Support\Facades\Helpers\Arr; + class Status extends Processor { + public function handle(): void + { + if ($this->tableNotFound()) { + return; + } + + $this->run(); + } + + protected function run(): void + { + $completed = $this->getCompleted(); + $actions = $this->getActionFiles(); + + $this->showCaption(); + $this->show($actions, $completed); + } + + protected function showCaption(): void + { + $this->notification->twoColumn('Action name', 'Batch / Status'); + } + + protected function show(array $actions, array $completed): void + { + foreach ($actions as $action) { + $batch = Arr::get($completed, 'batch', 'No'); + + $this->notification->twoColumn($action, $batch); + } + } + + protected function getCompleted(): array + { + return collect($this->repository->getCompleted())->pluck('batch', 'action')->toArray(); + } + + protected function getActionFiles(): array + { + return $this->getFiles(fn () => true); + } } diff --git a/src/Repositories/ActionRepository.php b/src/Repositories/ActionRepository.php index fef1b7b9..70a7f6eb 100644 --- a/src/Repositories/ActionRepository.php +++ b/src/Repositories/ActionRepository.php @@ -22,7 +22,7 @@ public function __construct( public function getCompleted(): array { return $this->getOrderTable() - ->pluck('action') + ->get() ->all(); } From 2f6a67d4c5f1629c8c22bc093ddbccee8c3b2d27 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Sun, 2 Oct 2022 15:53:34 +0300 Subject: [PATCH 069/153] WIP Status refactoring --- src/Processors/Status.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Processors/Status.php b/src/Processors/Status.php index 00bdd27b..15fdd74c 100644 --- a/src/Processors/Status.php +++ b/src/Processors/Status.php @@ -23,15 +23,15 @@ protected function run(): void $actions = $this->getActionFiles(); $this->showCaption(); - $this->show($actions, $completed); + $this->showData($actions, $completed); } protected function showCaption(): void { - $this->notification->twoColumn('Action name', 'Batch / Status'); + $this->notification->twoColumn('Action name', 'Batch / Status'); } - protected function show(array $actions, array $completed): void + protected function showData(array $actions, array $completed): void { foreach ($actions as $action) { $batch = Arr::get($completed, 'batch', 'No'); @@ -39,6 +39,10 @@ protected function show(array $actions, array $completed): void $this->notification->twoColumn($action, $batch); } } + + protected function getStatusFor(array $ran, array $batches){ + + } protected function getCompleted(): array { From 96ee8a8ace11c90a904c27401fd709907e53047a Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Sun, 2 Oct 2022 21:02:59 +0300 Subject: [PATCH 070/153] Update Status processor --- src/Processors/Status.php | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/Processors/Status.php b/src/Processors/Status.php index 15fdd74c..085f9320 100644 --- a/src/Processors/Status.php +++ b/src/Processors/Status.php @@ -34,19 +34,28 @@ protected function showCaption(): void protected function showData(array $actions, array $completed): void { foreach ($actions as $action) { - $batch = Arr::get($completed, 'batch', 'No'); + $status = $this->getStatusFor($completed, $action); - $this->notification->twoColumn($action, $batch); + $this->notification->twoColumn($action, $status); } } - - protected function getStatusFor(array $ran, array $batches){ - + + protected function getStatusFor(array $completed, string $action): string + { + if ($batch = Arr::get($completed, $action)) { + $status = 'Ran'; + + return "[$batch] $status"; + } + + return 'Pending'; } protected function getCompleted(): array { - return collect($this->repository->getCompleted())->pluck('batch', 'action')->toArray(); + return collect($this->repository->getCompleted()) + ->pluck('batch', 'action') + ->toArray(); } protected function getActionFiles(): array From ec1ada30a6689e43f3844ad61f05da6387b4bc41 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Sun, 2 Oct 2022 21:22:38 +0300 Subject: [PATCH 071/153] Added Upgrade processor --- src/Processors/Processor.php | 4 +- src/Processors/Status.php | 2 +- src/Processors/Upgrade.php | 84 ++++++++++++++++++++++++++++++++++++ 3 files changed, 87 insertions(+), 3 deletions(-) diff --git a/src/Processors/Processor.php b/src/Processors/Processor.php index 1b7a875b..5ae786e5 100644 --- a/src/Processors/Processor.php +++ b/src/Processors/Processor.php @@ -36,9 +36,9 @@ public function __construct( ) { } - protected function getFiles(Closure $filter): array + protected function getFiles(?Closure $filter = null, ?string $path = null): array { - $files = $this->file->names($this->config->path(), $filter, true); + $files = $this->file->names($path ?: $this->config->path(), $filter, true); return Arr::sort($files); } diff --git a/src/Processors/Status.php b/src/Processors/Status.php index 085f9320..80291877 100644 --- a/src/Processors/Status.php +++ b/src/Processors/Status.php @@ -60,6 +60,6 @@ protected function getCompleted(): array protected function getActionFiles(): array { - return $this->getFiles(fn () => true); + return $this->getFiles(); } } diff --git a/src/Processors/Upgrade.php b/src/Processors/Upgrade.php index edf35c48..a1184096 100644 --- a/src/Processors/Upgrade.php +++ b/src/Processors/Upgrade.php @@ -4,6 +4,90 @@ namespace DragonCode\LaravelActions\Processors; +use DragonCode\Support\Facades\Filesystem\Directory; +use DragonCode\Support\Facades\Filesystem\File; +use DragonCode\Support\Facades\Helpers\Str; + class Upgrade extends Processor { + public function handle(): void + { + if ($this->alreadyUpgraded()) { + $this->notification->info('Action upgrade already done'); + + return; + } + + $this->run(); + } + + protected function run(): void + { + foreach ($this->getOldFiles() as $filename) { + $this->notification->task($filename, fn () => $this->move($filename)); + } + } + + protected function move(string $filename): void + { + $content = $this->open($filename); + + $content = $this->replaceNamespace($content); + $content = $this->replaceClassName($content); + $content = $this->replaceDeclareStrictType($content); + + $this->store($filename, $content); + $this->delete($filename); + } + + protected function open(string $path): string + { + return file_get_contents(base_path('database/actions/' . $path)); + } + + protected function store(string $path, string $content): void + { + file_put_contents($this->config->path($path), $content); + } + + protected function delete(string $path): void + { + File::ensureDelete($this->config->path($path)); + } + + protected function replaceNamespace(string $content): string + { + return Str::of($content)->replace( + ['DragonCode\\LaravelActions\\Support\\Actionable', 'Actionable'], + ['DragonCode\\LaravelActions\\Action', 'Action'] + )->toString(); + } + + protected function replaceClassName(string $content): string + { + return Str::of($content) + ->pregReplace('/^([final\s|class]+.+extends\sAction)$/', 'return new class () extends Action') + ->trim() + ->append(';') + ->append(PHP_EOL) + ->toString(); + } + + protected function replaceDeclareStrictType(string $content): string + { + return Str::of($content) + ->replace('(declare\s*\(\s*strict_types\s*=\s*[1|0]\);)', '') + ->replace("toString(); + } + + protected function getOldFiles(): array + { + return $this->getFiles(path: base_path('database/actions')); + } + + protected function alreadyUpgraded(): bool + { + return Directory::exists($this->config->path()); + } } From 6604c81c75819888db203b7ae38ecc53cf1446ef Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Sun, 2 Oct 2022 22:50:24 +0300 Subject: [PATCH 072/153] Update getByStep method --- src/Repositories/ActionRepository.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Repositories/ActionRepository.php b/src/Repositories/ActionRepository.php index 70a7f6eb..b358b52a 100644 --- a/src/Repositories/ActionRepository.php +++ b/src/Repositories/ActionRepository.php @@ -26,10 +26,10 @@ public function getCompleted(): array ->all(); } - public function getByStep(?int $steps = null): array + public function getByStep(int $steps): array { return $this->getOrderTable('desc') - ->when($steps, fn (Query $builder) => $builder->take($steps)) + ->whereIn('batch', $this->getBatchNumbers($steps)) ->get() ->all(); } @@ -83,6 +83,15 @@ public function deleteRepository(): void $this->schema()->dropIfExists($this->config->table()); } + protected function getBatchNumbers(int $steps): array + { + return $this->getOrderTable('desc') + ->pluck('batch') + ->unique() + ->take($steps) + ->all(); + } + protected function getOrderTable(string $order = 'asc'): Query { return $this->table() From 92f1805739e4391921a1bbe1cd39b9610b568aca Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Sun, 2 Oct 2022 22:54:14 +0300 Subject: [PATCH 073/153] Added setting connection name --- src/Processors/Processor.php | 2 ++ src/Repositories/ActionRepository.php | 11 ++++++++++- src/Services/Migrator.php | 7 +++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Processors/Processor.php b/src/Processors/Processor.php index 5ae786e5..a3728351 100644 --- a/src/Processors/Processor.php +++ b/src/Processors/Processor.php @@ -34,6 +34,8 @@ public function __construct( protected Migrator $migrator, protected Notification $notification ) { + $this->repository->setConnection($this->options->connection); + $this->migrator->setConnection($this->options->connection); } protected function getFiles(?Closure $filter = null, ?string $path = null): array diff --git a/src/Repositories/ActionRepository.php b/src/Repositories/ActionRepository.php index b358b52a..f73bc3fc 100644 --- a/src/Repositories/ActionRepository.php +++ b/src/Repositories/ActionRepository.php @@ -13,12 +13,21 @@ class ActionRepository { + protected ?string $connection = null; + public function __construct( protected Resolver $resolver, protected Config $config ) { } + public function setConnection(?string $connection): self + { + $this->connection = $connection; + + return $this; + } + public function getCompleted(): array { return $this->getOrderTable() @@ -107,7 +116,7 @@ protected function schema(): Builder protected function getConnection(): ConnectionInterface { return $this->resolver->connection( - $this->config->connection() + $this->connection ?: $this->config->connection() ); } diff --git a/src/Services/Migrator.php b/src/Services/Migrator.php index c4bed924..47b643ae 100644 --- a/src/Services/Migrator.php +++ b/src/Services/Migrator.php @@ -24,6 +24,13 @@ public function __construct( ) { } + public function setConnection(?string $connection): string + { + $this->repository->setConnection($connection); + + return $this; + } + public function runUp(string $file, int $batch, Options $options): void { $action = $this->resolve($file); From 4f98e46560e841b75b90ed97ea6a29aca033a7e2 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Sun, 2 Oct 2022 23:26:29 +0300 Subject: [PATCH 074/153] Update options --- src/Console/Install.php | 9 +++++++++ src/Console/Refresh.php | 2 ++ src/Console/Reset.php | 9 +++++++++ src/Console/Status.php | 1 - src/Services/Migrator.php | 2 +- 5 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/Console/Install.php b/src/Console/Install.php index aa6e3c2c..629a2934 100644 --- a/src/Console/Install.php +++ b/src/Console/Install.php @@ -3,6 +3,7 @@ namespace DragonCode\LaravelActions\Console; use DragonCode\LaravelActions\Constants\Names; +use DragonCode\LaravelActions\Constants\Options; use DragonCode\LaravelActions\Processors\Install as InstallProcessor; use DragonCode\LaravelActions\Processors\Processor; @@ -13,4 +14,12 @@ class Install extends Command protected $description = 'Create the actions repository'; protected Processor|string $processor = InstallProcessor::class; + + protected array $options = [ + Options::CONNECTION, + Options::FORCE, + Options::PATH, + Options::REALPATH, + Options::NAME, + ]; } diff --git a/src/Console/Refresh.php b/src/Console/Refresh.php index 64d97914..fd9db84a 100644 --- a/src/Console/Refresh.php +++ b/src/Console/Refresh.php @@ -18,6 +18,8 @@ class Refresh extends Command protected array $options = [ Options::CONNECTION, Options::FORCE, + Options::PATH, + Options::REALPATH, Options::STEP, ]; } diff --git a/src/Console/Reset.php b/src/Console/Reset.php index bcd38f19..28583b79 100644 --- a/src/Console/Reset.php +++ b/src/Console/Reset.php @@ -3,6 +3,7 @@ namespace DragonCode\LaravelActions\Console; use DragonCode\LaravelActions\Constants\Names; +use DragonCode\LaravelActions\Constants\Options; use DragonCode\LaravelActions\Processors\Processor; use DragonCode\LaravelActions\Processors\Reset as ResetProcessor; @@ -13,4 +14,12 @@ class Reset extends Command protected $description = 'Rollback all database actions'; protected Processor|string $processor = ResetProcessor::class; + + protected array $options = [ + Options::CONNECTION, + Options::PATH, + Options::REALPATH, + Options::STEP, + Options::FORCE, + ]; } diff --git a/src/Console/Status.php b/src/Console/Status.php index f0447b08..c4c59de0 100644 --- a/src/Console/Status.php +++ b/src/Console/Status.php @@ -17,6 +17,5 @@ class Status extends Command protected array $options = [ Options::CONNECTION, - Options::BEFORE, ]; } diff --git a/src/Services/Migrator.php b/src/Services/Migrator.php index 47b643ae..89705823 100644 --- a/src/Services/Migrator.php +++ b/src/Services/Migrator.php @@ -24,7 +24,7 @@ public function __construct( ) { } - public function setConnection(?string $connection): string + public function setConnection(?string $connection): self { $this->repository->setConnection($connection); From ef166237cd931cab6e19149c828d1916df11ba94 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Sun, 2 Oct 2022 23:45:34 +0300 Subject: [PATCH 075/153] Added events --- src/Events/ActionsEnded.php | 14 ++++++++++++++ src/Events/ActionsStarted.php | 14 ++++++++++++++ src/Events/BaseEvent.php | 9 +++++++++ src/Events/NoPendingActions.php | 13 +++++++++++++ src/Processors/Migrate.php | 16 +++++++++++++++- src/Processors/Processor.php | 10 +++++++++- src/Processors/Rollback.php | 22 +++++++++++++++++++--- 7 files changed, 93 insertions(+), 5 deletions(-) create mode 100644 src/Events/ActionsEnded.php create mode 100644 src/Events/ActionsStarted.php create mode 100644 src/Events/BaseEvent.php create mode 100644 src/Events/NoPendingActions.php diff --git a/src/Events/ActionsEnded.php b/src/Events/ActionsEnded.php new file mode 100644 index 00000000..917a9d61 --- /dev/null +++ b/src/Events/ActionsEnded.php @@ -0,0 +1,14 @@ +runEach($this->getNewFiles(), $this->getBatch()); + if ($files = $this->getNewFiles()) { + $this->fireEvent(new ActionsStarted('up', $this->options->before)); + + $this->runEach($files, $this->getBatch()); + + $this->fireEvent(new ActionsEnded('up', $this->options->before)); + + return; + } + + $this->fireEvent(new NoPendingActions('up')); } protected function runEach(array $files, int $batch): void diff --git a/src/Processors/Processor.php b/src/Processors/Processor.php index a3728351..c70d4426 100644 --- a/src/Processors/Processor.php +++ b/src/Processors/Processor.php @@ -6,6 +6,7 @@ use Closure; use DragonCode\LaravelActions\Concerns\Artisan; +use DragonCode\LaravelActions\Events\BaseEvent; use DragonCode\LaravelActions\Helpers\Config; use DragonCode\LaravelActions\Helpers\Git; use DragonCode\LaravelActions\Notifications\Notification; @@ -14,6 +15,7 @@ use DragonCode\LaravelActions\Values\Options; use DragonCode\Support\Facades\Helpers\Arr; use DragonCode\Support\Filesystem\File; +use Illuminate\Contracts\Events\Dispatcher; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -32,7 +34,8 @@ public function __construct( protected Git $git, protected File $file, protected Migrator $migrator, - protected Notification $notification + protected Notification $notification, + protected Dispatcher $events ) { $this->repository->setConnection($this->options->connection); $this->migrator->setConnection($this->options->connection); @@ -60,4 +63,9 @@ protected function tableNotFound(): bool return false; } + + protected function fireEvent(BaseEvent $event): void + { + $this->events->dispatch($event); + } } diff --git a/src/Processors/Rollback.php b/src/Processors/Rollback.php index ec464caa..fa3111b7 100644 --- a/src/Processors/Rollback.php +++ b/src/Processors/Rollback.php @@ -4,20 +4,36 @@ namespace DragonCode\LaravelActions\Processors; +use DragonCode\LaravelActions\Events\ActionsEnded; +use DragonCode\LaravelActions\Events\ActionsStarted; +use DragonCode\LaravelActions\Events\NoPendingActions; + class Rollback extends Processor { public function handle(): void { if ($this->tableNotFound() || $this->nothingToRollback()) { + $this->fireEvent(new NoPendingActions('down')); + + return; + } + + if ($actions = $this->getActions($this->options->step)) { + $this->fireEvent(new ActionsStarted('down', $this->options->before)); + + $this->run($actions); + + $this->fireEvent(new ActionsEnded('down', $this->options->before)); + return; } - $this->run($this->options->step); + $this->fireEvent(new NoPendingActions('down')); } - protected function run(?int $step): void + protected function run(array $actions): void { - foreach ($this->getActions($step) as $row) { + foreach ($actions as $row) { $this->rollbackAction($row->action); } } From 7a010e5698f260fdc59f1e7ba3369860f2827447 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Thu, 6 Oct 2022 01:28:38 +0300 Subject: [PATCH 076/153] Update About trait --- src/Concerns/About.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/Concerns/About.php b/src/Concerns/About.php index 4b0925d2..9e0d3121 100644 --- a/src/Concerns/About.php +++ b/src/Concerns/About.php @@ -5,12 +5,15 @@ namespace DragonCode\LaravelActions\Concerns; use Composer\InstalledVersions; +use DragonCode\Support\Facades\Helpers\Arr; use DragonCode\Support\Facades\Helpers\Str; use Illuminate\Foundation\Console\AboutCommand; trait About { - protected string $packageName = 'dragon-code/laravel-migration-actions'; + protected string $composer = __DIR__ . '/../../composer.json'; + + protected ?string $packageName = null; protected function registerAbout(): void { @@ -23,7 +26,7 @@ protected function registerAbout(): void protected function getPackageName(): string { - return Str::of($this->packageName) + return Str::of($this->loadPackageName()) ->after('/') ->snake() ->replace('_', ' ') @@ -33,6 +36,15 @@ protected function getPackageName(): string protected function getPackageVersion(): string { - return InstalledVersions::getPrettyVersion($this->packageName); + return InstalledVersions::getPrettyVersion($this->loadPackageName()); + } + + protected function loadPackageName(): string + { + if (! is_null($this->packageName)) { + return $this->packageName; + } + + return $this->packageName = Arr::ofFile($this->composer)->get('name'); } } From 12b19bdd07fa77b21620715d9f77e895d8256f16 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Thu, 6 Oct 2022 01:32:38 +0300 Subject: [PATCH 077/153] Removed `dragon-code/contracts` dependency --- composer.json | 1 - src/Action.php | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/composer.json b/composer.json index dfd86d3a..692b9165 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,6 @@ "php": "^8.0", "composer-runtime-api": "^2.2", "doctrine/dbal": "^2.13 || ^3.4", - "dragon-code/contracts": "^2.15", "dragon-code/laravel-support": "^3.4", "dragon-code/simple-dto": "^2.3", "dragon-code/support": "^6.3", diff --git a/src/Action.php b/src/Action.php index 0bf8d8c8..84539bb3 100644 --- a/src/Action.php +++ b/src/Action.php @@ -2,12 +2,11 @@ namespace DragonCode\LaravelActions; -use DragonCode\Contracts\LaravelActions\Actionable as Contract; use DragonCode\LaravelActions\Concerns\Artisan; use Illuminate\Database\Migrations\Migration; use Illuminate\Support\Arr; -abstract class Action extends Migration implements Contract +abstract class Action extends Migration { use Artisan; From 75f6a266c2d103d63a7148a81d257642338ae3fd Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Thu, 6 Oct 2022 01:40:33 +0300 Subject: [PATCH 078/153] Added invokable method by default --- resources/stubs/action.stub | 2 +- src/Action.php | 7 +++++++ src/Services/Migrator.php | 15 ++++++++++++--- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/resources/stubs/action.stub b/resources/stubs/action.stub index bd0143f7..05b88896 100644 --- a/resources/stubs/action.stub +++ b/resources/stubs/action.stub @@ -11,7 +11,7 @@ return new class () extends Action * * @return void */ - public function up(): void + public function __invoke(): void { // } diff --git a/src/Action.php b/src/Action.php index 84539bb3..100e27ee 100644 --- a/src/Action.php +++ b/src/Action.php @@ -57,6 +57,13 @@ abstract class Action extends Migration */ protected bool $before = true; + /** + * Run the actions. + */ + public function up(): void + { + } + /** * Reverse the actions. */ diff --git a/src/Services/Migrator.php b/src/Services/Migrator.php index 89705823..1fe6cffb 100644 --- a/src/Services/Migrator.php +++ b/src/Services/Migrator.php @@ -36,7 +36,9 @@ public function runUp(string $file, int $batch, Options $options): void $action = $this->resolve($file); if ($this->allowAction($action, $file, $options)) { - $this->runAction($action, $file, 'up'); + $this->hasAction($action, '__invoke') + ? $this->runAction($action, $file, '__invoke') + : $this->runAction($action, $file, 'up'); if ($this->allowLogging($action)) { $this->log($file, $batch); @@ -48,15 +50,22 @@ public function runDown(string $file): void { $action = $this->resolve($file); - $this->runAction($action, $file, 'down'); + if ($this->hasAction($action, 'down')) { + $this->runAction($action, $file, 'down'); + } $this->deleteLog($file); } + protected function hasAction(Action $action, string $method): bool + { + return method_exists($action, $method); + } + protected function runAction(Action $action, string $name, string $method): void { $this->notification->task("Action: $name", function () use ($action, $method) { - if (method_exists($action, $method)) { + if ($this->hasAction($action, $method)) { try { $action->enabledTransactions() ? DB::transaction(fn () => $this->runMethod($action, $method), $action->transactionAttempts()) From 06e60d214518103dbd691d7617e9731db596c2d7 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Thu, 6 Oct 2022 02:08:33 +0300 Subject: [PATCH 079/153] Resolved Dependency Injection to `invokable`, `up` and `down` methods --- src/Services/Migrator.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/Services/Migrator.php b/src/Services/Migrator.php index 1fe6cffb..b4e87ef8 100644 --- a/src/Services/Migrator.php +++ b/src/Services/Migrator.php @@ -11,6 +11,7 @@ use DragonCode\LaravelActions\Values\Options; use DragonCode\Support\Exceptions\FileNotFoundException; use DragonCode\Support\Filesystem\File; +use Illuminate\Contracts\Foundation\Application; use Illuminate\Support\Facades\DB; use Throwable; @@ -20,7 +21,8 @@ public function __construct( protected File $file, protected Notification $notification, protected ActionRepository $repository, - protected Config $config + protected Config $config, + protected Application $laravel ) { } @@ -67,9 +69,9 @@ protected function runAction(Action $action, string $name, string $method): void $this->notification->task("Action: $name", function () use ($action, $method) { if ($this->hasAction($action, $method)) { try { - $action->enabledTransactions() - ? DB::transaction(fn () => $this->runMethod($action, $method), $action->transactionAttempts()) - : $this->runMethod($action, $method); + $this->runMethod($action, $method, $action->enabledTransactions(), $action->transactionAttempts()); + + $action->success(); } catch (Throwable $e) { $action->failed(); @@ -80,11 +82,11 @@ protected function runAction(Action $action, string $name, string $method): void }); } - protected function runMethod(Action $action, string $method): void + protected function runMethod(Action $action, string $method, bool $transactions, int $attempts): void { - $action->{$method}(); + $callback = fn () => $this->laravel->call([$action, $method]); - $action->success(); + $transactions ? DB::transaction($callback, $attempts) : $callback(); } protected function log(string $name, int $batch): void From 749aca9c9de7a250dbf7bdae7312bdee418f793c Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Thu, 6 Oct 2022 02:21:00 +0300 Subject: [PATCH 080/153] Removed `force` checking --- src/Concerns/ConfirmableTrait.php | 19 +++++++++++++++++++ src/Console/Command.php | 12 ++++++------ src/Console/Migrate.php | 3 ++- src/Console/Status.php | 2 ++ 4 files changed, 29 insertions(+), 7 deletions(-) create mode 100644 src/Concerns/ConfirmableTrait.php diff --git a/src/Concerns/ConfirmableTrait.php b/src/Concerns/ConfirmableTrait.php new file mode 100644 index 00000000..06ab4714 --- /dev/null +++ b/src/Concerns/ConfirmableTrait.php @@ -0,0 +1,19 @@ +secure || $this->confirmToProceed(); + } +} diff --git a/src/Console/Command.php b/src/Console/Command.php index 7a2b05e9..9afa7ea5 100644 --- a/src/Console/Command.php +++ b/src/Console/Command.php @@ -4,11 +4,11 @@ namespace DragonCode\LaravelActions\Console; +use DragonCode\LaravelActions\Concerns\ConfirmableTrait; use DragonCode\LaravelActions\Constants\Options; use DragonCode\LaravelActions\Processors\Processor; use DragonCode\Support\Facades\Helpers\Arr; use Illuminate\Console\Command as BaseCommand; -use Illuminate\Console\ConfirmableTrait; use Illuminate\Container\Container; use Symfony\Component\Console\Input\InputOption; @@ -25,13 +25,13 @@ abstract class Command extends BaseCommand public function handle(): int { - if (! $this->confirmToProceed()) { - return 1; - } + if ($this->allowToProceed()) { + $this->resolveProcessor()->handle(); - $this->resolveProcessor()->handle(); + return 0; + } - return 0; + return 1; } protected function resolveProcessor(): Processor diff --git a/src/Console/Migrate.php b/src/Console/Migrate.php index 234b4a52..860bb5d9 100644 --- a/src/Console/Migrate.php +++ b/src/Console/Migrate.php @@ -15,10 +15,11 @@ class Migrate extends Command protected Processor|string $processor = MigrateProcessor::class; + protected bool $secure = false; + protected array $options = [ Options::BEFORE, Options::CONNECTION, - Options::FORCE, Options::PATH, Options::REALPATH, Options::STEP, diff --git a/src/Console/Status.php b/src/Console/Status.php index c4c59de0..94fc0675 100644 --- a/src/Console/Status.php +++ b/src/Console/Status.php @@ -15,6 +15,8 @@ class Status extends Command protected Processor|string $processor = StatusProcessor::class; + protected bool $secure = false; + protected array $options = [ Options::CONNECTION, ]; From 419b261e4fe2337043eb8e3301859fc95c831991 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Thu, 6 Oct 2022 02:24:21 +0300 Subject: [PATCH 081/153] Fixed command options --- src/Console/Command.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Console/Command.php b/src/Console/Command.php index 9afa7ea5..87d0a5c2 100644 --- a/src/Console/Command.php +++ b/src/Console/Command.php @@ -57,8 +57,8 @@ protected function availableOptions(): array [Options::CONNECTION, null, InputOption::VALUE_OPTIONAL, 'The database connection to use'], [Options::FORCE, null, InputOption::VALUE_NONE, 'Force the operation to run when in production'], [Options::NAME, null, InputOption::VALUE_OPTIONAL, 'The name of the action'], - [Options::PATH, '*', InputOption::VALUE_IS_ARRAY, 'The path(s) to the migrations files to be executed'], - [Options::REALPATH, null, InputOption::VALUE_NONE, 'Indicate any provided migration file paths are pre-resolved absolute paths'], + [Options::PATH, null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'The path(s) to the actions files to be executed'], + [Options::REALPATH, null, InputOption::VALUE_NONE, 'Indicate any provided action file paths are pre-resolved absolute paths'], [Options::STEP, null, InputOption::VALUE_OPTIONAL, 'Force the actions to be run so they can be rolled back individually'], ]; } From 51121e5f7fd097200aac49728c7bc0c9237febcc Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Thu, 6 Oct 2022 02:26:27 +0300 Subject: [PATCH 082/153] Fixed migrate initialize --- src/Database/BaseChangeMigrationColumn.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Database/BaseChangeMigrationColumn.php b/src/Database/BaseChangeMigrationColumn.php index 5bf1ba99..2a2c8d1c 100644 --- a/src/Database/BaseChangeMigrationColumn.php +++ b/src/Database/BaseChangeMigrationColumn.php @@ -11,9 +11,11 @@ abstract class BaseChangeMigrationColumn extends Action { - public function __construct( - protected Config $config - ) { + protected Config $config; + + public function __construct() + { + $this->config = app(Config::class); } public function up(): void From 26abe4ccedcaf1eb28dcef8c9f305af98f6bd7a0 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Thu, 6 Oct 2022 02:38:15 +0300 Subject: [PATCH 083/153] Upgrade config file --- config/actions.php | 39 +++++++++++++++++ config/database.php | 51 ---------------------- src/Concerns/Optionable.php | 84 ------------------------------------- src/Helpers/Config.php | 6 +-- src/ServiceProvider.php | 22 ++++++++++ tests/Concerns/Database.php | 4 +- tests/Concerns/Files.php | 10 ++++- 7 files changed, 75 insertions(+), 141 deletions(-) create mode 100644 config/actions.php delete mode 100644 config/database.php delete mode 100644 src/Concerns/Optionable.php diff --git a/config/actions.php b/config/actions.php new file mode 100644 index 00000000..82d8321f --- /dev/null +++ b/config/actions.php @@ -0,0 +1,39 @@ + env('DB_CONNECTION'), + + /* + |-------------------------------------------------------------------------- + | Actions Repository Table + |-------------------------------------------------------------------------- + | + | This table keeps track of all the actions that have already run for + | your application. Using this information, we can determine which of + | the actions on disk haven't actually been run in the database. + | + */ + + 'table' => 'migration_actions', + + /* + |-------------------------------------------------------------------------- + | Actions Path + |-------------------------------------------------------------------------- + | + | This option defines the path to the action directory. + | + */ + + 'path' => base_path('actions'), +]; diff --git a/config/database.php b/config/database.php deleted file mode 100644 index 28a7f7c7..00000000 --- a/config/database.php +++ /dev/null @@ -1,51 +0,0 @@ - [ - /* - |-------------------------------------------------------------------------- - | Actions Repository Connection - |-------------------------------------------------------------------------- - | - | This option controls the database connection used to store the table - | of executed actions. - | - */ - - 'connection' => env('DB_CONNECTION'), - - /* - |-------------------------------------------------------------------------- - | Actions Repository Table - |-------------------------------------------------------------------------- - | - | This table keeps track of all the actions that have already run for - | your application. Using this information, we can determine which of - | the actions on disk haven't actually been run in the database. - | - */ - - 'table' => 'migration_actions', - - /* - |-------------------------------------------------------------------------- - | Actions Path - |-------------------------------------------------------------------------- - | - | This option defines the path to the action directory. - | - */ - - 'path' => base_path('actions'), - ], -]; diff --git a/src/Concerns/Optionable.php b/src/Concerns/Optionable.php deleted file mode 100644 index 977b1151..00000000 --- a/src/Concerns/Optionable.php +++ /dev/null @@ -1,84 +0,0 @@ -optionHas(Options::FORCE); - } - - protected function optionBefore(): bool - { - return $this->option(Options::BEFORE); - } - - protected function optionConnection(): ?string - { - return $this->option(Options::CONNECTION); - } - - protected function optionName(): ?string - { - return $this->option(Options::NAME); - } - - protected function optionStep(?int $default = null): ?int - { - return $this->option(Options::STEP) ?: $default; - } - - protected function optionPath(): ?array - { - if (! $this->hasOption(Options::PATH)) { - return null; - } - - if ($path = $this->option(Options::PATH)) { - return collect($path)->map(function ($path) { - if ($this->usingRealPath()) { - return $path; - } - - $filename = $this->getActionsPath($path); - - if (is_dir($filename) || file_exists($filename)) { - return $filename; - } - - return Str::finish($filename, '.php'); - })->all(); - } - - return null; - } - - protected function usingRealPath(): bool - { - return $this->optionHas(Options::REALPATH); - } - - protected function optionHas(string $key): bool - { - return $this->hasOption($key) && $this->option($key); - } - - protected function optionDto(): OptionsDto - { - return OptionsDto::make([ - 'before' => $this->optionBefore(), - 'database' => $this->optionConnection(), - 'force' => $this->optionForce(), - 'name' => $this->optionName(), - 'path' => $this->optionPath(), - 'realpath' => $this->usingRealPath(), - 'step' => $this->optionStep(), - ]); - } -} diff --git a/src/Helpers/Config.php b/src/Helpers/Config.php index 6f3e786b..4a662a2b 100644 --- a/src/Helpers/Config.php +++ b/src/Helpers/Config.php @@ -20,17 +20,17 @@ public function environment(): ?string public function connection(): ?string { - return $this->config->get('database.actions.connection'); + return $this->config->get('actions.connection'); } public function table(): string { - return $this->config->get('database.actions.table'); + return $this->config->get('actions.table'); } public function path(?string $path = null): string { - $directory = $this->config->get('database.actions.path', base_path('actions')); + $directory = $this->config->get('actions.path', base_path('actions')); return rtrim($directory, '\\/') . DIRECTORY_SEPARATOR . ltrim((string) $path, '\\/'); } diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index 5426e600..e9947b44 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -20,6 +20,8 @@ class ServiceProvider extends BaseServiceProvider public function boot(): void { if ($this->app->runningInConsole()) { + $this->publishConfig(); + $this->registerCommands(); $this->registerAbout(); $this->registerMigrations(); @@ -27,6 +29,11 @@ public function boot(): void } } + public function register(): void + { + $this->registerConfig(); + } + protected function registerCommands(): void { $this->commands([ @@ -55,4 +62,19 @@ class_exists(Factory::class) ? $this->app->bind(Notification::class, Beautiful::class) : $this->app->bind(Notification::class, Basic::class); } + + protected function publishConfig(): void + { + $this->publishes([ + __DIR__ . '/../config/actions.php' => $this->app->configPath('actions.php'), + ]); + } + + protected function registerConfig(): void + { + $this->mergeConfigFrom( + __DIR__ . '/../config/actions.php', + 'actions' + ); + } } diff --git a/tests/Concerns/Database.php b/tests/Concerns/Database.php index 877fba88..24de59fb 100644 --- a/tests/Concerns/Database.php +++ b/tests/Concerns/Database.php @@ -11,13 +11,15 @@ trait Database protected function setDatabase($app): void { $app['config']->set('database.default', $this->database); - $app['config']->set('database.actions', $this->table); $app['config']->set('database.connections.' . $this->database, [ 'driver' => 'sqlite', 'database' => ':memory:', 'prefix' => '', ]); + + $app['config']->set('actions.connection', $this->database); + $app['config']->set('actions.table', $this->table); } protected function freshDatabase(): void diff --git a/tests/Concerns/Files.php b/tests/Concerns/Files.php index 1f14ede6..f6cb46c5 100644 --- a/tests/Concerns/Files.php +++ b/tests/Concerns/Files.php @@ -4,6 +4,7 @@ use Illuminate\Support\Facades\File; +/** @mixin \Tests\TestCase */ trait Files { protected function freshFiles(): void @@ -21,7 +22,7 @@ protected function copyFiles(): void ); } - protected function copySuccessFailureMethod() + protected function copySuccessFailureMethod(): void { File::copy( __DIR__ . '/../fixtures/app/actions_failed/2021_12_23_165048_run_success_on_failed.php', @@ -29,7 +30,7 @@ protected function copySuccessFailureMethod() ); } - protected function copyFailedMethod() + protected function copyFailedMethod(): void { File::copy( __DIR__ . '/../fixtures/app/actions_failed/2021_12_23_184029_run_failed_failure.php', @@ -61,4 +62,9 @@ protected function targetDirectory(?string $path = null): string return rtrim($dir, '/\\') . '/' . ltrim($path, '/\\'); } + + protected function getActionsPath(): string + { + return $this->app['config']->get('actions.path'); + } } From bbf1f2b49bd7ae015ae97731fac9686535cf270d Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Thu, 6 Oct 2022 02:45:33 +0300 Subject: [PATCH 084/153] Update Upgrade processor --- src/Processors/Upgrade.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/Processors/Upgrade.php b/src/Processors/Upgrade.php index a1184096..9836276f 100644 --- a/src/Processors/Upgrade.php +++ b/src/Processors/Upgrade.php @@ -4,6 +4,7 @@ namespace DragonCode\LaravelActions\Processors; +use DragonCode\LaravelActions\ServiceProvider; use DragonCode\Support\Facades\Filesystem\Directory; use DragonCode\Support\Facades\Filesystem\File; use DragonCode\Support\Facades\Helpers\Str; @@ -22,6 +23,12 @@ public function handle(): void } protected function run(): void + { + $this->moveFiles(); + $this->moveConfig(); + } + + protected function moveFiles(): void { foreach ($this->getOldFiles() as $filename) { $this->notification->task($filename, fn () => $this->move($filename)); @@ -81,6 +88,22 @@ protected function replaceDeclareStrictType(string $content): string ->toString(); } + protected function moveConfig(): void + { + $this->artisan('vendor:publish', [ + '--force' => true, + '--provider' => ServiceProvider::class, + ]); + + $path = config_path('actions.php'); + + $table = config('database.actions', 'migration_actions'); + + $content = Str::replace(file_get_contents($path), "'table' => 'migration_actions'", "'table' => '$table'"); + + file_put_contents($path, $content); + } + protected function getOldFiles(): array { return $this->getFiles(path: base_path('database/actions')); From 4ff129a8410a164465971353593db50037eccd0f Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Thu, 6 Oct 2022 03:34:24 +0300 Subject: [PATCH 085/153] Resolved OutputInterface dependency inject --- src/Console/Command.php | 8 +++++++- src/Contracts/Notification.php | 23 +++++++++++++++++++++++ src/Notifications/Beautiful.php | 2 +- src/Notifications/Notification.php | 13 +++++++++---- src/Processors/Processor.php | 3 ++- src/Processors/Refresh.php | 8 ++++---- src/ServiceProvider.php | 2 +- src/Services/Migrator.php | 2 +- src/Values/Options.php | 2 +- 9 files changed, 49 insertions(+), 14 deletions(-) create mode 100644 src/Contracts/Notification.php diff --git a/src/Console/Command.php b/src/Console/Command.php index 87d0a5c2..80f61c2f 100644 --- a/src/Console/Command.php +++ b/src/Console/Command.php @@ -7,6 +7,7 @@ use DragonCode\LaravelActions\Concerns\ConfirmableTrait; use DragonCode\LaravelActions\Constants\Options; use DragonCode\LaravelActions\Processors\Processor; +use DragonCode\LaravelActions\Values\Options as OptionsDto; use DragonCode\Support\Facades\Helpers\Arr; use Illuminate\Console\Command as BaseCommand; use Illuminate\Container\Container; @@ -37,12 +38,17 @@ public function handle(): int protected function resolveProcessor(): Processor { return Container::getInstance()->make($this->processor, [ - 'options' => $this->options(), + 'options' => $this->getOptionsDto(), 'input' => $this->input, 'output' => $this->output, ]); } + protected function getOptionsDto(): OptionsDto + { + return OptionsDto::fromArray($this->options()); + } + protected function getOptions(): array { return Arr::of($this->availableOptions()) diff --git a/src/Contracts/Notification.php b/src/Contracts/Notification.php new file mode 100644 index 00000000..0cbe3b37 --- /dev/null +++ b/src/Contracts/Notification.php @@ -0,0 +1,23 @@ +output = $output; + + return $this; } } diff --git a/src/Processors/Processor.php b/src/Processors/Processor.php index c70d4426..17bd0f88 100644 --- a/src/Processors/Processor.php +++ b/src/Processors/Processor.php @@ -6,10 +6,10 @@ use Closure; use DragonCode\LaravelActions\Concerns\Artisan; +use DragonCode\LaravelActions\Contracts\Notification; use DragonCode\LaravelActions\Events\BaseEvent; use DragonCode\LaravelActions\Helpers\Config; use DragonCode\LaravelActions\Helpers\Git; -use DragonCode\LaravelActions\Notifications\Notification; use DragonCode\LaravelActions\Repositories\ActionRepository; use DragonCode\LaravelActions\Services\Migrator; use DragonCode\LaravelActions\Values\Options; @@ -37,6 +37,7 @@ public function __construct( protected Notification $notification, protected Dispatcher $events ) { + $this->notification->setOutput($this->output); $this->repository->setConnection($this->options->connection); $this->migrator->setConnection($this->options->connection); } diff --git a/src/Processors/Refresh.php b/src/Processors/Refresh.php index cb238166..62168e2c 100644 --- a/src/Processors/Refresh.php +++ b/src/Processors/Refresh.php @@ -20,14 +20,14 @@ public function handle(): void $this->runMigrate($connection, $path, $realPath); } - protected function rollback(?string $connection, ?string $path, bool $realPath, ?int $step): void + protected function rollback(?string $connection, array $path, bool $realPath, ?int $step): void { (int) $step > 0 ? $this->runRollback($connection, $path, $realPath, $step) : $this->runReset($connection, $path, $realPath); } - protected function runRollback(?string $connection, ?string $path, bool $realPath, ?int $step): void + protected function runRollback(?string $connection, array $path, bool $realPath, ?int $step): void { $this->runCommand(Names::ROLLBACK, [ '--' . Options::CONNECTION => $connection, @@ -38,7 +38,7 @@ protected function runRollback(?string $connection, ?string $path, bool $realPat ]); } - protected function runReset(?string $connection, ?string $path, bool $realPath): void + protected function runReset(?string $connection, array $path, bool $realPath): void { $this->runCommand(Names::RESET, [ '--' . Options::CONNECTION => $connection, @@ -48,7 +48,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, array $path, bool $realPath): void { $this->runCommand(Names::MIGRATE, [ '--' . Options::CONNECTION => $connection, diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index e9947b44..0b2d5755 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -6,9 +6,9 @@ use DragonCode\LaravelActions\Concerns\About; use DragonCode\LaravelActions\Concerns\Anonymous; +use DragonCode\LaravelActions\Contracts\Notification; use DragonCode\LaravelActions\Notifications\Basic; use DragonCode\LaravelActions\Notifications\Beautiful; -use DragonCode\LaravelActions\Notifications\Notification; use Illuminate\Console\View\Components\Factory; use Illuminate\Support\ServiceProvider as BaseServiceProvider; diff --git a/src/Services/Migrator.php b/src/Services/Migrator.php index b4e87ef8..4986e9a9 100644 --- a/src/Services/Migrator.php +++ b/src/Services/Migrator.php @@ -5,8 +5,8 @@ namespace DragonCode\LaravelActions\Services; use DragonCode\LaravelActions\Action; +use DragonCode\LaravelActions\Contracts\Notification; use DragonCode\LaravelActions\Helpers\Config; -use DragonCode\LaravelActions\Notifications\Notification; use DragonCode\LaravelActions\Repositories\ActionRepository; use DragonCode\LaravelActions\Values\Options; use DragonCode\Support\Exceptions\FileNotFoundException; diff --git a/src/Values/Options.php b/src/Values/Options.php index 9e409320..a3231e0c 100644 --- a/src/Values/Options.php +++ b/src/Values/Options.php @@ -16,7 +16,7 @@ class Options extends DataTransferObject public ?string $name = null; - public ?string $path = null; + public array $path = []; public bool $realpath = false; From 5ad8c1fd99145669c991ee0914a3ea2072f5353f Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Thu, 6 Oct 2022 03:37:57 +0300 Subject: [PATCH 086/153] Added funding block to `composer.json` --- composer.json | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/composer.json b/composer.json index 692b9165..b224d095 100644 --- a/composer.json +++ b/composer.json @@ -24,6 +24,24 @@ "issues": "https://github.com/TheDragonCode/laravel-migration-actions/issues", "source": "https://github.com/TheDragonCode/laravel-migration-actions" }, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/TheDragonCode" + }, + { + "type": "open_collective", + "url": "https://opencollective.com/dragon-code" + }, + { + "type": "boosty", + "url": "https://boosty.to/dragon-code" + }, + { + "type": "yoomoney", + "url": "https://yoomoney.ru/to/410012608840929" + } + ], "require": { "php": "^8.0", "composer-runtime-api": "^2.2", From f0806162e3bc50043151c2835528ff8bf9586a50 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Thu, 6 Oct 2022 22:00:39 +0300 Subject: [PATCH 087/153] Fixed arguments --- src/Console/Command.php | 25 ++++++++++++++++++++++++- src/Console/Make.php | 5 ++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/Console/Command.php b/src/Console/Command.php index 80f61c2f..562fec19 100644 --- a/src/Console/Command.php +++ b/src/Console/Command.php @@ -11,6 +11,7 @@ use DragonCode\Support\Facades\Helpers\Arr; use Illuminate\Console\Command as BaseCommand; use Illuminate\Container\Container; +use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; abstract class Command extends BaseCommand @@ -19,6 +20,8 @@ abstract class Command extends BaseCommand protected Processor|string $processor; + protected array $arguments = []; + protected array $options = [ Options::CONNECTION, Options::FORCE, @@ -44,6 +47,13 @@ protected function resolveProcessor(): Processor ]); } + protected function configure(): void + { + foreach ($this->getFilteredArguments() as $argument) { + $this->addArgument(...$argument); + } + } + protected function getOptionsDto(): OptionsDto { return OptionsDto::fromArray($this->options()); @@ -62,10 +72,23 @@ protected function availableOptions(): array [Options::BEFORE, null, InputOption::VALUE_NONE, 'Run actions marked as before'], [Options::CONNECTION, null, InputOption::VALUE_OPTIONAL, 'The database connection to use'], [Options::FORCE, null, InputOption::VALUE_NONE, 'Force the operation to run when in production'], - [Options::NAME, null, InputOption::VALUE_OPTIONAL, 'The name of the action'], [Options::PATH, null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'The path(s) to the actions files to be executed'], [Options::REALPATH, null, InputOption::VALUE_NONE, 'Indicate any provided action file paths are pre-resolved absolute paths'], [Options::STEP, null, InputOption::VALUE_OPTIONAL, 'Force the actions to be run so they can be rolled back individually'], ]; } + + protected function getFilteredArguments(): array + { + return Arr::of($this->availableArguments()) + ->filter(fn (array $argument) => in_array($argument[0], $this->arguments)) + ->toArray(); + } + + protected function availableArguments(): array + { + return [ + [Options::NAME, InputArgument::OPTIONAL, 'The name of the action'], + ]; + } } diff --git a/src/Console/Make.php b/src/Console/Make.php index 5c660b78..a01e1d70 100644 --- a/src/Console/Make.php +++ b/src/Console/Make.php @@ -15,9 +15,12 @@ class Make extends Command protected Processor|string $processor = MakeProcessor::class; + protected array $arguments = [ + Options::NAME, + ]; + protected array $options = [ Options::CONNECTION, Options::FORCE, - Options::NAME, ]; } From 31a1e31f8b9c288a69cb48479174842cf3a06de4 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Thu, 6 Oct 2022 23:06:34 +0300 Subject: [PATCH 088/153] Removed unecessary concern --- tests/Concerns/Path.php | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 tests/Concerns/Path.php diff --git a/tests/Concerns/Path.php b/tests/Concerns/Path.php deleted file mode 100644 index 465063ff..00000000 --- a/tests/Concerns/Path.php +++ /dev/null @@ -1,11 +0,0 @@ - Date: Thu, 6 Oct 2022 23:06:44 +0300 Subject: [PATCH 089/153] Update dependency --- composer.json | 2 +- src/Processors/Processor.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index b224d095..b296e4fa 100644 --- a/composer.json +++ b/composer.json @@ -48,7 +48,7 @@ "doctrine/dbal": "^2.13 || ^3.4", "dragon-code/laravel-support": "^3.4", "dragon-code/simple-dto": "^2.3", - "dragon-code/support": "^6.3", + "dragon-code/support": "^6.6", "illuminate/console": "^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0", "illuminate/container": "^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0", "illuminate/database": "^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0", diff --git a/src/Processors/Processor.php b/src/Processors/Processor.php index 17bd0f88..6ff1ac73 100644 --- a/src/Processors/Processor.php +++ b/src/Processors/Processor.php @@ -44,7 +44,7 @@ public function __construct( protected function getFiles(?Closure $filter = null, ?string $path = null): array { - $files = $this->file->names($path ?: $this->config->path(), $filter, true); + $files = $this->file->allPaths($path ?: $this->config->path(), $filter, true); return Arr::sort($files); } From 59734a52a290d767e18c9fc7d2e7d0f8558e6628 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Fri, 7 Oct 2022 01:20:50 +0300 Subject: [PATCH 090/153] Resolved Fresh command --- composer.json | 2 +- src/Console/Command.php | 2 +- src/Contracts/Notification.php | 4 +-- src/Notifications/Beautiful.php | 5 ++-- src/Notifications/Notification.php | 5 ++-- src/Processors/Fresh.php | 12 ++++++--- src/Processors/Processor.php | 6 ++--- src/Services/Migrator.php | 43 +++++++++++++++++++++--------- src/Values/Options.php | 10 +++++++ 9 files changed, 62 insertions(+), 27 deletions(-) diff --git a/composer.json b/composer.json index b296e4fa..46ed3612 100644 --- a/composer.json +++ b/composer.json @@ -47,7 +47,7 @@ "composer-runtime-api": "^2.2", "doctrine/dbal": "^2.13 || ^3.4", "dragon-code/laravel-support": "^3.4", - "dragon-code/simple-dto": "^2.3", + "dragon-code/simple-dto": "^2.5.1", "dragon-code/support": "^6.6", "illuminate/console": "^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0", "illuminate/container": "^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0", diff --git a/src/Console/Command.php b/src/Console/Command.php index 562fec19..91fbc73a 100644 --- a/src/Console/Command.php +++ b/src/Console/Command.php @@ -56,7 +56,7 @@ protected function configure(): void protected function getOptionsDto(): OptionsDto { - return OptionsDto::fromArray($this->options()); + return OptionsDto::fromArray(array_merge($this->options(), $this->arguments())); } protected function getOptions(): array diff --git a/src/Contracts/Notification.php b/src/Contracts/Notification.php index 0cbe3b37..cec6a7dd 100644 --- a/src/Contracts/Notification.php +++ b/src/Contracts/Notification.php @@ -5,7 +5,7 @@ namespace DragonCode\LaravelActions\Contracts; use Closure; -use Symfony\Component\Console\Output\OutputInterface; +use Illuminate\Console\OutputStyle; interface Notification { @@ -13,7 +13,7 @@ public function info(string $string): void; public function line(string $string, ?string $style = null): void; - public function setOutput(OutputInterface $output): self; + public function setOutput(OutputStyle $output): self; public function task(string $description, Closure $task): void; diff --git a/src/Notifications/Beautiful.php b/src/Notifications/Beautiful.php index bd425ec5..9f8d2285 100644 --- a/src/Notifications/Beautiful.php +++ b/src/Notifications/Beautiful.php @@ -6,7 +6,6 @@ use Closure; use Illuminate\Console\View\Components\Factory; -use Illuminate\Container\Container; class Beautiful extends Notification { @@ -37,12 +36,12 @@ public function twoColumn(string $first, string $second): void $this->components()->twoColumnDetail($first, $second, $this->verbosity); } - protected function components() + protected function components(): Factory { if (! is_null($this->components)) { return $this->components; } - return $this->components = Container::getInstance()->make(Factory::class, ['output' => $this->output]); + return $this->component = new Factory($this->output); } } diff --git a/src/Notifications/Notification.php b/src/Notifications/Notification.php index a0707169..ed4c8896 100644 --- a/src/Notifications/Notification.php +++ b/src/Notifications/Notification.php @@ -6,11 +6,12 @@ use Closure; use DragonCode\LaravelActions\Contracts\Notification as NotificationContract; +use Illuminate\Console\OutputStyle; use Symfony\Component\Console\Output\OutputInterface; abstract class Notification implements NotificationContract { - protected ?OutputInterface $output = null; + protected ?OutputStyle $output = null; protected int $verbosity = OutputInterface::VERBOSITY_NORMAL; @@ -24,7 +25,7 @@ abstract public function task(string $description, Closure $task): void; abstract public function twoColumn(string $first, string $second): void; - public function setOutput(OutputInterface $output): NotificationContract + public function setOutput(OutputStyle $output): NotificationContract { $this->output = $output; diff --git a/src/Processors/Fresh.php b/src/Processors/Fresh.php index 0fb8b1ca..0b488432 100644 --- a/src/Processors/Fresh.php +++ b/src/Processors/Fresh.php @@ -13,14 +13,13 @@ public function handle(): void { $this->drop(); $this->create(); + $this->migrate(); } protected function drop(): void { if ($this->repository->repositoryExists()) { - $this->repository->deleteRepository(); - - $this->notification->info('Actions repository successfully deleted.'); + $this->notification->task('Dropping all actions', fn () => $this->repository->deleteRepository()); } } @@ -31,4 +30,11 @@ protected function create(): void '--' . Options::FORCE => $this->options->force, ]); } + + protected function migrate(): void + { + $this->runCommand(Names::MIGRATE, [ + '--' . Options::CONNECTION => $this->options->connection, + ]); + } } diff --git a/src/Processors/Processor.php b/src/Processors/Processor.php index 6ff1ac73..e1caea6a 100644 --- a/src/Processors/Processor.php +++ b/src/Processors/Processor.php @@ -15,9 +15,9 @@ use DragonCode\LaravelActions\Values\Options; use DragonCode\Support\Facades\Helpers\Arr; use DragonCode\Support\Filesystem\File; +use Illuminate\Console\OutputStyle; use Illuminate\Contracts\Events\Dispatcher; use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Output\OutputInterface; abstract class Processor { @@ -28,7 +28,7 @@ abstract public function handle(): void; public function __construct( protected Options $options, protected InputInterface $input, - protected OutputInterface $output, + protected OutputStyle $output, protected Config $config, protected ActionRepository $repository, protected Git $git, @@ -39,7 +39,7 @@ public function __construct( ) { $this->notification->setOutput($this->output); $this->repository->setConnection($this->options->connection); - $this->migrator->setConnection($this->options->connection); + $this->migrator->setConnection($this->options->connection)->setOutput($this->output); } protected function getFiles(?Closure $filter = null, ?string $path = null): array diff --git a/src/Services/Migrator.php b/src/Services/Migrator.php index 4986e9a9..8ab3dcc1 100644 --- a/src/Services/Migrator.php +++ b/src/Services/Migrator.php @@ -10,7 +10,9 @@ use DragonCode\LaravelActions\Repositories\ActionRepository; use DragonCode\LaravelActions\Values\Options; use DragonCode\Support\Exceptions\FileNotFoundException; +use DragonCode\Support\Facades\Helpers\Str; use DragonCode\Support\Filesystem\File; +use Illuminate\Console\OutputStyle; use Illuminate\Contracts\Foundation\Application; use Illuminate\Support\Facades\DB; use Throwable; @@ -33,30 +35,39 @@ public function setConnection(?string $connection): self return $this; } + public function setOutput(OutputStyle $output): self + { + $this->notification->setOutput($output); + + return $this; + } + public function runUp(string $file, int $batch, Options $options): void { - $action = $this->resolve($file); + $action = $this->resolvePath($file); + $name = $this->resolveActionName($file); - if ($this->allowAction($action, $file, $options)) { + if ($this->allowAction($action, $name, $options)) { $this->hasAction($action, '__invoke') - ? $this->runAction($action, $file, '__invoke') - : $this->runAction($action, $file, 'up'); + ? $this->runAction($action, $name, '__invoke') + : $this->runAction($action, $name, 'up'); if ($this->allowLogging($action)) { - $this->log($file, $batch); + $this->log($name, $batch); } } } public function runDown(string $file): void { - $action = $this->resolve($file); + $action = $this->resolvePath($file); + $name = $this->resolveActionName($file); if ($this->hasAction($action, 'down')) { - $this->runAction($action, $file, 'down'); + $this->runAction($action, $name, 'down'); } - $this->deleteLog($file); + $this->deleteLog($name); } protected function hasAction(Action $action, string $method): bool @@ -99,7 +110,7 @@ protected function deleteLog(string $name): void $this->repository->delete($name); } - protected function allowAction(Action $action, string $name, Options $options): bool + protected function allowAction(Action $action, string $name, Options $options, bool $log = false): bool { if (! $this->allowEnvironment($action)) { $this->notification->info("Action: $name was skipped on this environment"); @@ -107,7 +118,7 @@ protected function allowAction(Action $action, string $name, Options $options): return false; } - if (! $this->allowBefore($action, $options)) { + if ($this->disallowBefore($action, $options)) { $this->notification->info("Action: $name was skipped by 'before' option"); return false; @@ -135,7 +146,7 @@ protected function allowEnvironment(Action $action): bool return ! (! empty($except) && in_array($env, $except)); } - protected function allowBefore(Action $action, Options $options): bool + protected function disallowBefore(Action $action, Options $options): bool { return $options->before && ! $action->hasBefore(); } @@ -145,7 +156,7 @@ protected function allowLogging(Action $action): bool return $action->isOnce(); } - protected function resolve(string $path): Action + protected function resolvePath(string $path): Action { if ($this->file->exists($path)) { return require $path; @@ -153,4 +164,12 @@ protected function resolve(string $path): Action throw new FileNotFoundException($path); } + + protected function resolveActionName(string $path): string + { + return Str::of(realpath($path)) + ->after(realpath($this->config->path())) + ->ltrim('\\/') + ->toString(); + } } diff --git a/src/Values/Options.php b/src/Values/Options.php index a3231e0c..7acba7ce 100644 --- a/src/Values/Options.php +++ b/src/Values/Options.php @@ -5,6 +5,7 @@ namespace DragonCode\LaravelActions\Values; use DragonCode\SimpleDataTransferObject\DataTransferObject; +use DragonCode\Support\Facades\Helpers\Str; class Options extends DataTransferObject { @@ -21,4 +22,13 @@ class Options extends DataTransferObject public bool $realpath = false; public ?int $step = null; + + protected function castName(?string $value): ?string + { + if (! empty($value)) { + return Str::snake($value); + } + + return null; + } } From ac03dbe689d2112acffe7dbb26ddfcd939aa7f66 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Fri, 7 Oct 2022 02:18:59 +0300 Subject: [PATCH 091/153] WIP --- src/Console/Command.php | 4 +- src/Processors/Install.php | 8 ++ src/Processors/Processor.php | 2 +- src/Processors/Rollback.php | 4 +- tests/Commands/FreshTest.php | 8 +- tests/Commands/InstallTest.php | 8 +- tests/Commands/MakeTest.php | 8 +- tests/Commands/MigrateTest.php | 100 ++++++++++----------- tests/Commands/RefreshTest.php | 8 +- tests/Commands/ResetTest.php | 8 +- tests/Commands/RollbackTest.php | 65 +++++++------- tests/Commands/StatusTest.php | 10 +-- tests/fixtures/app/stubs/make_example.stub | 9 +- 13 files changed, 130 insertions(+), 112 deletions(-) diff --git a/src/Console/Command.php b/src/Console/Command.php index 91fbc73a..59dd4175 100644 --- a/src/Console/Command.php +++ b/src/Console/Command.php @@ -32,10 +32,10 @@ public function handle(): int if ($this->allowToProceed()) { $this->resolveProcessor()->handle(); - return 0; + return self::SUCCESS; } - return 1; + return self::FAILURE; } protected function resolveProcessor(): Processor diff --git a/src/Processors/Install.php b/src/Processors/Install.php index ffbf384a..dc099ba2 100644 --- a/src/Processors/Install.php +++ b/src/Processors/Install.php @@ -4,6 +4,8 @@ namespace DragonCode\LaravelActions\Processors; +use DragonCode\Support\Facades\Filesystem\Directory; + class Install extends Processor { public function handle(): void @@ -15,6 +17,7 @@ public function handle(): void } $this->create(); + $this->ensureDirectory(); } protected function exists(): bool @@ -28,4 +31,9 @@ protected function create(): void $this->notification->info('Actions repository successfully created.'); } + + protected function ensureDirectory(): void + { + Directory::ensureDirectory($this->config->path()); + } } diff --git a/src/Processors/Processor.php b/src/Processors/Processor.php index e1caea6a..dd3d0bf5 100644 --- a/src/Processors/Processor.php +++ b/src/Processors/Processor.php @@ -57,7 +57,7 @@ protected function runCommand(string $command, array $options = []): void protected function tableNotFound(): bool { if (! $this->repository->repositoryExists()) { - $this->notification->warning('Actions table not found'); + $this->notification->warning('Actions table not found.'); return true; } diff --git a/src/Processors/Rollback.php b/src/Processors/Rollback.php index fa3111b7..b0758f79 100644 --- a/src/Processors/Rollback.php +++ b/src/Processors/Rollback.php @@ -47,7 +47,9 @@ protected function getActions(?int $step): array protected function rollbackAction(string $action): void { - $this->migrator->runDown($action); + $this->migrator->runDown( + $this->config->path($action) + ); } protected function nothingToRollback(): bool diff --git a/tests/Commands/FreshTest.php b/tests/Commands/FreshTest.php index 209a4ac8..6a2e5b98 100644 --- a/tests/Commands/FreshTest.php +++ b/tests/Commands/FreshTest.php @@ -13,18 +13,18 @@ public function testFreshCommand(): void { $this->assertDatabaseDoesntTable($this->table); - $this->artisan(Names::INSTALL)->run(); + $this->artisan(Names::INSTALL)->assertSuccessful(); $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 0); - $this->artisan(Names::MAKE, ['name' => 'Fresh'])->run(); - $this->artisan(Names::MIGRATE)->run(); + $this->artisan(Names::MAKE, ['name' => 'Fresh'])->assertSuccessful(); + $this->artisan(Names::MIGRATE)->assertSuccessful(); $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 1); - $this->artisan(Names::FRESH)->run(); + $this->artisan(Names::FRESH)->assertSuccessful(); $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 1); diff --git a/tests/Commands/InstallTest.php b/tests/Commands/InstallTest.php index d27cfd99..94d75b02 100644 --- a/tests/Commands/InstallTest.php +++ b/tests/Commands/InstallTest.php @@ -11,14 +11,18 @@ public function testNotFound(): void { $this->assertDatabaseDoesntTable($this->table); - $this->artisan(Names::STATUS)->expectsOutput('Actions table not found.'); + $this->artisan(Names::STATUS) + ->expectsOutputToContain('Actions table not found.') + ->assertSuccessful(); + + $this->assertDatabaseDoesntTable($this->table); } public function testCreate(): void { $this->assertDatabaseDoesntTable($this->table); - $this->artisan(Names::INSTALL)->run(); + $this->artisan(Names::INSTALL)->assertSuccessful(); $this->assertDatabaseHasTable($this->table); } diff --git a/tests/Commands/MakeTest.php b/tests/Commands/MakeTest.php index 78e49e9b..fe3fead3 100644 --- a/tests/Commands/MakeTest.php +++ b/tests/Commands/MakeTest.php @@ -11,11 +11,11 @@ public function testMakingFiles() { $name = 'MakeExample'; - $path = $this->getActionsPath(date('Y_m_d_His') . '_make_example.php'); + $path = $this->getActionsPath() . '/' . date('Y_m_d_His') . '_make_example.php'; $this->assertFileDoesNotExist($path); - $this->artisan(Names::MAKE, compact('name'))->run(); + $this->artisan(Names::MAKE, compact('name'))->assertSuccessful(); $this->assertFileExists($path); @@ -29,11 +29,11 @@ public function testMakingFiles() public function testAutoName() { - $path = $this->getActionsPath(date('Y_m_d_His') . '_auto.php'); + $path = $this->getActionsPath() . '/' . date('Y_m_d_His') . '_auto.php'; $this->assertFileDoesNotExist($path); - $this->artisan(Names::MAKE)->run(); + $this->artisan(Names::MAKE)->assertSuccessful(); $this->assertFileExists($path); } diff --git a/tests/Commands/MigrateTest.php b/tests/Commands/MigrateTest.php index cc0b0931..1e320ed9 100644 --- a/tests/Commands/MigrateTest.php +++ b/tests/Commands/MigrateTest.php @@ -14,13 +14,13 @@ public function testMigrationCommand() { $this->assertDatabaseDoesntTable($this->table); - $this->artisan(Names::INSTALL)->run(); + $this->artisan(Names::INSTALL)->assertSuccessful(); $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 0); - $this->artisan(Names::MAKE, ['name' => 'TestMigration'])->run(); - $this->artisan(Names::MIGRATE)->run(); + $this->artisan(Names::MAKE, ['name' => 'TestMigration'])->assertSuccessful(); + $this->artisan(Names::MIGRATE)->assertSuccessful(); $this->assertDatabaseCount($this->table, 1); $this->assertDatabaseMigrationHas($this->table, 'test_migration'); @@ -32,27 +32,27 @@ public function testOnce() $table = 'every_time'; - $this->artisan(Names::INSTALL)->run(); + $this->artisan(Names::INSTALL)->assertSuccessful(); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, $table); - $this->artisan(Names::MIGRATE)->run(); + $this->artisan(Names::MIGRATE)->assertSuccessful(); $this->assertDatabaseCount($table, 1); $this->assertDatabaseCount($this->table, 10); $this->assertDatabaseMigrationDoesntLike($this->table, $table); - $this->artisan(Names::MIGRATE)->run(); + $this->artisan(Names::MIGRATE)->assertSuccessful(); $this->assertDatabaseCount($table, 2); $this->assertDatabaseCount($this->table, 10); $this->assertDatabaseMigrationDoesntLike($this->table, $table); - $this->artisan(Names::MIGRATE)->run(); + $this->artisan(Names::MIGRATE)->assertSuccessful(); $this->assertDatabaseCount($table, 3); $this->assertDatabaseCount($this->table, 10); $this->assertDatabaseMigrationDoesntLike($this->table, $table); - $this->artisan(Names::MIGRATE)->run(); + $this->artisan(Names::MIGRATE)->assertSuccessful(); $this->assertDatabaseCount($table, 4); $this->assertDatabaseCount($this->table, 10); @@ -65,12 +65,12 @@ public function testSuccessTransaction() $table = 'transactions'; - $this->artisan(Names::INSTALL)->run(); + $this->artisan(Names::INSTALL)->assertSuccessful(); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, $table); - $this->artisan(Names::MIGRATE)->run(); + $this->artisan(Names::MIGRATE)->assertSuccessful(); $this->assertDatabaseCount($table, 3); $this->assertDatabaseCount($this->table, 1); @@ -83,14 +83,14 @@ public function testFailedTransaction() $table = 'transactions'; - $this->artisan(Names::INSTALL)->run(); + $this->artisan(Names::INSTALL)->assertSuccessful(); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, $table); try { - $this->artisan(Names::MIGRATE)->run(); + $this->artisan(Names::MIGRATE)->assertSuccessful(); } catch (Exception $e) { $this->assertSame(Exception::class, get_class($e)); @@ -108,7 +108,7 @@ public function testSingleEnvironment() $table = 'environment'; - $this->artisan(Names::INSTALL)->run(); + $this->artisan(Names::INSTALL)->assertSuccessful(); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); @@ -117,7 +117,7 @@ public function testSingleEnvironment() $this->assertDatabaseMigrationDoesntLike($this->table, 'run_on_testing'); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_except_production'); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_except_testing'); - $this->artisan(Names::MIGRATE)->run(); + $this->artisan(Names::MIGRATE)->assertSuccessful(); $this->assertDatabaseCount($table, 5); $this->assertDatabaseCount($this->table, 10); @@ -126,7 +126,7 @@ public function testSingleEnvironment() $this->assertDatabaseMigrationHas($this->table, 'run_on_testing'); $this->assertDatabaseMigrationHas($this->table, 'run_except_production'); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_except_testing'); - $this->artisan(Names::MIGRATE)->run(); + $this->artisan(Names::MIGRATE)->assertSuccessful(); $this->assertDatabaseCount($table, 5); $this->assertDatabaseCount($this->table, 10); @@ -143,7 +143,7 @@ public function testManyEnvironments() $table = 'environment'; - $this->artisan(Names::INSTALL)->run(); + $this->artisan(Names::INSTALL)->assertSuccessful(); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); @@ -154,7 +154,7 @@ public function testManyEnvironments() $this->assertDatabaseMigrationDoesntLike($this->table, 'run_except_production'); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_except_testing'); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_except_many_environments'); - $this->artisan(Names::MIGRATE)->run(); + $this->artisan(Names::MIGRATE)->assertSuccessful(); $this->assertDatabaseCount($table, 5); $this->assertDatabaseCount($this->table, 10); @@ -165,7 +165,7 @@ public function testManyEnvironments() $this->assertDatabaseMigrationHas($this->table, 'run_except_production'); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_except_testing'); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_except_many_environments'); - $this->artisan(Names::MIGRATE)->run(); + $this->artisan(Names::MIGRATE)->assertSuccessful(); $this->assertDatabaseCount($table, 5); $this->assertDatabaseCount($this->table, 10); @@ -184,19 +184,19 @@ public function testAllow() $table = 'environment'; - $this->artisan(Names::INSTALL)->run(); + $this->artisan(Names::INSTALL)->assertSuccessful(); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_allow'); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_disallow'); - $this->artisan(Names::MIGRATE)->run(); + $this->artisan(Names::MIGRATE)->assertSuccessful(); $this->assertDatabaseCount($table, 5); $this->assertDatabaseCount($this->table, 10); $this->assertDatabaseMigrationHas($this->table, 'run_allow'); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_disallow'); - $this->artisan(Names::MIGRATE)->run(); + $this->artisan(Names::MIGRATE)->assertSuccessful(); $this->assertDatabaseCount($table, 5); $this->assertDatabaseCount($this->table, 10); @@ -210,12 +210,12 @@ public function testUpSuccess() $table = 'success'; - $this->artisan(Names::INSTALL)->run(); + $this->artisan(Names::INSTALL)->assertSuccessful(); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_success'); - $this->artisan(Names::MIGRATE)->run(); + $this->artisan(Names::MIGRATE)->assertSuccessful(); $this->assertDatabaseCount($table, 2); $this->assertDatabaseCount($this->table, 10); @@ -228,12 +228,12 @@ public function testUpSuccessOnFailed() $table = 'success'; - $this->artisan(Names::INSTALL)->run(); + $this->artisan(Names::INSTALL)->assertSuccessful(); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_success_on_failed'); - $this->artisan(Names::MIGRATE)->run(); + $this->artisan(Names::MIGRATE)->assertSuccessful(); $this->assertDatabaseCount($table, 2); $this->assertDatabaseCount($this->table, 10); @@ -242,7 +242,7 @@ public function testUpSuccessOnFailed() try { $this->copySuccessFailureMethod(); - $this->artisan(Names::MIGRATE)->run(); + $this->artisan(Names::MIGRATE)->assertSuccessful(); } catch (Throwable $e) { $this->assertInstanceOf(Exception::class, $e); @@ -263,12 +263,12 @@ public function testUpFailed() $table = 'failed'; - $this->artisan(Names::INSTALL)->run(); + $this->artisan(Names::INSTALL)->assertSuccessful(); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_failed'); - $this->artisan(Names::MIGRATE)->run(); + $this->artisan(Names::MIGRATE)->assertSuccessful(); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 10); @@ -281,12 +281,12 @@ public function testUpFailedOnException() $table = 'failed'; - $this->artisan(Names::INSTALL)->run(); + $this->artisan(Names::INSTALL)->assertSuccessful(); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_failed_failure'); - $this->artisan(Names::MIGRATE)->run(); + $this->artisan(Names::MIGRATE)->assertSuccessful(); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 10); @@ -295,7 +295,7 @@ public function testUpFailedOnException() try { $this->copyFailedMethod(); - $this->artisan(Names::MIGRATE)->run(); + $this->artisan(Names::MIGRATE)->assertSuccessful(); } catch (Throwable $e) { $this->assertInstanceOf(Exception::class, $e); @@ -318,12 +318,12 @@ public function testPathAsFileWithExtension() $path = 'sub_path/2021_12_15_205804_baz.php'; - $this->artisan(Names::INSTALL)->run(); + $this->artisan(Names::INSTALL)->assertSuccessful(); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'baz'); - $this->artisan(Names::MIGRATE, ['--path' => $path])->run(); + $this->artisan(Names::MIGRATE, ['--path' => $path])->assertSuccessful(); $this->assertDatabaseCount($table, 1); $this->assertDatabaseCount($this->table, 1); @@ -338,12 +338,12 @@ public function testPathAsFileWithoutExtension() $path = 'sub_path/2021_12_15_205804_baz'; - $this->artisan(Names::INSTALL)->run(); + $this->artisan(Names::INSTALL)->assertSuccessful(); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'baz'); - $this->artisan(Names::MIGRATE, ['--path' => $path])->run(); + $this->artisan(Names::MIGRATE, ['--path' => $path])->assertSuccessful(); $this->assertDatabaseCount($table, 1); $this->assertDatabaseCount($this->table, 1); @@ -358,12 +358,12 @@ public function testPathAsDirectory() $path = 'sub_path'; - $this->artisan(Names::INSTALL)->run(); + $this->artisan(Names::INSTALL)->assertSuccessful(); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'baz'); - $this->artisan(Names::MIGRATE, ['--path' => $path])->run(); + $this->artisan(Names::MIGRATE, ['--path' => $path])->assertSuccessful(); $this->assertDatabaseCount($table, 1); $this->assertDatabaseCount($this->table, 1); @@ -374,11 +374,11 @@ public function testMigrationNotFound() { $this->assertDatabaseDoesntTable($this->table); - $this->artisan(Names::INSTALL)->run(); + $this->artisan(Names::INSTALL)->assertSuccessful(); $this->assertDatabaseHasTable($this->table); - $this->artisan(Names::STATUS)->expectsOutput('No actions found'); + $this->artisan(Names::STATUS)->expectsOutputToContain('No actions found'); } public function testDisabledBefore() @@ -387,19 +387,19 @@ public function testDisabledBefore() $table = 'before'; - $this->artisan(Names::INSTALL)->run(); + $this->artisan(Names::INSTALL)->assertSuccessful(); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'test_before_enabled'); $this->assertDatabaseMigrationDoesntLike($this->table, 'test_before_disabled'); - $this->artisan(Names::MIGRATE)->run(); + $this->artisan(Names::MIGRATE)->assertSuccessful(); $this->assertDatabaseCount($table, 2); $this->assertDatabaseCount($this->table, 10); $this->assertDatabaseMigrationHas($this->table, 'test_before_enabled'); $this->assertDatabaseMigrationHas($this->table, 'test_before_disabled'); - $this->artisan(Names::MIGRATE)->run(); + $this->artisan(Names::MIGRATE)->assertSuccessful(); $this->assertDatabaseCount($table, 2); $this->assertDatabaseCount($this->table, 10); @@ -413,19 +413,19 @@ public function testEnabledBefore() $table = 'before'; - $this->artisan(Names::INSTALL)->run(); + $this->artisan(Names::INSTALL)->assertSuccessful(); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'test_before_enabled'); $this->assertDatabaseMigrationDoesntLike($this->table, 'test_before_disabled'); - $this->artisan(Names::MIGRATE, ['--before' => true])->run(); + $this->artisan(Names::MIGRATE, ['--before' => true])->assertSuccessful(); $this->assertDatabaseCount($table, 1); $this->assertDatabaseCount($this->table, 9); $this->assertDatabaseMigrationHas($this->table, 'test_before_enabled'); $this->assertDatabaseMigrationDoesntLike($this->table, 'test_before_disabled'); - $this->artisan(Names::MIGRATE, ['--before' => true])->run(); + $this->artisan(Names::MIGRATE, ['--before' => true])->assertSuccessful(); $this->assertDatabaseCount($table, 1); $this->assertDatabaseCount($this->table, 9); @@ -439,31 +439,31 @@ public function testMixedBefore() $table = 'before'; - $this->artisan(Names::INSTALL)->run(); + $this->artisan(Names::INSTALL)->assertSuccessful(); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'test_before_enabled'); $this->assertDatabaseMigrationDoesntLike($this->table, 'test_before_disabled'); - $this->artisan(Names::MIGRATE, ['--before' => true])->run(); + $this->artisan(Names::MIGRATE, ['--before' => true])->assertSuccessful(); $this->assertDatabaseCount($table, 1); $this->assertDatabaseCount($this->table, 9); $this->assertDatabaseMigrationHas($this->table, 'test_before_enabled'); $this->assertDatabaseMigrationDoesntLike($this->table, 'test_before_disabled'); - $this->artisan(Names::MIGRATE, ['--before' => true])->run(); + $this->artisan(Names::MIGRATE, ['--before' => true])->assertSuccessful(); $this->assertDatabaseCount($table, 1); $this->assertDatabaseCount($this->table, 9); $this->assertDatabaseMigrationHas($this->table, 'test_before_enabled'); $this->assertDatabaseMigrationDoesntLike($this->table, 'test_before_disabled'); - $this->artisan(Names::MIGRATE)->run(); + $this->artisan(Names::MIGRATE)->assertSuccessful(); $this->assertDatabaseCount($table, 2); $this->assertDatabaseCount($this->table, 10); $this->assertDatabaseMigrationHas($this->table, 'test_before_enabled'); $this->assertDatabaseMigrationHas($this->table, 'test_before_disabled'); - $this->artisan(Names::MIGRATE)->run(); + $this->artisan(Names::MIGRATE)->assertSuccessful(); $this->assertDatabaseCount($table, 2); $this->assertDatabaseCount($this->table, 10); diff --git a/tests/Commands/RefreshTest.php b/tests/Commands/RefreshTest.php index c51e519b..01e5be7a 100644 --- a/tests/Commands/RefreshTest.php +++ b/tests/Commands/RefreshTest.php @@ -11,18 +11,18 @@ public function testRefreshCommand() { $this->assertDatabaseDoesntTable($this->table); - $this->artisan(Names::INSTALL)->run(); + $this->artisan(Names::INSTALL)->assertSuccessful(); $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 0); - $this->artisan(Names::MAKE, ['name' => 'Refresh'])->run(); - $this->artisan(Names::MIGRATE)->run(); + $this->artisan(Names::MAKE, ['name' => 'Refresh'])->assertSuccessful(); + $this->artisan(Names::MIGRATE)->assertSuccessful(); $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 1); - $this->artisan(Names::REFRESH)->run(); + $this->artisan(Names::REFRESH)->assertSuccessful(); $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 1); diff --git a/tests/Commands/ResetTest.php b/tests/Commands/ResetTest.php index ec2d7376..31ad1f71 100644 --- a/tests/Commands/ResetTest.php +++ b/tests/Commands/ResetTest.php @@ -11,19 +11,19 @@ public function testResetCommand() { $this->assertDatabaseDoesntTable($this->table); - $this->artisan(Names::INSTALL)->run(); + $this->artisan(Names::INSTALL)->assertSuccessful(); $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 0); - $this->artisan(Names::MAKE, ['name' => 'Reset'])->run(); - $this->artisan(Names::MIGRATE)->run(); + $this->artisan(Names::MAKE, ['name' => 'Reset'])->assertSuccessful(); + $this->artisan(Names::MIGRATE)->assertSuccessful(); $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 1); $this->assertDatabaseMigrationHas($this->table, 'reset'); - $this->artisan(Names::RESET)->run(); + $this->artisan(Names::RESET)->assertSuccessful(); $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 0); diff --git a/tests/Commands/RollbackTest.php b/tests/Commands/RollbackTest.php index bd02f4f1..4d895e85 100644 --- a/tests/Commands/RollbackTest.php +++ b/tests/Commands/RollbackTest.php @@ -14,14 +14,15 @@ public function testRollbackCommand() { $this->assertDatabaseDoesntTable($this->table); - $this->artisan(Names::INSTALL)->run(); + $this->artisan(Names::INSTALL)->assertSuccessful(); $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 0); - $this->artisan(Names::MAKE, ['name' => 'RollbackOne'])->run(); - $this->artisan(Names::MAKE, ['name' => 'RollbackTwo'])->run(); - $this->artisan(Names::MIGRATE)->run(); + $this->artisan(Names::MAKE, ['name' => 'RollbackOne'])->assertSuccessful(); + $this->artisan(Names::MAKE, ['name' => 'RollbackTwo'])->assertSuccessful(); + + $this->artisan(Names::MIGRATE)->assertSuccessful(); $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 2); @@ -30,18 +31,18 @@ public function testRollbackCommand() $this->assertDatabaseMigrationHas($this->table, 'rollback_two'); $this->assertDatabaseMigrationDoesntLike($this->table, 'rollback_tree'); - $this->artisan(Names::ROLLBACK)->run(); + $this->artisan(Names::ROLLBACK)->assertSuccessful(); $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 0); - $this->artisan(Names::MIGRATE)->run(); + $this->artisan(Names::MIGRATE)->assertSuccessful(); $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 2); - $this->artisan(Names::MAKE, ['name' => 'RollbackTree'])->run(); - $this->artisan(Names::MIGRATE)->run(); + $this->artisan(Names::MAKE, ['name' => 'RollbackTree'])->assertSuccessful(); + $this->artisan(Names::MIGRATE)->assertSuccessful(); $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 3); @@ -57,7 +58,7 @@ public function testEnvironment() $table = 'environment'; - $this->artisan(Names::MIGRATE)->run(); + $this->artisan(Names::MIGRATE)->assertSuccessful(); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); @@ -65,7 +66,7 @@ public function testEnvironment() $this->assertDatabaseMigrationDoesntLike($this->table, 'run_on_production'); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_on_testing'); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_on_many_environments'); - $this->artisan(Names::MIGRATE)->run(); + $this->artisan(Names::MIGRATE)->assertSuccessful(); $this->assertDatabaseCount($table, 5); $this->assertDatabaseCount($this->table, 10); @@ -73,9 +74,9 @@ public function testEnvironment() $this->assertDatabaseMigrationDoesntLike($this->table, 'run_on_production'); $this->assertDatabaseMigrationHas($this->table, 'run_on_testing'); $this->assertDatabaseMigrationHas($this->table, 'run_on_many_environments'); - $this->artisan(Names::MIGRATE)->run(); + $this->artisan(Names::MIGRATE)->assertSuccessful(); - $this->artisan(Names::ROLLBACK)->run(); + $this->artisan(Names::ROLLBACK)->assertSuccessful(); $this->assertDatabaseCount($table, 10); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_on_all'); @@ -90,18 +91,18 @@ public function testDownSuccess() $table = 'success'; - $this->artisan(Names::MIGRATE)->run(); + $this->artisan(Names::MIGRATE)->assertSuccessful(); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_success'); - $this->artisan(Names::MIGRATE)->run(); + $this->artisan(Names::MIGRATE)->assertSuccessful(); $this->assertDatabaseCount($table, 2); $this->assertDatabaseCount($this->table, 10); $this->assertDatabaseMigrationHas($this->table, 'run_success'); - $this->artisan(Names::ROLLBACK)->run(); + $this->artisan(Names::ROLLBACK)->assertSuccessful(); $this->assertDatabaseCount($table, 4); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_success'); @@ -113,12 +114,12 @@ public function testDownSuccessOnFailed() $table = 'success'; - $this->artisan(Names::MIGRATE)->run(); + $this->artisan(Names::MIGRATE)->assertSuccessful(); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_success_on_failed'); - $this->artisan(Names::MIGRATE)->run(); + $this->artisan(Names::MIGRATE)->assertSuccessful(); $this->assertDatabaseCount($table, 2); $this->assertDatabaseCount($this->table, 10); @@ -129,7 +130,7 @@ public function testDownSuccessOnFailed() $this->table()->insert(['migration' => '2021_12_23_165048_run_success_on_failed', 'batch' => 999]); - $this->artisan(Names::ROLLBACK)->run(); + $this->artisan(Names::ROLLBACK)->assertSuccessful(); } catch (Throwable $e) { $this->assertInstanceOf(Exception::class, $e); @@ -150,18 +151,18 @@ public function testDownFailed() $table = 'failed'; - $this->artisan(Names::MIGRATE)->run(); + $this->artisan(Names::MIGRATE)->assertSuccessful(); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_failed'); - $this->artisan(Names::MIGRATE)->run(); + $this->artisan(Names::MIGRATE)->assertSuccessful(); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 10); $this->assertDatabaseMigrationHas($this->table, 'run_failed'); - $this->artisan(Names::ROLLBACK)->run(); + $this->artisan(Names::ROLLBACK)->assertSuccessful(); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_failed'); @@ -173,12 +174,12 @@ public function testUpFailedOnException() $table = 'failed'; - $this->artisan(Names::MIGRATE)->run(); + $this->artisan(Names::MIGRATE)->assertSuccessful(); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_failed_failure'); - $this->artisan(Names::MIGRATE)->run(); + $this->artisan(Names::MIGRATE)->assertSuccessful(); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 10); @@ -189,7 +190,7 @@ public function testUpFailedOnException() $this->table()->insert(['migration' => '2021_12_23_184029_run_failed_failure', 'batch' => 999]); - $this->artisan(Names::ROLLBACK)->run(); + $this->artisan(Names::ROLLBACK)->assertSuccessful(); } catch (Throwable $e) { $this->assertInstanceOf(Exception::class, $e); @@ -210,21 +211,21 @@ public function testDisabledBefore() $table = 'before'; - $this->artisan(Names::MIGRATE)->run(); + $this->artisan(Names::MIGRATE)->assertSuccessful(); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'test_before_enabled'); $this->assertDatabaseMigrationDoesntLike($this->table, 'test_before_disabled'); - $this->artisan(Names::MIGRATE)->run(); + $this->artisan(Names::MIGRATE)->assertSuccessful(); $this->assertDatabaseCount($table, 2); $this->assertDatabaseCount($this->table, 10); $this->assertDatabaseMigrationHas($this->table, 'test_before_enabled'); $this->assertDatabaseMigrationHas($this->table, 'test_before_disabled'); - $this->artisan(Names::MIGRATE)->run(); + $this->artisan(Names::MIGRATE)->assertSuccessful(); - $this->artisan(Names::ROLLBACK)->run(); + $this->artisan(Names::ROLLBACK)->assertSuccessful(); $this->assertDatabaseCount($table, 4); $this->assertDatabaseCount($this->table, 0); @@ -238,21 +239,21 @@ public function testEnabledBefore() $table = 'before'; - $this->artisan(Names::MIGRATE)->run(); + $this->artisan(Names::MIGRATE)->assertSuccessful(); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'test_before_enabled'); $this->assertDatabaseMigrationDoesntLike($this->table, 'test_before_disabled'); - $this->artisan(Names::MIGRATE, ['--before' => true])->run(); + $this->artisan(Names::MIGRATE, ['--before' => true])->assertSuccessful(); $this->assertDatabaseCount($table, 1); $this->assertDatabaseCount($this->table, 9); $this->assertDatabaseMigrationHas($this->table, 'test_before_enabled'); $this->assertDatabaseMigrationDoesntLike($this->table, 'test_before_disabled'); - $this->artisan(Names::MIGRATE, ['--before' => true])->run(); + $this->artisan(Names::MIGRATE, ['--before' => true])->assertSuccessful(); - $this->artisan(Names::ROLLBACK)->run(); + $this->artisan(Names::ROLLBACK)->assertSuccessful(); $this->assertDatabaseCount($table, 2); $this->assertDatabaseCount($this->table, 0); diff --git a/tests/Commands/StatusTest.php b/tests/Commands/StatusTest.php index d92aa7a0..b8633576 100644 --- a/tests/Commands/StatusTest.php +++ b/tests/Commands/StatusTest.php @@ -11,19 +11,19 @@ public function testStatusCommand() { $this->assertDatabaseDoesntTable($this->table); - $this->artisan(Names::INSTALL)->run(); + $this->artisan(Names::INSTALL)->assertSuccessful(); $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 0); - $this->artisan(Names::STATUS)->expectsTable([], [])->run(); + $this->artisan(Names::STATUS)->expectsTable([], [])->assertSuccessful(); - $this->artisan(Names::MAKE, ['name' => 'Status'])->run(); - $this->artisan(Names::MIGRATE)->run(); + $this->artisan(Names::MAKE, ['name' => 'Status'])->assertSuccessful(); + $this->artisan(Names::MIGRATE)->assertSuccessful(); $this->assertDatabaseCount($this->table, 1); - $this->artisan(Names::STATUS)->run(); + $this->artisan(Names::STATUS)->assertSuccessful(); $this->assertDatabaseMigrationHas($this->table, 'status'); } diff --git a/tests/fixtures/app/stubs/make_example.stub b/tests/fixtures/app/stubs/make_example.stub index 09847ca5..05b88896 100644 --- a/tests/fixtures/app/stubs/make_example.stub +++ b/tests/fixtures/app/stubs/make_example.stub @@ -1,14 +1,17 @@ Date: Fri, 7 Oct 2022 02:21:07 +0300 Subject: [PATCH 092/153] Update tests --- .github/workflows/laravel.yml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/laravel.yml b/.github/workflows/laravel.yml index 6cf56916..a82c1b1a 100644 --- a/.github/workflows/laravel.yml +++ b/.github/workflows/laravel.yml @@ -9,18 +9,19 @@ jobs: fail-fast: true matrix: laravel: [ "6.0", "7.0", "8.0", "9.0", "10.0" ] - php: [ "8.0", "8.1" ] + php: [ "8.0", "8.1", "8.2" ] + prefer: [ "stable", "lowest" ] exclude: - laravel: "6.0" - php: "8.1" + php: [ "8.1", "8.2" ] - laravel: "7.0" - php: "8.1" + php: [ "8.1", "8.2" ] - laravel: "10.0" php: "8.0" - name: Laravel ${{ matrix.laravel }}, PHP ${{ matrix.php }} + name: Laravel ${{ matrix.laravel }}, PHP ${{ matrix.php }}, Prefer ${{ matrix.prefer }} steps: - name: Checkout code @@ -34,7 +35,7 @@ jobs: coverage: none - name: Install dependencies - run: composer require --dev laravel/framework:^${{ matrix.laravel }} + run: composer require --dev laravel/framework:^${{ matrix.laravel }} --prefer-${{ matrix.prefer }} - name: Execute tests run: sudo vendor/bin/phpunit From 92386722f9b347504796c73f2e4bf9ccb152c90e Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Fri, 7 Oct 2022 02:22:45 +0300 Subject: [PATCH 093/153] Fixed GitHub Actions rules --- .github/workflows/laravel.yml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/laravel.yml b/.github/workflows/laravel.yml index a82c1b1a..5b56b90d 100644 --- a/.github/workflows/laravel.yml +++ b/.github/workflows/laravel.yml @@ -13,10 +13,16 @@ jobs: prefer: [ "stable", "lowest" ] exclude: - laravel: "6.0" - php: [ "8.1", "8.2" ] + php: "8.1" + + - laravel: "6.0" + php: "8.2" + + - laravel: "7.0" + php: "8.1" - laravel: "7.0" - php: [ "8.1", "8.2" ] + php: "8.2" - laravel: "10.0" php: "8.0" From 581eb932fb0a66fba6d63187f8224dab1dff4751 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Sat, 8 Oct 2022 01:33:54 +0300 Subject: [PATCH 094/153] Update tests rules --- .github/workflows/laravel.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/laravel.yml b/.github/workflows/laravel.yml index 5b56b90d..87b8bf98 100644 --- a/.github/workflows/laravel.yml +++ b/.github/workflows/laravel.yml @@ -8,8 +8,8 @@ jobs: strategy: fail-fast: true matrix: - laravel: [ "6.0", "7.0", "8.0", "9.0", "10.0" ] php: [ "8.0", "8.1", "8.2" ] + laravel: [ "6.0", "7.0", "8.0", "9.0", "10.0" ] prefer: [ "stable", "lowest" ] exclude: - laravel: "6.0" @@ -27,7 +27,7 @@ jobs: - laravel: "10.0" php: "8.0" - name: Laravel ${{ matrix.laravel }}, PHP ${{ matrix.php }}, Prefer ${{ matrix.prefer }} + name: PHP ${{ matrix.php }}, Laravel ${{ matrix.laravel }} ${{ matrix.prefer }} steps: - name: Checkout code From c930bd5e74d2f4c0ecd599c8f22f92e467f49098 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Sat, 8 Oct 2022 03:50:57 +0300 Subject: [PATCH 095/153] Update tests --- tests/Commands/FreshTest.php | 4 +- tests/Commands/InstallTest.php | 18 ++++--- tests/Commands/MakeTest.php | 4 +- tests/Commands/MigrateTest.php | 54 ++++++++++++------- tests/Commands/StatusTest.php | 11 ++++ ...2_15_124237_test_success_transactions.stub | 7 +-- ...02_15_124852_test_failed_transactions.stub | 7 +-- 7 files changed, 71 insertions(+), 34 deletions(-) diff --git a/tests/Commands/FreshTest.php b/tests/Commands/FreshTest.php index 6a2e5b98..8b33bd64 100644 --- a/tests/Commands/FreshTest.php +++ b/tests/Commands/FreshTest.php @@ -24,7 +24,9 @@ public function testFreshCommand(): void $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 1); - $this->artisan(Names::FRESH)->assertSuccessful(); + $this->artisan(Names::FRESH) + ->expectsOutputToContain('Dropping all actions') + ->assertSuccessful(); $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 1); diff --git a/tests/Commands/InstallTest.php b/tests/Commands/InstallTest.php index 94d75b02..516ae6e5 100644 --- a/tests/Commands/InstallTest.php +++ b/tests/Commands/InstallTest.php @@ -7,22 +7,28 @@ class InstallTest extends TestCase { - public function testNotFound(): void + public function testCreate(): void { $this->assertDatabaseDoesntTable($this->table); - $this->artisan(Names::STATUS) - ->expectsOutputToContain('Actions table not found.') + $this->artisan(Names::INSTALL) + ->expectsOutputToContain('Actions repository successfully created.') ->assertSuccessful(); - $this->assertDatabaseDoesntTable($this->table); + $this->assertDatabaseHasTable($this->table); } - public function testCreate(): void + public function testAlreadyCreated(): void { $this->assertDatabaseDoesntTable($this->table); - $this->artisan(Names::INSTALL)->assertSuccessful(); + $this->artisan(Names::INSTALL) + ->expectsOutputToContain('Actions repository successfully created.') + ->assertSuccessful(); + + $this->artisan(Names::INSTALL) + ->expectsOutputToContain('Actions repository already exists.') + ->assertSuccessful(); $this->assertDatabaseHasTable($this->table); } diff --git a/tests/Commands/MakeTest.php b/tests/Commands/MakeTest.php index fe3fead3..4adc6822 100644 --- a/tests/Commands/MakeTest.php +++ b/tests/Commands/MakeTest.php @@ -19,10 +19,8 @@ public function testMakingFiles() $this->assertFileExists($path); - $expected = __DIR__ . '/../fixtures/app/stubs/make_example.stub'; - $this->assertEquals( - file_get_contents($expected), + file_get_contents(__DIR__ . '/../fixtures/app/stubs/make_example.stub'), file_get_contents($path) ); } diff --git a/tests/Commands/MigrateTest.php b/tests/Commands/MigrateTest.php index 1e320ed9..b6b413a9 100644 --- a/tests/Commands/MigrateTest.php +++ b/tests/Commands/MigrateTest.php @@ -26,6 +26,24 @@ public function testMigrationCommand() $this->assertDatabaseMigrationHas($this->table, 'test_migration'); } + public function testSameName() + { + $this->assertDatabaseDoesntTable($this->table); + + $this->artisan(Names::INSTALL)->assertSuccessful(); + + $this->assertDatabaseHasTable($this->table); + $this->assertDatabaseCount($this->table, 0); + + $this->artisan(Names::MAKE, ['name' => 'TestMigration'])->assertSuccessful(); + sleep(2); + $this->artisan(Names::MAKE, ['name' => 'TestMigration'])->assertSuccessful(); + $this->artisan(Names::MIGRATE)->assertSuccessful(); + + $this->assertDatabaseCount($this->table, 2); + $this->assertDatabaseMigrationHas($this->table, 'test_migration'); + } + public function testOnce() { $this->copyFiles(); @@ -40,22 +58,22 @@ public function testOnce() $this->artisan(Names::MIGRATE)->assertSuccessful(); $this->assertDatabaseCount($table, 1); - $this->assertDatabaseCount($this->table, 10); + $this->assertDatabaseCount($this->table, 11); $this->assertDatabaseMigrationDoesntLike($this->table, $table); $this->artisan(Names::MIGRATE)->assertSuccessful(); $this->assertDatabaseCount($table, 2); - $this->assertDatabaseCount($this->table, 10); + $this->assertDatabaseCount($this->table, 11); $this->assertDatabaseMigrationDoesntLike($this->table, $table); $this->artisan(Names::MIGRATE)->assertSuccessful(); $this->assertDatabaseCount($table, 3); - $this->assertDatabaseCount($this->table, 10); + $this->assertDatabaseCount($this->table, 11); $this->assertDatabaseMigrationDoesntLike($this->table, $table); $this->artisan(Names::MIGRATE)->assertSuccessful(); $this->assertDatabaseCount($table, 4); - $this->assertDatabaseCount($this->table, 10); + $this->assertDatabaseCount($this->table, 11); $this->assertDatabaseMigrationDoesntLike($this->table, $table); } @@ -120,7 +138,7 @@ public function testSingleEnvironment() $this->artisan(Names::MIGRATE)->assertSuccessful(); $this->assertDatabaseCount($table, 5); - $this->assertDatabaseCount($this->table, 10); + $this->assertDatabaseCount($this->table, 11); $this->assertDatabaseMigrationHas($this->table, 'run_on_all'); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_on_production'); $this->assertDatabaseMigrationHas($this->table, 'run_on_testing'); @@ -129,7 +147,7 @@ public function testSingleEnvironment() $this->artisan(Names::MIGRATE)->assertSuccessful(); $this->assertDatabaseCount($table, 5); - $this->assertDatabaseCount($this->table, 10); + $this->assertDatabaseCount($this->table, 11); $this->assertDatabaseMigrationHas($this->table, 'run_on_all'); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_on_production'); $this->assertDatabaseMigrationHas($this->table, 'run_on_testing'); @@ -157,7 +175,7 @@ public function testManyEnvironments() $this->artisan(Names::MIGRATE)->assertSuccessful(); $this->assertDatabaseCount($table, 5); - $this->assertDatabaseCount($this->table, 10); + $this->assertDatabaseCount($this->table, 11); $this->assertDatabaseMigrationHas($this->table, 'run_on_all'); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_on_production'); $this->assertDatabaseMigrationHas($this->table, 'run_on_testing'); @@ -168,7 +186,7 @@ public function testManyEnvironments() $this->artisan(Names::MIGRATE)->assertSuccessful(); $this->assertDatabaseCount($table, 5); - $this->assertDatabaseCount($this->table, 10); + $this->assertDatabaseCount($this->table, 11); $this->assertDatabaseMigrationHas($this->table, 'run_on_all'); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_on_production'); $this->assertDatabaseMigrationHas($this->table, 'run_on_testing'); @@ -193,13 +211,13 @@ public function testAllow() $this->artisan(Names::MIGRATE)->assertSuccessful(); $this->assertDatabaseCount($table, 5); - $this->assertDatabaseCount($this->table, 10); + $this->assertDatabaseCount($this->table, 11); $this->assertDatabaseMigrationHas($this->table, 'run_allow'); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_disallow'); $this->artisan(Names::MIGRATE)->assertSuccessful(); $this->assertDatabaseCount($table, 5); - $this->assertDatabaseCount($this->table, 10); + $this->assertDatabaseCount($this->table, 11); $this->assertDatabaseMigrationHas($this->table, 'run_allow'); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_disallow'); } @@ -218,7 +236,7 @@ public function testUpSuccess() $this->artisan(Names::MIGRATE)->assertSuccessful(); $this->assertDatabaseCount($table, 2); - $this->assertDatabaseCount($this->table, 10); + $this->assertDatabaseCount($this->table, 11); $this->assertDatabaseMigrationHas($this->table, 'run_success'); } @@ -236,7 +254,7 @@ public function testUpSuccessOnFailed() $this->artisan(Names::MIGRATE)->assertSuccessful(); $this->assertDatabaseCount($table, 2); - $this->assertDatabaseCount($this->table, 10); + $this->assertDatabaseCount($this->table, 11); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_success_on_failed'); try { @@ -253,7 +271,7 @@ public function testUpSuccessOnFailed() } $this->assertDatabaseCount($table, 2); - $this->assertDatabaseCount($this->table, 10); + $this->assertDatabaseCount($this->table, 11); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_success_on_failed'); } @@ -271,7 +289,7 @@ public function testUpFailed() $this->artisan(Names::MIGRATE)->assertSuccessful(); $this->assertDatabaseCount($table, 0); - $this->assertDatabaseCount($this->table, 10); + $this->assertDatabaseCount($this->table, 11); $this->assertDatabaseMigrationHas($this->table, 'run_failed'); } @@ -289,7 +307,7 @@ public function testUpFailedOnException() $this->artisan(Names::MIGRATE)->assertSuccessful(); $this->assertDatabaseCount($table, 0); - $this->assertDatabaseCount($this->table, 10); + $this->assertDatabaseCount($this->table, 11); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_failed_failure'); try { @@ -306,7 +324,7 @@ public function testUpFailedOnException() } $this->assertDatabaseCount($table, 1); - $this->assertDatabaseCount($this->table, 10); + $this->assertDatabaseCount($this->table, 11); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_failed_failure'); } @@ -396,13 +414,13 @@ public function testDisabledBefore() $this->artisan(Names::MIGRATE)->assertSuccessful(); $this->assertDatabaseCount($table, 2); - $this->assertDatabaseCount($this->table, 10); + $this->assertDatabaseCount($this->table, 11); $this->assertDatabaseMigrationHas($this->table, 'test_before_enabled'); $this->assertDatabaseMigrationHas($this->table, 'test_before_disabled'); $this->artisan(Names::MIGRATE)->assertSuccessful(); $this->assertDatabaseCount($table, 2); - $this->assertDatabaseCount($this->table, 10); + $this->assertDatabaseCount($this->table, 11); $this->assertDatabaseMigrationHas($this->table, 'test_before_enabled'); $this->assertDatabaseMigrationHas($this->table, 'test_before_disabled'); } diff --git a/tests/Commands/StatusTest.php b/tests/Commands/StatusTest.php index b8633576..532ed457 100644 --- a/tests/Commands/StatusTest.php +++ b/tests/Commands/StatusTest.php @@ -7,6 +7,17 @@ class StatusTest extends TestCase { + public function testNotFound(): void + { + $this->assertDatabaseDoesntTable($this->table); + + $this->artisan(Names::STATUS) + ->expectsOutputToContain('Actions table not found.') + ->assertSuccessful(); + + $this->assertDatabaseDoesntTable($this->table); + } + public function testStatusCommand() { $this->assertDatabaseDoesntTable($this->table); diff --git a/tests/fixtures/app/stubs/2021_02_15_124237_test_success_transactions.stub b/tests/fixtures/app/stubs/2021_02_15_124237_test_success_transactions.stub index 4349707d..38577654 100644 --- a/tests/fixtures/app/stubs/2021_02_15_124237_test_success_transactions.stub +++ b/tests/fixtures/app/stubs/2021_02_15_124237_test_success_transactions.stub @@ -1,11 +1,12 @@ Date: Sat, 8 Oct 2022 03:51:24 +0300 Subject: [PATCH 096/153] Fixed saving the path to the database --- src/Services/Migrator.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Services/Migrator.php b/src/Services/Migrator.php index 8ab3dcc1..cc8f7445 100644 --- a/src/Services/Migrator.php +++ b/src/Services/Migrator.php @@ -170,6 +170,7 @@ protected function resolveActionName(string $path): string return Str::of(realpath($path)) ->after(realpath($this->config->path())) ->ltrim('\\/') + ->replace('\\', '/') ->toString(); } } From e6db259b7f60785b634be7023b32210a925f7fe9 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Sat, 8 Oct 2022 03:52:30 +0300 Subject: [PATCH 097/153] Fixed getting a list of new files --- src/Processors/Migrate.php | 5 +++-- src/Processors/Reset.php | 2 +- src/Processors/Status.php | 2 +- src/Repositories/ActionRepository.php | 7 +++---- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Processors/Migrate.php b/src/Processors/Migrate.php index f94521f7..44cd5e69 100644 --- a/src/Processors/Migrate.php +++ b/src/Processors/Migrate.php @@ -7,6 +7,7 @@ use DragonCode\LaravelActions\Events\ActionsEnded; use DragonCode\LaravelActions\Events\ActionsStarted; use DragonCode\LaravelActions\Events\NoPendingActions; +use DragonCode\Support\Facades\Helpers\Str; class Migrate extends Processor { @@ -39,9 +40,9 @@ protected function run(string $file, int $batch): void protected function getNewFiles(): array { - $completed = $this->repository->getCompleted(); + $completed = $this->repository->getCompleted()->pluck('action')->toArray(); - return $this->getFiles(fn (string $file) => ! in_array($file, $completed)); + return $this->getFiles(fn (string $file) => ! Str::of($file)->replace('\\', '/')->endsWith($completed)); } protected function getBatch(): int diff --git a/src/Processors/Reset.php b/src/Processors/Reset.php index 5965e9ab..f116e593 100644 --- a/src/Processors/Reset.php +++ b/src/Processors/Reset.php @@ -32,6 +32,6 @@ protected function reset(?string $connection, ?string $path, ?bool $realPath, ?i protected function count(): int { - return count($this->repository->getCompleted()); + return $this->repository->getCompleted()->count(); } } diff --git a/src/Processors/Status.php b/src/Processors/Status.php index 80291877..0b257aaa 100644 --- a/src/Processors/Status.php +++ b/src/Processors/Status.php @@ -53,7 +53,7 @@ protected function getStatusFor(array $completed, string $action): string protected function getCompleted(): array { - return collect($this->repository->getCompleted()) + return $this->repository->getCompleted() ->pluck('batch', 'action') ->toArray(); } diff --git a/src/Repositories/ActionRepository.php b/src/Repositories/ActionRepository.php index f73bc3fc..971288d8 100644 --- a/src/Repositories/ActionRepository.php +++ b/src/Repositories/ActionRepository.php @@ -10,6 +10,7 @@ use Illuminate\Database\Query\Builder as Query; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Builder; +use Illuminate\Support\Collection; class ActionRepository { @@ -28,11 +29,9 @@ public function setConnection(?string $connection): self return $this; } - public function getCompleted(): array + public function getCompleted(): Collection { - return $this->getOrderTable() - ->get() - ->all(); + return $this->getOrderTable()->get(); } public function getByStep(int $steps): array From 6ae2fc5a8984f790ed143ca93f90905d1eb93ea6 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Sat, 8 Oct 2022 03:52:49 +0300 Subject: [PATCH 098/153] Fixed options declaration --- src/Console/Fresh.php | 8 ++++++++ src/Console/Install.php | 1 - src/Console/Make.php | 2 ++ src/Console/Migrate.php | 1 - src/Console/Refresh.php | 1 - src/Console/Reset.php | 5 ++--- src/Console/Rollback.php | 4 +++- src/Console/Status.php | 2 ++ src/Processors/Fresh.php | 10 +++++++++- 9 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/Console/Fresh.php b/src/Console/Fresh.php index 4ee66fd0..cc31fa4e 100644 --- a/src/Console/Fresh.php +++ b/src/Console/Fresh.php @@ -5,6 +5,7 @@ namespace DragonCode\LaravelActions\Console; use DragonCode\LaravelActions\Constants\Names; +use DragonCode\LaravelActions\Constants\Options; use DragonCode\LaravelActions\Processors\Fresh as FreshProcessor; use DragonCode\LaravelActions\Processors\Processor; @@ -15,4 +16,11 @@ class Fresh extends Command protected $description = 'Drop and re-run all actions'; protected Processor|string $processor = FreshProcessor::class; + + protected array $options = [ + Options::CONNECTION, + Options::FORCE, + Options::PATH, + Options::REALPATH, + ]; } diff --git a/src/Console/Install.php b/src/Console/Install.php index 629a2934..09ac1d81 100644 --- a/src/Console/Install.php +++ b/src/Console/Install.php @@ -20,6 +20,5 @@ class Install extends Command Options::FORCE, Options::PATH, Options::REALPATH, - Options::NAME, ]; } diff --git a/src/Console/Make.php b/src/Console/Make.php index a01e1d70..52020688 100644 --- a/src/Console/Make.php +++ b/src/Console/Make.php @@ -22,5 +22,7 @@ class Make extends Command protected array $options = [ Options::CONNECTION, Options::FORCE, + Options::PATH, + Options::REALPATH, ]; } diff --git a/src/Console/Migrate.php b/src/Console/Migrate.php index 860bb5d9..6aab749c 100644 --- a/src/Console/Migrate.php +++ b/src/Console/Migrate.php @@ -22,6 +22,5 @@ class Migrate extends Command Options::CONNECTION, Options::PATH, Options::REALPATH, - Options::STEP, ]; } diff --git a/src/Console/Refresh.php b/src/Console/Refresh.php index fd9db84a..2d665a62 100644 --- a/src/Console/Refresh.php +++ b/src/Console/Refresh.php @@ -20,6 +20,5 @@ class Refresh extends Command Options::FORCE, Options::PATH, Options::REALPATH, - Options::STEP, ]; } diff --git a/src/Console/Reset.php b/src/Console/Reset.php index 28583b79..b96d764b 100644 --- a/src/Console/Reset.php +++ b/src/Console/Reset.php @@ -11,15 +11,14 @@ class Reset extends Command { protected $name = Names::RESET; - protected $description = 'Rollback all database actions'; + protected $description = 'Rollback all actions'; protected Processor|string $processor = ResetProcessor::class; protected array $options = [ Options::CONNECTION, + Options::FORCE, Options::PATH, Options::REALPATH, - Options::STEP, - Options::FORCE, ]; } diff --git a/src/Console/Rollback.php b/src/Console/Rollback.php index 8ff2c8e7..d4c23fda 100644 --- a/src/Console/Rollback.php +++ b/src/Console/Rollback.php @@ -11,13 +11,15 @@ class Rollback extends Command { protected $name = Names::ROLLBACK; - protected $description = 'Rollback the last database action'; + protected $description = 'Rollback the last action'; protected Processor|string $processor = RollbackProcessor::class; protected array $options = [ Options::CONNECTION, Options::FORCE, + Options::PATH, + Options::REALPATH, Options::STEP, ]; } diff --git a/src/Console/Status.php b/src/Console/Status.php index 94fc0675..072b55d8 100644 --- a/src/Console/Status.php +++ b/src/Console/Status.php @@ -19,5 +19,7 @@ class Status extends Command protected array $options = [ Options::CONNECTION, + Options::PATH, + Options::REALPATH, ]; } diff --git a/src/Processors/Fresh.php b/src/Processors/Fresh.php index 0b488432..40e989de 100644 --- a/src/Processors/Fresh.php +++ b/src/Processors/Fresh.php @@ -19,7 +19,10 @@ public function handle(): void protected function drop(): void { if ($this->repository->repositoryExists()) { - $this->notification->task('Dropping all actions', fn () => $this->repository->deleteRepository()); + $this->notification->task( + 'Dropping all actions', + fn () => $this->repository->deleteRepository() + ); } } @@ -28,13 +31,18 @@ protected function create(): void $this->runCommand(Names::INSTALL, [ '--' . Options::CONNECTION => $this->options->connection, '--' . Options::FORCE => $this->options->force, + '--' . Options::PATH => $this->options->path, + '--' . Options::REALPATH => $this->options->realpath, ]); } protected function migrate(): void { $this->runCommand(Names::MIGRATE, [ + '--' . Options::BEFORE => $this->options->before, '--' . Options::CONNECTION => $this->options->connection, + '--' . Options::PATH => $this->options->path, + '--' . Options::REALPATH => $this->options->realpath, ]); } } From 7f5ee8261e26083d400b6d8f3fe9b527a8d3dd64 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Sat, 8 Oct 2022 19:07:33 +0300 Subject: [PATCH 099/153] =?UTF-8?q?=F0=9F=A7=91=E2=80=8D=F0=9F=8F=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Console/Install.php | 2 - src/Console/Reset.php | 2 +- src/Constants/Order.php | 12 ++++++ .../{ActionsEnded.php => ActionEnded.php} | 2 +- .../{ActionsStarted.php => ActionStarted.php} | 2 +- src/Processors/Fresh.php | 8 +--- src/Processors/Install.php | 10 ++--- src/Processors/Make.php | 11 +++--- src/Processors/Migrate.php | 8 ++-- src/Processors/Processor.php | 7 +--- src/Processors/Refresh.php | 26 ++----------- src/Processors/Reset.php | 6 +-- src/Processors/Rollback.php | 10 ++--- src/Processors/Status.php | 37 ++++++++++--------- src/Processors/Upgrade.php | 12 +++++- src/Repositories/ActionRepository.php | 28 ++++++++------ src/Services/Migrator.php | 24 ++++++------ src/Values/Options.php | 8 +--- 18 files changed, 104 insertions(+), 111 deletions(-) create mode 100644 src/Constants/Order.php rename src/Events/{ActionsEnded.php => ActionEnded.php} (83%) rename src/Events/{ActionsStarted.php => ActionStarted.php} (82%) diff --git a/src/Console/Install.php b/src/Console/Install.php index 09ac1d81..c2d4ab7d 100644 --- a/src/Console/Install.php +++ b/src/Console/Install.php @@ -18,7 +18,5 @@ class Install extends Command protected array $options = [ Options::CONNECTION, Options::FORCE, - Options::PATH, - Options::REALPATH, ]; } diff --git a/src/Console/Reset.php b/src/Console/Reset.php index b96d764b..dfcb0906 100644 --- a/src/Console/Reset.php +++ b/src/Console/Reset.php @@ -13,7 +13,7 @@ class Reset extends Command protected $description = 'Rollback all actions'; - protected Processor|string $processor = ResetProcessor::class; + protected Processor|string $processor = rollback::class; protected array $options = [ Options::CONNECTION, diff --git a/src/Constants/Order.php b/src/Constants/Order.php new file mode 100644 index 00000000..d7624f86 --- /dev/null +++ b/src/Constants/Order.php @@ -0,0 +1,12 @@ +repository->repositoryExists()) { - $this->notification->task( - 'Dropping all actions', - fn () => $this->repository->deleteRepository() - ); + $this->notification->task('Dropping all actions', fn () => $this->repository->deleteRepository()); } } @@ -31,15 +28,12 @@ protected function create(): void $this->runCommand(Names::INSTALL, [ '--' . Options::CONNECTION => $this->options->connection, '--' . Options::FORCE => $this->options->force, - '--' . Options::PATH => $this->options->path, - '--' . Options::REALPATH => $this->options->realpath, ]); } protected function migrate(): void { $this->runCommand(Names::MIGRATE, [ - '--' . Options::BEFORE => $this->options->before, '--' . Options::CONNECTION => $this->options->connection, '--' . Options::PATH => $this->options->path, '--' . Options::REALPATH => $this->options->realpath, diff --git a/src/Processors/Install.php b/src/Processors/Install.php index dc099ba2..d92000a1 100644 --- a/src/Processors/Install.php +++ b/src/Processors/Install.php @@ -11,13 +11,15 @@ class Install extends Processor public function handle(): void { if ($this->exists()) { - $this->notification->warning('Actions repository already exists.'); + $this->notification->warning('Actions repository already exists'); return; } - $this->create(); - $this->ensureDirectory(); + $this->notification->task('Installing the action repository', function () { + $this->create(); + $this->ensureDirectory(); + }); } protected function exists(): bool @@ -28,8 +30,6 @@ protected function exists(): bool protected function create(): void { $this->repository->createRepository(); - - $this->notification->info('Actions repository successfully created.'); } protected function ensureDirectory(): void diff --git a/src/Processors/Make.php b/src/Processors/Make.php index 5e113ada..d167487f 100644 --- a/src/Processors/Make.php +++ b/src/Processors/Make.php @@ -10,13 +10,14 @@ class Make extends Processor { - protected string $defaultName = 'auto'; + protected string $fallbackName = 'auto'; protected string $stub = __DIR__ . '/../../resources/stubs/action.stub'; public function handle(): void { - $path = $this->getPath(); + $name = $this->getName(); + $path = $this->getPath($name); $this->create($path); } @@ -26,10 +27,8 @@ protected function create(string $path): void File::copy($this->stub, $path); } - protected function getPath(): string + protected function getPath(string $name): string { - $name = $this->getName(); - return $this->options->realpath ? $name : $this->config->path($name); } @@ -48,7 +47,7 @@ protected function getFilename(string $branch): string protected function getBranchName(): string { - return $this->options->name ?? $this->git->currentBranch() ?? $this->defaultName; + return $this->options->name ?? $this->git->currentBranch() ?? $this->fallbackName; } protected function getTime(): string diff --git a/src/Processors/Migrate.php b/src/Processors/Migrate.php index 44cd5e69..07d3c784 100644 --- a/src/Processors/Migrate.php +++ b/src/Processors/Migrate.php @@ -4,8 +4,8 @@ namespace DragonCode\LaravelActions\Processors; -use DragonCode\LaravelActions\Events\ActionsEnded; -use DragonCode\LaravelActions\Events\ActionsStarted; +use DragonCode\LaravelActions\Events\ActionEnded; +use DragonCode\LaravelActions\Events\ActionStarted; use DragonCode\LaravelActions\Events\NoPendingActions; use DragonCode\Support\Facades\Helpers\Str; @@ -14,11 +14,11 @@ class Migrate extends Processor public function handle(): void { if ($files = $this->getNewFiles()) { - $this->fireEvent(new ActionsStarted('up', $this->options->before)); + $this->fireEvent(new ActionStarted('up', $this->options->before)); $this->runEach($files, $this->getBatch()); - $this->fireEvent(new ActionsEnded('up', $this->options->before)); + $this->fireEvent(new ActionEnded('up', $this->options->before)); return; } diff --git a/src/Processors/Processor.php b/src/Processors/Processor.php index dd3d0bf5..d252ef57 100644 --- a/src/Processors/Processor.php +++ b/src/Processors/Processor.php @@ -13,7 +13,6 @@ use DragonCode\LaravelActions\Repositories\ActionRepository; use DragonCode\LaravelActions\Services\Migrator; use DragonCode\LaravelActions\Values\Options; -use DragonCode\Support\Facades\Helpers\Arr; use DragonCode\Support\Filesystem\File; use Illuminate\Console\OutputStyle; use Illuminate\Contracts\Events\Dispatcher; @@ -44,9 +43,7 @@ public function __construct( protected function getFiles(?Closure $filter = null, ?string $path = null): array { - $files = $this->file->allPaths($path ?: $this->config->path(), $filter, true); - - return Arr::sort($files); + return $this->file->allPaths($path ?: $this->config->path(), $filter, true); } protected function runCommand(string $command, array $options = []): void @@ -57,7 +54,7 @@ protected function runCommand(string $command, array $options = []): void protected function tableNotFound(): bool { if (! $this->repository->repositoryExists()) { - $this->notification->warning('Actions table not found.'); + $this->notification->warning('Actions table not found'); return true; } diff --git a/src/Processors/Refresh.php b/src/Processors/Refresh.php index 62168e2c..ae7192c8 100644 --- a/src/Processors/Refresh.php +++ b/src/Processors/Refresh.php @@ -14,31 +14,12 @@ public function handle(): void $connection = $this->options->connection; $path = $this->options->path; $realPath = $this->options->realpath; - $step = $this->options->step; - $this->rollback($connection, $path, $realPath, $step); + $this->runReset($connection, $path, $realPath); $this->runMigrate($connection, $path, $realPath); } - protected function rollback(?string $connection, array $path, bool $realPath, ?int $step): void - { - (int) $step > 0 - ? $this->runRollback($connection, $path, $realPath, $step) - : $this->runReset($connection, $path, $realPath); - } - - protected function runRollback(?string $connection, array $path, bool $realPath, ?int $step): void - { - $this->runCommand(Names::ROLLBACK, [ - '--' . Options::CONNECTION => $connection, - '--' . Options::PATH => $path, - '--' . Options::REALPATH => $realPath, - '--' . Options::STEP => $step, - '--' . Options::FORCE => true, - ]); - } - - protected function runReset(?string $connection, array $path, bool $realPath): void + protected function runReset(?string $connection, ?string $path, bool $realPath): void { $this->runCommand(Names::RESET, [ '--' . Options::CONNECTION => $connection, @@ -48,13 +29,12 @@ protected function runReset(?string $connection, array $path, bool $realPath): v ]); } - protected function runMigrate(?string $connection, array $path, bool $realPath): void + protected function runMigrate(?string $connection, ?string $path, bool $realPath): void { $this->runCommand(Names::MIGRATE, [ '--' . Options::CONNECTION => $connection, '--' . Options::PATH => $path, '--' . Options::REALPATH => $realPath, - '--' . Options::FORCE => true, ]); } } diff --git a/src/Processors/Reset.php b/src/Processors/Reset.php index f116e593..c85b84de 100644 --- a/src/Processors/Reset.php +++ b/src/Processors/Reset.php @@ -11,7 +11,7 @@ class Reset extends Processor { public function handle(): void { - $this->reset( + $this->rollback( $this->options->connection, $this->options->path, $this->options->realpath, @@ -19,7 +19,7 @@ public function handle(): void ); } - protected function reset(?string $connection, ?string $path, ?bool $realPath, ?int $step): void + protected function rollback(?string $connection, ?string $path, ?bool $realPath, int $step): void { $this->runCommand(Names::ROLLBACK, [ '--' . Options::CONNECTION => $connection, @@ -32,6 +32,6 @@ protected function reset(?string $connection, ?string $path, ?bool $realPath, ?i protected function count(): int { - return $this->repository->getCompleted()->count(); + return $this->repository->getCompleted()->max('batch'); } } diff --git a/src/Processors/Rollback.php b/src/Processors/Rollback.php index b0758f79..4b27e360 100644 --- a/src/Processors/Rollback.php +++ b/src/Processors/Rollback.php @@ -4,8 +4,8 @@ namespace DragonCode\LaravelActions\Processors; -use DragonCode\LaravelActions\Events\ActionsEnded; -use DragonCode\LaravelActions\Events\ActionsStarted; +use DragonCode\LaravelActions\Events\ActionEnded; +use DragonCode\LaravelActions\Events\ActionStarted; use DragonCode\LaravelActions\Events\NoPendingActions; class Rollback extends Processor @@ -19,11 +19,11 @@ public function handle(): void } if ($actions = $this->getActions($this->options->step)) { - $this->fireEvent(new ActionsStarted('down', $this->options->before)); + $this->fireEvent(new ActionStarted('down', $this->options->before)); $this->run($actions); - $this->fireEvent(new ActionsEnded('down', $this->options->before)); + $this->fireEvent(new ActionEnded('down', $this->options->before)); return; } @@ -55,7 +55,7 @@ protected function rollbackAction(string $action): void protected function nothingToRollback(): bool { if ($this->count() <= 0) { - $this->notification->warning('Nothing to rollback'); + $this->notification->warning('Nothing To Rollback'); return true; } diff --git a/src/Processors/Status.php b/src/Processors/Status.php index 0b257aaa..f40cda32 100644 --- a/src/Processors/Status.php +++ b/src/Processors/Status.php @@ -8,27 +8,35 @@ class Status extends Processor { + protected string $columnName = 'Action name'; + + protected string $columnStatus = 'Batch / Status'; + + protected string $statusRan = 'Ran'; + + protected string $statusPending = 'Pending'; + public function handle(): void { if ($this->tableNotFound()) { return; } - $this->run(); + $this->showCaption(); + $this->showStatus(); } - protected function run(): void + protected function showCaption(): void { - $completed = $this->getCompleted(); - $actions = $this->getActionFiles(); - - $this->showCaption(); - $this->showData($actions, $completed); + $this->notification->twoColumn($this->columnName, $this->columnStatus); } - protected function showCaption(): void + protected function showStatus(): void { - $this->notification->twoColumn('Action name', 'Batch / Status'); + $this->showData( + $this->getFiles(), + $this->getCompleted() + ); } protected function showData(array $actions, array $completed): void @@ -43,12 +51,10 @@ protected function showData(array $actions, array $completed): void protected function getStatusFor(array $completed, string $action): string { if ($batch = Arr::get($completed, $action)) { - $status = 'Ran'; - - return "[$batch] $status"; + return "[$batch] $this->statusRan"; } - return 'Pending'; + return $this->statusPending; } protected function getCompleted(): array @@ -57,9 +63,4 @@ protected function getCompleted(): array ->pluck('batch', 'action') ->toArray(); } - - protected function getActionFiles(): array - { - return $this->getFiles(); - } } diff --git a/src/Processors/Upgrade.php b/src/Processors/Upgrade.php index 9836276f..c867f28f 100644 --- a/src/Processors/Upgrade.php +++ b/src/Processors/Upgrade.php @@ -8,6 +8,7 @@ use DragonCode\Support\Facades\Filesystem\Directory; use DragonCode\Support\Facades\Filesystem\File; use DragonCode\Support\Facades\Helpers\Str; +use DragonCode\Support\Helpers\Ables\Stringable; class Upgrade extends Processor { @@ -42,6 +43,7 @@ protected function move(string $filename): void $content = $this->replaceNamespace($content); $content = $this->replaceClassName($content); $content = $this->replaceDeclareStrictType($content); + $content = $this->replaceWithInvoke($content); $this->store($filename, $content); $this->delete($filename); @@ -88,11 +90,19 @@ protected function replaceDeclareStrictType(string $content): string ->toString(); } + protected function replaceWithInvoke(string $content): string + { + return Str::of($content) + ->when(! Str::matchContains($content, '/public\s+function\s+down/'), function (Stringable $string) { + return $string->pregReplace('/(public\s+function\s+up)/', 'public function __invoke'); + })->toString(); + } + protected function moveConfig(): void { $this->artisan('vendor:publish', [ - '--force' => true, '--provider' => ServiceProvider::class, + '--force' => true, ]); $path = config_path('actions.php'); diff --git a/src/Repositories/ActionRepository.php b/src/Repositories/ActionRepository.php index 971288d8..3c028c79 100644 --- a/src/Repositories/ActionRepository.php +++ b/src/Repositories/ActionRepository.php @@ -4,6 +4,7 @@ namespace DragonCode\LaravelActions\Repositories; +use DragonCode\LaravelActions\Constants\Order; use DragonCode\LaravelActions\Helpers\Config; use Illuminate\Database\ConnectionInterface; use Illuminate\Database\ConnectionResolverInterface as Resolver; @@ -31,12 +32,12 @@ public function setConnection(?string $connection): self public function getCompleted(): Collection { - return $this->getOrderTable()->get(); + return $this->sortedTable()->get(); } public function getByStep(int $steps): array { - return $this->getOrderTable('desc') + return $this->sortedTable(Order::DESC) ->whereIn('batch', $this->getBatchNumbers($steps)) ->get() ->all(); @@ -44,7 +45,7 @@ public function getByStep(int $steps): array public function getLast(): array { - return $this->getOrderTable('desc') + return $this->sortedTable(Order::DESC) ->where('batch', $this->getLastBatchNumber()) ->get() ->all(); @@ -91,20 +92,25 @@ public function deleteRepository(): void $this->schema()->dropIfExists($this->config->table()); } + /** + * @param int $steps + * + * @return array + */ protected function getBatchNumbers(int $steps): array { - return $this->getOrderTable('desc') + return $this->sortedTable(Order::DESC) ->pluck('batch') ->unique() ->take($steps) ->all(); } - protected function getOrderTable(string $order = 'asc'): Query + protected function sortedTable(string $order = Order::ASC): Query { return $this->table() ->orderBy('batch', $order) - ->orderBy('action', $order); + ->orderBy('id', $order); } protected function schema(): Builder @@ -112,15 +118,15 @@ protected function schema(): Builder return $this->getConnection()->getSchemaBuilder(); } + protected function table(): Query + { + return $this->getConnection()->table($this->config->table())->useWritePdo(); + } + protected function getConnection(): ConnectionInterface { return $this->resolver->connection( $this->connection ?: $this->config->connection() ); } - - protected function table(): Query - { - return $this->getConnection()->table($this->config->table())->useWritePdo(); - } } diff --git a/src/Services/Migrator.php b/src/Services/Migrator.php index cc8f7445..cb839042 100644 --- a/src/Services/Migrator.php +++ b/src/Services/Migrator.php @@ -110,7 +110,7 @@ protected function deleteLog(string $name): void $this->repository->delete($name); } - protected function allowAction(Action $action, string $name, Options $options, bool $log = false): bool + protected function allowAction(Action $action, string $name, Options $options): bool { if (! $this->allowEnvironment($action)) { $this->notification->info("Action: $name was skipped on this environment"); @@ -131,19 +131,19 @@ protected function allowEnvironment(Action $action): bool { $env = $this->config->environment(); - $on = $action->onEnvironment(); - $except = $action->exceptEnvironment(); - $allow = $action->allow(); - - if (! $allow) { - return false; - } + return $action->allow() + || $this->onEnvironment($env, $action->onEnvironment()) + || $this->exceptEnvironment($env, $action->exceptEnvironment()); + } - if (! empty($on) && ! in_array($env, $on)) { - return false; - } + protected function onEnvironment(?string $env, array $on): bool + { + return empty($on) || ! in_array($env, $on); + } - return ! (! empty($except) && in_array($env, $except)); + protected function exceptEnvironment(?string $env, array $except): bool + { + return empty($except) || ! in_array($env, $except); } protected function disallowBefore(Action $action, Options $options): bool diff --git a/src/Values/Options.php b/src/Values/Options.php index 7acba7ce..a8bb4480 100644 --- a/src/Values/Options.php +++ b/src/Values/Options.php @@ -17,7 +17,7 @@ class Options extends DataTransferObject public ?string $name = null; - public array $path = []; + public ?string $path = null; public bool $realpath = false; @@ -25,10 +25,6 @@ class Options extends DataTransferObject protected function castName(?string $value): ?string { - if (! empty($value)) { - return Str::snake($value); - } - - return null; + return empty($value) ? null : Str::snake($value); } } From 8b3c0ad6ba43f9f5d7ab89c6412e4f2fcab425fc Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Sat, 8 Oct 2022 19:57:46 +0300 Subject: [PATCH 100/153] Added forgetting processors --- src/Console/Command.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Console/Command.php b/src/Console/Command.php index 59dd4175..12563f98 100644 --- a/src/Console/Command.php +++ b/src/Console/Command.php @@ -31,6 +31,7 @@ public function handle(): int { if ($this->allowToProceed()) { $this->resolveProcessor()->handle(); + $this->forgetProcessor(); return self::SUCCESS; } @@ -40,13 +41,23 @@ public function handle(): int protected function resolveProcessor(): Processor { - return Container::getInstance()->make($this->processor, [ + return $this->container()->make($this->processor, [ 'options' => $this->getOptionsDto(), 'input' => $this->input, 'output' => $this->output, ]); } + protected function forgetProcessor(): void + { + $this->container()->forgetInstance($this->processor); + } + + protected function container(): Container + { + return Container::getInstance(); + } + protected function configure(): void { foreach ($this->getFilteredArguments() as $argument) { From 7984027540780045f877ac5a626ca324af91c642 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Sat, 8 Oct 2022 20:02:01 +0300 Subject: [PATCH 101/153] Fixed options --- src/Console/Command.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Console/Command.php b/src/Console/Command.php index 12563f98..66199935 100644 --- a/src/Console/Command.php +++ b/src/Console/Command.php @@ -83,8 +83,8 @@ protected function availableOptions(): array [Options::BEFORE, null, InputOption::VALUE_NONE, 'Run actions marked as before'], [Options::CONNECTION, null, InputOption::VALUE_OPTIONAL, 'The database connection to use'], [Options::FORCE, null, InputOption::VALUE_NONE, 'Force the operation to run when in production'], - [Options::PATH, null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'The path(s) to the actions files to be executed'], - [Options::REALPATH, null, InputOption::VALUE_NONE, 'Indicate any provided action file paths are pre-resolved absolute paths'], + [Options::PATH, null, InputOption::VALUE_OPTIONAL, 'The path to the actions files to be executed'], + [Options::REALPATH, null, InputOption::VALUE_NONE, 'Indicate any provided action file paths are pre-resolved absolute path'], [Options::STEP, null, InputOption::VALUE_OPTIONAL, 'Force the actions to be run so they can be rolled back individually'], ]; } From 0373cf58979832006629a6ffaa455c30d80739c1 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Sat, 8 Oct 2022 21:30:03 +0300 Subject: [PATCH 102/153] Fixed processor's link --- src/Console/Reset.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Console/Reset.php b/src/Console/Reset.php index dfcb0906..b96d764b 100644 --- a/src/Console/Reset.php +++ b/src/Console/Reset.php @@ -13,7 +13,7 @@ class Reset extends Command protected $description = 'Rollback all actions'; - protected Processor|string $processor = rollback::class; + protected Processor|string $processor = ResetProcessor::class; protected array $options = [ Options::CONNECTION, From 21a63c8d3cd79ee349f14a8b639436b7b8ec7298 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Sat, 8 Oct 2022 21:36:52 +0300 Subject: [PATCH 103/153] Fixed `path` options provide --- src/Processors/Install.php | 4 +++- src/Processors/Make.php | 7 +------ src/Processors/Processor.php | 9 ++++++++- src/Processors/Rollback.php | 2 +- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/Processors/Install.php b/src/Processors/Install.php index d92000a1..e9c76042 100644 --- a/src/Processors/Install.php +++ b/src/Processors/Install.php @@ -34,6 +34,8 @@ protected function create(): void protected function ensureDirectory(): void { - Directory::ensureDirectory($this->config->path()); + Directory::ensureDirectory( + $this->getActionsPath() + ); } } diff --git a/src/Processors/Make.php b/src/Processors/Make.php index d167487f..d9b81d82 100644 --- a/src/Processors/Make.php +++ b/src/Processors/Make.php @@ -17,7 +17,7 @@ class Make extends Processor public function handle(): void { $name = $this->getName(); - $path = $this->getPath($name); + $path = $this->getActionsPath($name); $this->create($path); } @@ -27,11 +27,6 @@ protected function create(string $path): void File::copy($this->stub, $path); } - protected function getPath(string $name): string - { - return $this->options->realpath ? $name : $this->config->path($name); - } - protected function getName(): string { $branch = $this->getBranchName(); diff --git a/src/Processors/Processor.php b/src/Processors/Processor.php index d252ef57..86deb62c 100644 --- a/src/Processors/Processor.php +++ b/src/Processors/Processor.php @@ -43,7 +43,14 @@ public function __construct( protected function getFiles(?Closure $filter = null, ?string $path = null): array { - return $this->file->allPaths($path ?: $this->config->path(), $filter, true); + return $this->file->allPaths($path ?: $this->getActionsPath(), $filter, true); + } + + protected function getActionsPath(?string $name = null): string + { + $path = $this->options->path ?: $this->config->path(); + + return $this->options->realpath ? $name : $path . DIRECTORY_SEPARATOR . $name; } protected function runCommand(string $command, array $options = []): void diff --git a/src/Processors/Rollback.php b/src/Processors/Rollback.php index 4b27e360..dbc8b455 100644 --- a/src/Processors/Rollback.php +++ b/src/Processors/Rollback.php @@ -48,7 +48,7 @@ protected function getActions(?int $step): array protected function rollbackAction(string $action): void { $this->migrator->runDown( - $this->config->path($action) + $this->getActionsPath($action) ); } From e5ffdd60b7a12f3a6dc2afe8a9190436b9329649 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Sat, 8 Oct 2022 21:39:07 +0300 Subject: [PATCH 104/153] Update tests --- tests/Commands/InstallTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Commands/InstallTest.php b/tests/Commands/InstallTest.php index 516ae6e5..02f82d29 100644 --- a/tests/Commands/InstallTest.php +++ b/tests/Commands/InstallTest.php @@ -12,7 +12,7 @@ public function testCreate(): void $this->assertDatabaseDoesntTable($this->table); $this->artisan(Names::INSTALL) - ->expectsOutputToContain('Actions repository successfully created.') + ->expectsOutputToContain('Installing the action repository') ->assertSuccessful(); $this->assertDatabaseHasTable($this->table); @@ -23,11 +23,11 @@ public function testAlreadyCreated(): void $this->assertDatabaseDoesntTable($this->table); $this->artisan(Names::INSTALL) - ->expectsOutputToContain('Actions repository successfully created.') + ->expectsOutputToContain('Installing the action repository') ->assertSuccessful(); $this->artisan(Names::INSTALL) - ->expectsOutputToContain('Actions repository already exists.') + ->expectsOutputToContain('Actions repository already exists') ->assertSuccessful(); $this->assertDatabaseHasTable($this->table); From 7ae263a5dca72254a6bf7655a616eedaad61e621 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Mon, 10 Oct 2022 22:20:35 +0300 Subject: [PATCH 105/153] Work, work, work... --- src/Concerns/Optionable.php | 59 +++++++++++++++++++++++++++++++++ src/Console/Command.php | 53 ++--------------------------- src/Helpers/Git.php | 8 ++--- src/Processors/Make.php | 2 +- src/Processors/Migrate.php | 18 +++++++++- src/Processors/Processor.php | 15 ++++++--- src/Processors/Reset.php | 2 +- src/Processors/Rollback.php | 10 +++++- src/Processors/Status.php | 35 +++++++++++++------ src/Services/Migrator.php | 6 ++-- tests/Commands/MigrateTest.php | 12 +++---- tests/Commands/RollbackTest.php | 4 ++- tests/Services/GitTest.php | 2 +- 13 files changed, 141 insertions(+), 85 deletions(-) create mode 100644 src/Concerns/Optionable.php diff --git a/src/Concerns/Optionable.php b/src/Concerns/Optionable.php new file mode 100644 index 00000000..14357b28 --- /dev/null +++ b/src/Concerns/Optionable.php @@ -0,0 +1,59 @@ +specifyParameters(); + } + + protected function getOptions(): array + { + return Arr::of($this->availableOptions()) + ->filter(fn (array $option) => in_array($option[0], $this->options)) + ->toArray(); + } + + protected function getArguments(): array + { + return Arr::of($this->availableArguments()) + ->filter(fn (array $argument) => in_array($argument[0], $this->arguments)) + ->toArray(); + } + + protected function availableOptions(): array + { + return [ + [Options::BEFORE, null, InputOption::VALUE_NONE, 'Run actions marked as before'], + [Options::CONNECTION, null, InputOption::VALUE_OPTIONAL, 'The database connection to use'], + [Options::FORCE, null, InputOption::VALUE_NONE, 'Force the operation to run when in production'], + [Options::PATH, null, InputOption::VALUE_OPTIONAL, 'The path to the actions files to be executed'], + [Options::REALPATH, null, InputOption::VALUE_NONE, 'Indicate any provided action file paths are pre-resolved absolute path'], + [Options::STEP, null, InputOption::VALUE_OPTIONAL, 'Force the actions to be run so they can be rolled back individually'], + ]; + } + + protected function availableArguments(): array + { + return [ + [Options::NAME, InputArgument::OPTIONAL, 'The name of the action'], + ]; + } +} diff --git a/src/Console/Command.php b/src/Console/Command.php index 66199935..22709cb1 100644 --- a/src/Console/Command.php +++ b/src/Console/Command.php @@ -5,28 +5,19 @@ namespace DragonCode\LaravelActions\Console; use DragonCode\LaravelActions\Concerns\ConfirmableTrait; -use DragonCode\LaravelActions\Constants\Options; +use DragonCode\LaravelActions\Concerns\Optionable; use DragonCode\LaravelActions\Processors\Processor; use DragonCode\LaravelActions\Values\Options as OptionsDto; -use DragonCode\Support\Facades\Helpers\Arr; use Illuminate\Console\Command as BaseCommand; use Illuminate\Container\Container; -use Symfony\Component\Console\Input\InputArgument; -use Symfony\Component\Console\Input\InputOption; abstract class Command extends BaseCommand { use ConfirmableTrait; + use Optionable; protected Processor|string $processor; - protected array $arguments = []; - - protected array $options = [ - Options::CONNECTION, - Options::FORCE, - ]; - public function handle(): int { if ($this->allowToProceed()) { @@ -58,48 +49,8 @@ protected function container(): Container return Container::getInstance(); } - protected function configure(): void - { - foreach ($this->getFilteredArguments() as $argument) { - $this->addArgument(...$argument); - } - } - protected function getOptionsDto(): OptionsDto { return OptionsDto::fromArray(array_merge($this->options(), $this->arguments())); } - - protected function getOptions(): array - { - return Arr::of($this->availableOptions()) - ->filter(fn (array $option) => in_array($option[0], $this->options)) - ->toArray(); - } - - protected function availableOptions(): array - { - return [ - [Options::BEFORE, null, InputOption::VALUE_NONE, 'Run actions marked as before'], - [Options::CONNECTION, null, InputOption::VALUE_OPTIONAL, 'The database connection to use'], - [Options::FORCE, null, InputOption::VALUE_NONE, 'Force the operation to run when in production'], - [Options::PATH, null, InputOption::VALUE_OPTIONAL, 'The path to the actions files to be executed'], - [Options::REALPATH, null, InputOption::VALUE_NONE, 'Indicate any provided action file paths are pre-resolved absolute path'], - [Options::STEP, null, InputOption::VALUE_OPTIONAL, 'Force the actions to be run so they can be rolled back individually'], - ]; - } - - protected function getFilteredArguments(): array - { - return Arr::of($this->availableArguments()) - ->filter(fn (array $argument) => in_array($argument[0], $this->arguments)) - ->toArray(); - } - - protected function availableArguments(): array - { - return [ - [Options::NAME, InputArgument::OPTIONAL, 'The name of the action'], - ]; - } } diff --git a/src/Helpers/Git.php b/src/Helpers/Git.php index b2a3de03..353cb9df 100644 --- a/src/Helpers/Git.php +++ b/src/Helpers/Git.php @@ -13,9 +13,9 @@ public function __construct( ) { } - public function currentBranch(): ?string + public function currentBranch(?string $path = null): ?string { - if ($this->hasGitDirectory()) { + if ($this->hasGitDirectory($path)) { return $this->exec('rev-parse --abbrev-ref HEAD'); } @@ -27,9 +27,9 @@ protected function exec(string $command): ?string return exec(sprintf('git --git-dir %s %s', $this->config->gitPath(), $command)); } - protected function hasGitDirectory(): bool + protected function hasGitDirectory(?string $path = null): bool { - if ($path = rtrim($this->config->gitPath(), '/\\')) { + if ($path = rtrim($path ?: $this->config->gitPath(), '/\\')) { return Directory::exists($path . DIRECTORY_SEPARATOR . '.git'); } diff --git a/src/Processors/Make.php b/src/Processors/Make.php index d9b81d82..88591ee2 100644 --- a/src/Processors/Make.php +++ b/src/Processors/Make.php @@ -37,7 +37,7 @@ protected function getName(): string protected function getFilename(string $branch): string { - return Str::of(Path::filename($branch))->prepend($this->getTime())->end('.php')->toString(); + return Str::of(Path::filename($branch))->prepend($this->getTime())->finish('.php')->toString(); } protected function getBranchName(): string diff --git a/src/Processors/Migrate.php b/src/Processors/Migrate.php index 07d3c784..a2ef93cb 100644 --- a/src/Processors/Migrate.php +++ b/src/Processors/Migrate.php @@ -4,6 +4,8 @@ namespace DragonCode\LaravelActions\Processors; +use DragonCode\LaravelActions\Constants\Names; +use DragonCode\LaravelActions\Constants\Options; use DragonCode\LaravelActions\Events\ActionEnded; use DragonCode\LaravelActions\Events\ActionStarted; use DragonCode\LaravelActions\Events\NoPendingActions; @@ -12,6 +14,20 @@ class Migrate extends Processor { public function handle(): void + { + $this->ensureRepository(); + $this->runActions(); + } + + protected function ensureRepository(): void + { + $this->artisan(Names::INSTALL, [ + '--' . Options::CONNECTION => $this->options->connection, + '--' . Options::FORCE => true, + ]); + } + + protected function runActions(): void { if ($files = $this->getNewFiles()) { $this->fireEvent(new ActionStarted('up', $this->options->before)); @@ -42,7 +58,7 @@ protected function getNewFiles(): array { $completed = $this->repository->getCompleted()->pluck('action')->toArray(); - return $this->getFiles(fn (string $file) => ! Str::of($file)->replace('\\', '/')->endsWith($completed)); + return $this->getFiles(fn (string $file) => ! Str::of($file)->replace('\\', '/')->contains($completed), $this->options->path); } protected function getBatch(): int diff --git a/src/Processors/Processor.php b/src/Processors/Processor.php index 86deb62c..2c7ac9fb 100644 --- a/src/Processors/Processor.php +++ b/src/Processors/Processor.php @@ -13,6 +13,7 @@ use DragonCode\LaravelActions\Repositories\ActionRepository; use DragonCode\LaravelActions\Services\Migrator; use DragonCode\LaravelActions\Values\Options; +use DragonCode\Support\Facades\Helpers\Str; use DragonCode\Support\Filesystem\File; use Illuminate\Console\OutputStyle; use Illuminate\Contracts\Events\Dispatcher; @@ -43,14 +44,20 @@ public function __construct( protected function getFiles(?Closure $filter = null, ?string $path = null): array { - return $this->file->allPaths($path ?: $this->getActionsPath(), $filter, true); + $path = $this->getActionsPath($path); + + return $this->file->exists($path) ? [$path] : $this->file->allPaths($path, $filter, true); } - protected function getActionsPath(?string $name = null): string + protected function getActionsPath(?string $path = null): string { - $path = $this->options->path ?: $this->config->path(); + $path = $this->options->realpath ? $path : $this->config->path($path); + + if (! is_dir($path) && ! Str::endsWith($path, '.php')) { + return $this->file->exists($path . '.php') ? $path . '.php' : $path; + } - return $this->options->realpath ? $name : $path . DIRECTORY_SEPARATOR . $name; + return $path; } protected function runCommand(string $command, array $options = []): void diff --git a/src/Processors/Reset.php b/src/Processors/Reset.php index c85b84de..e57ecf0b 100644 --- a/src/Processors/Reset.php +++ b/src/Processors/Reset.php @@ -32,6 +32,6 @@ protected function rollback(?string $connection, ?string $path, ?bool $realPath, protected function count(): int { - return $this->repository->getCompleted()->max('batch'); + return $this->repository->getLastBatchNumber(); } } diff --git a/src/Processors/Rollback.php b/src/Processors/Rollback.php index dbc8b455..0498c3a9 100644 --- a/src/Processors/Rollback.php +++ b/src/Processors/Rollback.php @@ -7,6 +7,7 @@ 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 { @@ -34,7 +35,9 @@ public function handle(): void protected function run(array $actions): void { foreach ($actions as $row) { - $this->rollbackAction($row->action); + $this->rollbackAction( + $this->resolveFilename($row->action) + ); } } @@ -67,4 +70,9 @@ 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 f40cda32..0f5abd84 100644 --- a/src/Processors/Status.php +++ b/src/Processors/Status.php @@ -22,8 +22,16 @@ public function handle(): void return; } - $this->showCaption(); - $this->showStatus(); + [$files, $completed] = $this->getData(); + + if ($this->doesntEmpty($files, $completed)) { + $this->showCaption(); + $this->showStatus($files, $completed); + + return; + } + + $this->notification->info('No actions found'); } protected function showCaption(): void @@ -31,15 +39,7 @@ protected function showCaption(): void $this->notification->twoColumn($this->columnName, $this->columnStatus); } - protected function showStatus(): void - { - $this->showData( - $this->getFiles(), - $this->getCompleted() - ); - } - - protected function showData(array $actions, array $completed): void + protected function showStatus(array $actions, array $completed): void { foreach ($actions as $action) { $status = $this->getStatusFor($completed, $action); @@ -48,6 +48,14 @@ protected function showData(array $actions, array $completed): void } } + protected function getData(): array + { + $files = $this->getFiles(); + $completed = $this->getCompleted(); + + return [$files, $completed]; + } + protected function getStatusFor(array $completed, string $action): string { if ($batch = Arr::get($completed, $action)) { @@ -63,4 +71,9 @@ protected function getCompleted(): array ->pluck('batch', 'action') ->toArray(); } + + protected function doesntEmpty(array $actions, array $completed): bool + { + return ! empty($actions) && ! empty($completed); + } } diff --git a/src/Services/Migrator.php b/src/Services/Migrator.php index cb839042..fb67afd3 100644 --- a/src/Services/Migrator.php +++ b/src/Services/Migrator.php @@ -132,13 +132,13 @@ protected function allowEnvironment(Action $action): bool $env = $this->config->environment(); return $action->allow() - || $this->onEnvironment($env, $action->onEnvironment()) - || $this->exceptEnvironment($env, $action->exceptEnvironment()); + && $this->onEnvironment($env, $action->onEnvironment()) + && $this->exceptEnvironment($env, $action->exceptEnvironment()); } protected function onEnvironment(?string $env, array $on): bool { - return empty($on) || ! in_array($env, $on); + return empty($on) || in_array($env, $on); } protected function exceptEnvironment(?string $env, array $except): bool diff --git a/tests/Commands/MigrateTest.php b/tests/Commands/MigrateTest.php index b6b413a9..4d19a675 100644 --- a/tests/Commands/MigrateTest.php +++ b/tests/Commands/MigrateTest.php @@ -440,13 +440,13 @@ public function testEnabledBefore() $this->artisan(Names::MIGRATE, ['--before' => true])->assertSuccessful(); $this->assertDatabaseCount($table, 1); - $this->assertDatabaseCount($this->table, 9); + $this->assertDatabaseCount($this->table, 10); $this->assertDatabaseMigrationHas($this->table, 'test_before_enabled'); $this->assertDatabaseMigrationDoesntLike($this->table, 'test_before_disabled'); $this->artisan(Names::MIGRATE, ['--before' => true])->assertSuccessful(); $this->assertDatabaseCount($table, 1); - $this->assertDatabaseCount($this->table, 9); + $this->assertDatabaseCount($this->table, 10); $this->assertDatabaseMigrationHas($this->table, 'test_before_enabled'); $this->assertDatabaseMigrationDoesntLike($this->table, 'test_before_disabled'); } @@ -466,25 +466,25 @@ public function testMixedBefore() $this->artisan(Names::MIGRATE, ['--before' => true])->assertSuccessful(); $this->assertDatabaseCount($table, 1); - $this->assertDatabaseCount($this->table, 9); + $this->assertDatabaseCount($this->table, 10); $this->assertDatabaseMigrationHas($this->table, 'test_before_enabled'); $this->assertDatabaseMigrationDoesntLike($this->table, 'test_before_disabled'); $this->artisan(Names::MIGRATE, ['--before' => true])->assertSuccessful(); $this->assertDatabaseCount($table, 1); - $this->assertDatabaseCount($this->table, 9); + $this->assertDatabaseCount($this->table, 10); $this->assertDatabaseMigrationHas($this->table, 'test_before_enabled'); $this->assertDatabaseMigrationDoesntLike($this->table, 'test_before_disabled'); $this->artisan(Names::MIGRATE)->assertSuccessful(); $this->assertDatabaseCount($table, 2); - $this->assertDatabaseCount($this->table, 10); + $this->assertDatabaseCount($this->table, 11); $this->assertDatabaseMigrationHas($this->table, 'test_before_enabled'); $this->assertDatabaseMigrationHas($this->table, 'test_before_disabled'); $this->artisan(Names::MIGRATE)->assertSuccessful(); $this->assertDatabaseCount($table, 2); - $this->assertDatabaseCount($this->table, 10); + $this->assertDatabaseCount($this->table, 11); $this->assertDatabaseMigrationHas($this->table, 'test_before_enabled'); $this->assertDatabaseMigrationHas($this->table, 'test_before_disabled'); } diff --git a/tests/Commands/RollbackTest.php b/tests/Commands/RollbackTest.php index 4d895e85..b646ea96 100644 --- a/tests/Commands/RollbackTest.php +++ b/tests/Commands/RollbackTest.php @@ -58,7 +58,9 @@ public function testEnvironment() $table = 'environment'; - $this->artisan(Names::MIGRATE)->assertSuccessful(); + $this->artisan(Names::MIGRATE) + ->expectsOutputToContain('Installing the action repository') + ->assertSuccessful(); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); diff --git a/tests/Services/GitTest.php b/tests/Services/GitTest.php index 9457a321..d8980c04 100644 --- a/tests/Services/GitTest.php +++ b/tests/Services/GitTest.php @@ -23,6 +23,6 @@ public function testCurrentBranch() protected function git(): Git { - return new Git(); + return $this->app->make(Git::class); } } From e13b0debb73ea1f26016b80af9aca56390a5bdc9 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Mon, 10 Oct 2022 23:18:57 +0300 Subject: [PATCH 106/153] RC --- src/Processors/Make.php | 5 ++++ tests/Commands/FreshTest.php | 1 + tests/Commands/MakeTest.php | 8 ++++-- tests/Commands/MigrateTest.php | 2 ++ tests/Commands/RollbackTest.php | 44 +++++++++++++++++---------------- 5 files changed, 37 insertions(+), 23 deletions(-) diff --git a/src/Processors/Make.php b/src/Processors/Make.php index 88591ee2..2f9e4883 100644 --- a/src/Processors/Make.php +++ b/src/Processors/Make.php @@ -15,6 +15,11 @@ class Make extends Processor protected string $stub = __DIR__ . '/../../resources/stubs/action.stub'; public function handle(): void + { + $this->notification->task('Creating an action', fn () => $this->run()); + } + + protected function run(): void { $name = $this->getName(); $path = $this->getActionsPath($name); diff --git a/tests/Commands/FreshTest.php b/tests/Commands/FreshTest.php index 8b33bd64..53e29952 100644 --- a/tests/Commands/FreshTest.php +++ b/tests/Commands/FreshTest.php @@ -26,6 +26,7 @@ public function testFreshCommand(): void $this->artisan(Names::FRESH) ->expectsOutputToContain('Dropping all actions') + ->expectsOutputToContain('Installing the action repository') ->assertSuccessful(); $this->assertDatabaseHasTable($this->table); diff --git a/tests/Commands/MakeTest.php b/tests/Commands/MakeTest.php index 4adc6822..a351ee2a 100644 --- a/tests/Commands/MakeTest.php +++ b/tests/Commands/MakeTest.php @@ -15,7 +15,9 @@ public function testMakingFiles() $this->assertFileDoesNotExist($path); - $this->artisan(Names::MAKE, compact('name'))->assertSuccessful(); + $this->artisan(Names::MAKE, compact('name')) + ->expectsOutputToContain('Creating an action') + ->assertSuccessful(); $this->assertFileExists($path); @@ -31,7 +33,9 @@ public function testAutoName() $this->assertFileDoesNotExist($path); - $this->artisan(Names::MAKE)->assertSuccessful(); + $this->artisan(Names::MAKE) + ->expectsOutputToContain('Creating an action') + ->assertSuccessful(); $this->assertFileExists($path); } diff --git a/tests/Commands/MigrateTest.php b/tests/Commands/MigrateTest.php index 4d19a675..c39b45a8 100644 --- a/tests/Commands/MigrateTest.php +++ b/tests/Commands/MigrateTest.php @@ -36,7 +36,9 @@ public function testSameName() $this->assertDatabaseCount($this->table, 0); $this->artisan(Names::MAKE, ['name' => 'TestMigration'])->assertSuccessful(); + sleep(2); + $this->artisan(Names::MAKE, ['name' => 'TestMigration'])->assertSuccessful(); $this->artisan(Names::MIGRATE)->assertSuccessful(); diff --git a/tests/Commands/RollbackTest.php b/tests/Commands/RollbackTest.php index b646ea96..54bf2cfd 100644 --- a/tests/Commands/RollbackTest.php +++ b/tests/Commands/RollbackTest.php @@ -58,9 +58,7 @@ public function testEnvironment() $table = 'environment'; - $this->artisan(Names::MIGRATE) - ->expectsOutputToContain('Installing the action repository') - ->assertSuccessful(); + $this->artisan(Names::INSTALL)->assertSuccessful(); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); @@ -71,7 +69,7 @@ public function testEnvironment() $this->artisan(Names::MIGRATE)->assertSuccessful(); $this->assertDatabaseCount($table, 5); - $this->assertDatabaseCount($this->table, 10); + $this->assertDatabaseCount($this->table, 11); $this->assertDatabaseMigrationHas($this->table, 'run_on_all'); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_on_production'); $this->assertDatabaseMigrationHas($this->table, 'run_on_testing'); @@ -93,7 +91,7 @@ public function testDownSuccess() $table = 'success'; - $this->artisan(Names::MIGRATE)->assertSuccessful(); + $this->artisan(Names::INSTALL)->assertSuccessful(); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); @@ -101,7 +99,7 @@ public function testDownSuccess() $this->artisan(Names::MIGRATE)->assertSuccessful(); $this->assertDatabaseCount($table, 2); - $this->assertDatabaseCount($this->table, 10); + $this->assertDatabaseCount($this->table, 11); $this->assertDatabaseMigrationHas($this->table, 'run_success'); $this->artisan(Names::ROLLBACK)->assertSuccessful(); @@ -116,7 +114,7 @@ public function testDownSuccessOnFailed() $table = 'success'; - $this->artisan(Names::MIGRATE)->assertSuccessful(); + $this->artisan(Names::INSTALL)->assertSuccessful(); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); @@ -124,15 +122,19 @@ public function testDownSuccessOnFailed() $this->artisan(Names::MIGRATE)->assertSuccessful(); $this->assertDatabaseCount($table, 2); - $this->assertDatabaseCount($this->table, 10); + $this->assertDatabaseCount($this->table, 11); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_success_on_failed'); try { $this->copySuccessFailureMethod(); - $this->table()->insert(['migration' => '2021_12_23_165048_run_success_on_failed', 'batch' => 999]); + $this->table()->insert(['action' => '2021_12_23_165048_run_success_on_failed', 'batch' => 999]); - $this->artisan(Names::ROLLBACK)->assertSuccessful(); + $this->assertDatabaseCount($table, 2); + $this->assertDatabaseCount($this->table, 12); + $this->assertDatabaseMigrationHas($this->table, 'run_success_on_failed'); + + $this->artisan(Names::ROLLBACK)->assertFailed(); } catch (Throwable $e) { $this->assertInstanceOf(Exception::class, $e); @@ -143,7 +145,7 @@ public function testDownSuccessOnFailed() } $this->assertDatabaseCount($table, 2); - $this->assertDatabaseCount($this->table, 11); + $this->assertDatabaseCount($this->table, 12); $this->assertDatabaseMigrationHas($this->table, 'run_success_on_failed'); } @@ -153,7 +155,7 @@ public function testDownFailed() $table = 'failed'; - $this->artisan(Names::MIGRATE)->assertSuccessful(); + $this->artisan(Names::INSTALL)->assertSuccessful(); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); @@ -161,7 +163,7 @@ public function testDownFailed() $this->artisan(Names::MIGRATE)->assertSuccessful(); $this->assertDatabaseCount($table, 0); - $this->assertDatabaseCount($this->table, 10); + $this->assertDatabaseCount($this->table, 11); $this->assertDatabaseMigrationHas($this->table, 'run_failed'); $this->artisan(Names::ROLLBACK)->assertSuccessful(); @@ -176,7 +178,7 @@ public function testUpFailedOnException() $table = 'failed'; - $this->artisan(Names::MIGRATE)->assertSuccessful(); + $this->artisan(Names::INSTALL)->assertSuccessful(); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); @@ -184,13 +186,13 @@ public function testUpFailedOnException() $this->artisan(Names::MIGRATE)->assertSuccessful(); $this->assertDatabaseCount($table, 0); - $this->assertDatabaseCount($this->table, 10); + $this->assertDatabaseCount($this->table, 11); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_failed_failure'); try { $this->copyFailedMethod(); - $this->table()->insert(['migration' => '2021_12_23_184029_run_failed_failure', 'batch' => 999]); + $this->table()->insert(['action' => '2021_12_23_184029_run_failed_failure', 'batch' => 999]); $this->artisan(Names::ROLLBACK)->assertSuccessful(); } @@ -203,7 +205,7 @@ public function testUpFailedOnException() } $this->assertDatabaseCount($table, 1); - $this->assertDatabaseCount($this->table, 11); + $this->assertDatabaseCount($this->table, 12); $this->assertDatabaseMigrationHas($this->table, 'run_failed_failure'); } @@ -213,7 +215,7 @@ public function testDisabledBefore() $table = 'before'; - $this->artisan(Names::MIGRATE)->assertSuccessful(); + $this->artisan(Names::INSTALL)->assertSuccessful(); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); @@ -222,7 +224,7 @@ public function testDisabledBefore() $this->artisan(Names::MIGRATE)->assertSuccessful(); $this->assertDatabaseCount($table, 2); - $this->assertDatabaseCount($this->table, 10); + $this->assertDatabaseCount($this->table, 11); $this->assertDatabaseMigrationHas($this->table, 'test_before_enabled'); $this->assertDatabaseMigrationHas($this->table, 'test_before_disabled'); $this->artisan(Names::MIGRATE)->assertSuccessful(); @@ -241,7 +243,7 @@ public function testEnabledBefore() $table = 'before'; - $this->artisan(Names::MIGRATE)->assertSuccessful(); + $this->artisan(Names::INSTALL)->assertSuccessful(); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); @@ -250,7 +252,7 @@ public function testEnabledBefore() $this->artisan(Names::MIGRATE, ['--before' => true])->assertSuccessful(); $this->assertDatabaseCount($table, 1); - $this->assertDatabaseCount($this->table, 9); + $this->assertDatabaseCount($this->table, 10); $this->assertDatabaseMigrationHas($this->table, 'test_before_enabled'); $this->assertDatabaseMigrationDoesntLike($this->table, 'test_before_disabled'); $this->artisan(Names::MIGRATE, ['--before' => true])->assertSuccessful(); From dec5811bbcde6624c5b9cd6a0ef3798649f7366d Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Mon, 10 Oct 2022 23:23:23 +0300 Subject: [PATCH 107/153] Error: Class "ChangeMigrationActionsTable" not found --- .../named/2022_08_18_180137_change_migration_actions_table.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/database/migrations/named/2022_08_18_180137_change_migration_actions_table.php b/database/migrations/named/2022_08_18_180137_change_migration_actions_table.php index 3540dc59..314b7ee7 100644 --- a/database/migrations/named/2022_08_18_180137_change_migration_actions_table.php +++ b/database/migrations/named/2022_08_18_180137_change_migration_actions_table.php @@ -2,6 +2,6 @@ use DragonCode\LaravelActions\Database\BaseChangeMigrationColumn; -class BaseChangeMigrationActionsTable extends BaseChangeMigrationColumn +class ChangeMigrationActionsTable extends BaseChangeMigrationColumn { } From 3936a98f78aa8699132e4b687e7002fb33e7273b Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Mon, 10 Oct 2022 23:49:37 +0300 Subject: [PATCH 108/153] Update Git helper --- src/Helpers/Git.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Helpers/Git.php b/src/Helpers/Git.php index 353cb9df..48663c10 100644 --- a/src/Helpers/Git.php +++ b/src/Helpers/Git.php @@ -16,23 +16,28 @@ public function __construct( public function currentBranch(?string $path = null): ?string { if ($this->hasGitDirectory($path)) { - return $this->exec('rev-parse --abbrev-ref HEAD'); + return $this->exec('rev-parse --abbrev-ref HEAD', $this->resolvePath($path)); } return null; } - protected function exec(string $command): ?string + protected function exec(string $command, ?string $path = null): ?string { - return exec(sprintf('git --git-dir %s %s', $this->config->gitPath(), $command)); + return exec(sprintf('git --git-dir "%s" %s', $path, $command)); } protected function hasGitDirectory(?string $path = null): bool { - if ($path = rtrim($path ?: $this->config->gitPath(), '/\\')) { + if ($path = rtrim($this->resolvePath($path), '/\\')) { return Directory::exists($path . DIRECTORY_SEPARATOR . '.git'); } return false; } + + protected function resolvePath(?string $path = null): string + { + return realpath($path ?: $this->config->gitPath()); + } } From d7b9a489f9f543a0b5c29e4e6976b946dc2043a3 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Tue, 11 Oct 2022 00:09:56 +0300 Subject: [PATCH 109/153] Removed output tests --- tests/Commands/FreshTest.php | 5 +---- tests/Commands/InstallTest.php | 13 +++---------- tests/Commands/MakeTest.php | 8 ++------ tests/Commands/MigrateTest.php | 2 +- tests/Commands/StatusTest.php | 4 +--- 5 files changed, 8 insertions(+), 24 deletions(-) diff --git a/tests/Commands/FreshTest.php b/tests/Commands/FreshTest.php index 53e29952..6a2e5b98 100644 --- a/tests/Commands/FreshTest.php +++ b/tests/Commands/FreshTest.php @@ -24,10 +24,7 @@ public function testFreshCommand(): void $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 1); - $this->artisan(Names::FRESH) - ->expectsOutputToContain('Dropping all actions') - ->expectsOutputToContain('Installing the action repository') - ->assertSuccessful(); + $this->artisan(Names::FRESH)->assertSuccessful(); $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 1); diff --git a/tests/Commands/InstallTest.php b/tests/Commands/InstallTest.php index 02f82d29..8d1c318a 100644 --- a/tests/Commands/InstallTest.php +++ b/tests/Commands/InstallTest.php @@ -11,9 +11,7 @@ public function testCreate(): void { $this->assertDatabaseDoesntTable($this->table); - $this->artisan(Names::INSTALL) - ->expectsOutputToContain('Installing the action repository') - ->assertSuccessful(); + $this->artisan(Names::INSTALL)->assertSuccessful(); $this->assertDatabaseHasTable($this->table); } @@ -22,13 +20,8 @@ public function testAlreadyCreated(): void { $this->assertDatabaseDoesntTable($this->table); - $this->artisan(Names::INSTALL) - ->expectsOutputToContain('Installing the action repository') - ->assertSuccessful(); - - $this->artisan(Names::INSTALL) - ->expectsOutputToContain('Actions repository already exists') - ->assertSuccessful(); + $this->artisan(Names::INSTALL)->assertSuccessful(); + $this->artisan(Names::INSTALL)->assertSuccessful(); $this->assertDatabaseHasTable($this->table); } diff --git a/tests/Commands/MakeTest.php b/tests/Commands/MakeTest.php index a351ee2a..4adc6822 100644 --- a/tests/Commands/MakeTest.php +++ b/tests/Commands/MakeTest.php @@ -15,9 +15,7 @@ public function testMakingFiles() $this->assertFileDoesNotExist($path); - $this->artisan(Names::MAKE, compact('name')) - ->expectsOutputToContain('Creating an action') - ->assertSuccessful(); + $this->artisan(Names::MAKE, compact('name'))->assertSuccessful(); $this->assertFileExists($path); @@ -33,9 +31,7 @@ public function testAutoName() $this->assertFileDoesNotExist($path); - $this->artisan(Names::MAKE) - ->expectsOutputToContain('Creating an action') - ->assertSuccessful(); + $this->artisan(Names::MAKE)->assertSuccessful(); $this->assertFileExists($path); } diff --git a/tests/Commands/MigrateTest.php b/tests/Commands/MigrateTest.php index c39b45a8..df11727b 100644 --- a/tests/Commands/MigrateTest.php +++ b/tests/Commands/MigrateTest.php @@ -398,7 +398,7 @@ public function testMigrationNotFound() $this->assertDatabaseHasTable($this->table); - $this->artisan(Names::STATUS)->expectsOutputToContain('No actions found'); + $this->artisan(Names::STATUS)->assertSuccessful(); } public function testDisabledBefore() diff --git a/tests/Commands/StatusTest.php b/tests/Commands/StatusTest.php index 532ed457..fd82dc3c 100644 --- a/tests/Commands/StatusTest.php +++ b/tests/Commands/StatusTest.php @@ -11,9 +11,7 @@ public function testNotFound(): void { $this->assertDatabaseDoesntTable($this->table); - $this->artisan(Names::STATUS) - ->expectsOutputToContain('Actions table not found.') - ->assertSuccessful(); + $this->artisan(Names::STATUS)->assertSuccessful(); $this->assertDatabaseDoesntTable($this->table); } From b0c5cdb1d7608a47d3c3401f1b2df9de7ffd9df5 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Tue, 11 Oct 2022 00:12:41 +0300 Subject: [PATCH 110/153] Call to undefined method Illuminate\Foundation\Testing\PendingCommand::assertSuccessful() --- tests/Commands/FreshTest.php | 9 +-- tests/Commands/InstallTest.php | 7 +- tests/Commands/MakeTest.php | 5 +- tests/Commands/MigrateTest.php | 109 ++++++++++++++++---------------- tests/Commands/RefreshTest.php | 9 +-- tests/Commands/ResetTest.php | 9 +-- tests/Commands/RollbackTest.php | 65 +++++++++---------- tests/Commands/StatusTest.php | 13 ++-- 8 files changed, 117 insertions(+), 109 deletions(-) diff --git a/tests/Commands/FreshTest.php b/tests/Commands/FreshTest.php index 6a2e5b98..7b4bbc11 100644 --- a/tests/Commands/FreshTest.php +++ b/tests/Commands/FreshTest.php @@ -4,6 +4,7 @@ namespace Tests\Commands; +use DragonCode\LaravelActions\Console\Command; use DragonCode\LaravelActions\Constants\Names; use Tests\TestCase; @@ -13,18 +14,18 @@ public function testFreshCommand(): void { $this->assertDatabaseDoesntTable($this->table); - $this->artisan(Names::INSTALL)->assertSuccessful(); + $this->artisan(Names::INSTALL)->assertExitCode(Command::SUCCESS); $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 0); - $this->artisan(Names::MAKE, ['name' => 'Fresh'])->assertSuccessful(); - $this->artisan(Names::MIGRATE)->assertSuccessful(); + $this->artisan(Names::MAKE, ['name' => 'Fresh'])->assertExitCode(Command::SUCCESS); + $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 1); - $this->artisan(Names::FRESH)->assertSuccessful(); + $this->artisan(Names::FRESH)->assertExitCode(Command::SUCCESS); $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 1); diff --git a/tests/Commands/InstallTest.php b/tests/Commands/InstallTest.php index 8d1c318a..3858821b 100644 --- a/tests/Commands/InstallTest.php +++ b/tests/Commands/InstallTest.php @@ -2,6 +2,7 @@ namespace Tests\Commands; +use DragonCode\LaravelActions\Console\Command; use DragonCode\LaravelActions\Constants\Names; use Tests\TestCase; @@ -11,7 +12,7 @@ public function testCreate(): void { $this->assertDatabaseDoesntTable($this->table); - $this->artisan(Names::INSTALL)->assertSuccessful(); + $this->artisan(Names::INSTALL)->assertExitCode(Command::SUCCESS); $this->assertDatabaseHasTable($this->table); } @@ -20,8 +21,8 @@ public function testAlreadyCreated(): void { $this->assertDatabaseDoesntTable($this->table); - $this->artisan(Names::INSTALL)->assertSuccessful(); - $this->artisan(Names::INSTALL)->assertSuccessful(); + $this->artisan(Names::INSTALL)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::INSTALL)->assertExitCode(Command::SUCCESS); $this->assertDatabaseHasTable($this->table); } diff --git a/tests/Commands/MakeTest.php b/tests/Commands/MakeTest.php index 4adc6822..1fa05d7f 100644 --- a/tests/Commands/MakeTest.php +++ b/tests/Commands/MakeTest.php @@ -2,6 +2,7 @@ namespace Tests\Commands; +use DragonCode\LaravelActions\Console\Command; use DragonCode\LaravelActions\Constants\Names; use Tests\TestCase; @@ -15,7 +16,7 @@ public function testMakingFiles() $this->assertFileDoesNotExist($path); - $this->artisan(Names::MAKE, compact('name'))->assertSuccessful(); + $this->artisan(Names::MAKE, compact('name'))->assertExitCode(Command::SUCCESS); $this->assertFileExists($path); @@ -31,7 +32,7 @@ public function testAutoName() $this->assertFileDoesNotExist($path); - $this->artisan(Names::MAKE)->assertSuccessful(); + $this->artisan(Names::MAKE)->assertExitCode(Command::SUCCESS); $this->assertFileExists($path); } diff --git a/tests/Commands/MigrateTest.php b/tests/Commands/MigrateTest.php index df11727b..538a2599 100644 --- a/tests/Commands/MigrateTest.php +++ b/tests/Commands/MigrateTest.php @@ -2,6 +2,7 @@ namespace Tests\Commands; +use DragonCode\LaravelActions\Console\Command; use DragonCode\LaravelActions\Constants\Names; use Exception; use Illuminate\Support\Str; @@ -14,13 +15,13 @@ public function testMigrationCommand() { $this->assertDatabaseDoesntTable($this->table); - $this->artisan(Names::INSTALL)->assertSuccessful(); + $this->artisan(Names::INSTALL)->assertExitCode(Command::SUCCESS); $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 0); - $this->artisan(Names::MAKE, ['name' => 'TestMigration'])->assertSuccessful(); - $this->artisan(Names::MIGRATE)->assertSuccessful(); + $this->artisan(Names::MAKE, ['name' => 'TestMigration'])->assertExitCode(Command::SUCCESS); + $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); $this->assertDatabaseCount($this->table, 1); $this->assertDatabaseMigrationHas($this->table, 'test_migration'); @@ -30,17 +31,17 @@ public function testSameName() { $this->assertDatabaseDoesntTable($this->table); - $this->artisan(Names::INSTALL)->assertSuccessful(); + $this->artisan(Names::INSTALL)->assertExitCode(Command::SUCCESS); $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 0); - $this->artisan(Names::MAKE, ['name' => 'TestMigration'])->assertSuccessful(); + $this->artisan(Names::MAKE, ['name' => 'TestMigration'])->assertExitCode(Command::SUCCESS); sleep(2); - $this->artisan(Names::MAKE, ['name' => 'TestMigration'])->assertSuccessful(); - $this->artisan(Names::MIGRATE)->assertSuccessful(); + $this->artisan(Names::MAKE, ['name' => 'TestMigration'])->assertExitCode(Command::SUCCESS); + $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); $this->assertDatabaseCount($this->table, 2); $this->assertDatabaseMigrationHas($this->table, 'test_migration'); @@ -52,27 +53,27 @@ public function testOnce() $table = 'every_time'; - $this->artisan(Names::INSTALL)->assertSuccessful(); + $this->artisan(Names::INSTALL)->assertExitCode(Command::SUCCESS); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, $table); - $this->artisan(Names::MIGRATE)->assertSuccessful(); + $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); $this->assertDatabaseCount($table, 1); $this->assertDatabaseCount($this->table, 11); $this->assertDatabaseMigrationDoesntLike($this->table, $table); - $this->artisan(Names::MIGRATE)->assertSuccessful(); + $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); $this->assertDatabaseCount($table, 2); $this->assertDatabaseCount($this->table, 11); $this->assertDatabaseMigrationDoesntLike($this->table, $table); - $this->artisan(Names::MIGRATE)->assertSuccessful(); + $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); $this->assertDatabaseCount($table, 3); $this->assertDatabaseCount($this->table, 11); $this->assertDatabaseMigrationDoesntLike($this->table, $table); - $this->artisan(Names::MIGRATE)->assertSuccessful(); + $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); $this->assertDatabaseCount($table, 4); $this->assertDatabaseCount($this->table, 11); @@ -85,12 +86,12 @@ public function testSuccessTransaction() $table = 'transactions'; - $this->artisan(Names::INSTALL)->assertSuccessful(); + $this->artisan(Names::INSTALL)->assertExitCode(Command::SUCCESS); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, $table); - $this->artisan(Names::MIGRATE)->assertSuccessful(); + $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); $this->assertDatabaseCount($table, 3); $this->assertDatabaseCount($this->table, 1); @@ -103,14 +104,14 @@ public function testFailedTransaction() $table = 'transactions'; - $this->artisan(Names::INSTALL)->assertSuccessful(); + $this->artisan(Names::INSTALL)->assertExitCode(Command::SUCCESS); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, $table); try { - $this->artisan(Names::MIGRATE)->assertSuccessful(); + $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); } catch (Exception $e) { $this->assertSame(Exception::class, get_class($e)); @@ -128,7 +129,7 @@ public function testSingleEnvironment() $table = 'environment'; - $this->artisan(Names::INSTALL)->assertSuccessful(); + $this->artisan(Names::INSTALL)->assertExitCode(Command::SUCCESS); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); @@ -137,7 +138,7 @@ public function testSingleEnvironment() $this->assertDatabaseMigrationDoesntLike($this->table, 'run_on_testing'); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_except_production'); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_except_testing'); - $this->artisan(Names::MIGRATE)->assertSuccessful(); + $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); $this->assertDatabaseCount($table, 5); $this->assertDatabaseCount($this->table, 11); @@ -146,7 +147,7 @@ public function testSingleEnvironment() $this->assertDatabaseMigrationHas($this->table, 'run_on_testing'); $this->assertDatabaseMigrationHas($this->table, 'run_except_production'); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_except_testing'); - $this->artisan(Names::MIGRATE)->assertSuccessful(); + $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); $this->assertDatabaseCount($table, 5); $this->assertDatabaseCount($this->table, 11); @@ -163,7 +164,7 @@ public function testManyEnvironments() $table = 'environment'; - $this->artisan(Names::INSTALL)->assertSuccessful(); + $this->artisan(Names::INSTALL)->assertExitCode(Command::SUCCESS); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); @@ -174,7 +175,7 @@ public function testManyEnvironments() $this->assertDatabaseMigrationDoesntLike($this->table, 'run_except_production'); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_except_testing'); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_except_many_environments'); - $this->artisan(Names::MIGRATE)->assertSuccessful(); + $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); $this->assertDatabaseCount($table, 5); $this->assertDatabaseCount($this->table, 11); @@ -185,7 +186,7 @@ public function testManyEnvironments() $this->assertDatabaseMigrationHas($this->table, 'run_except_production'); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_except_testing'); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_except_many_environments'); - $this->artisan(Names::MIGRATE)->assertSuccessful(); + $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); $this->assertDatabaseCount($table, 5); $this->assertDatabaseCount($this->table, 11); @@ -204,19 +205,19 @@ public function testAllow() $table = 'environment'; - $this->artisan(Names::INSTALL)->assertSuccessful(); + $this->artisan(Names::INSTALL)->assertExitCode(Command::SUCCESS); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_allow'); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_disallow'); - $this->artisan(Names::MIGRATE)->assertSuccessful(); + $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); $this->assertDatabaseCount($table, 5); $this->assertDatabaseCount($this->table, 11); $this->assertDatabaseMigrationHas($this->table, 'run_allow'); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_disallow'); - $this->artisan(Names::MIGRATE)->assertSuccessful(); + $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); $this->assertDatabaseCount($table, 5); $this->assertDatabaseCount($this->table, 11); @@ -230,12 +231,12 @@ public function testUpSuccess() $table = 'success'; - $this->artisan(Names::INSTALL)->assertSuccessful(); + $this->artisan(Names::INSTALL)->assertExitCode(Command::SUCCESS); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_success'); - $this->artisan(Names::MIGRATE)->assertSuccessful(); + $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); $this->assertDatabaseCount($table, 2); $this->assertDatabaseCount($this->table, 11); @@ -248,12 +249,12 @@ public function testUpSuccessOnFailed() $table = 'success'; - $this->artisan(Names::INSTALL)->assertSuccessful(); + $this->artisan(Names::INSTALL)->assertExitCode(Command::SUCCESS); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_success_on_failed'); - $this->artisan(Names::MIGRATE)->assertSuccessful(); + $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); $this->assertDatabaseCount($table, 2); $this->assertDatabaseCount($this->table, 11); @@ -262,7 +263,7 @@ public function testUpSuccessOnFailed() try { $this->copySuccessFailureMethod(); - $this->artisan(Names::MIGRATE)->assertSuccessful(); + $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); } catch (Throwable $e) { $this->assertInstanceOf(Exception::class, $e); @@ -283,12 +284,12 @@ public function testUpFailed() $table = 'failed'; - $this->artisan(Names::INSTALL)->assertSuccessful(); + $this->artisan(Names::INSTALL)->assertExitCode(Command::SUCCESS); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_failed'); - $this->artisan(Names::MIGRATE)->assertSuccessful(); + $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 11); @@ -301,12 +302,12 @@ public function testUpFailedOnException() $table = 'failed'; - $this->artisan(Names::INSTALL)->assertSuccessful(); + $this->artisan(Names::INSTALL)->assertExitCode(Command::SUCCESS); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_failed_failure'); - $this->artisan(Names::MIGRATE)->assertSuccessful(); + $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 11); @@ -315,7 +316,7 @@ public function testUpFailedOnException() try { $this->copyFailedMethod(); - $this->artisan(Names::MIGRATE)->assertSuccessful(); + $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); } catch (Throwable $e) { $this->assertInstanceOf(Exception::class, $e); @@ -338,12 +339,12 @@ public function testPathAsFileWithExtension() $path = 'sub_path/2021_12_15_205804_baz.php'; - $this->artisan(Names::INSTALL)->assertSuccessful(); + $this->artisan(Names::INSTALL)->assertExitCode(Command::SUCCESS); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'baz'); - $this->artisan(Names::MIGRATE, ['--path' => $path])->assertSuccessful(); + $this->artisan(Names::MIGRATE, ['--path' => $path])->assertExitCode(Command::SUCCESS); $this->assertDatabaseCount($table, 1); $this->assertDatabaseCount($this->table, 1); @@ -358,12 +359,12 @@ public function testPathAsFileWithoutExtension() $path = 'sub_path/2021_12_15_205804_baz'; - $this->artisan(Names::INSTALL)->assertSuccessful(); + $this->artisan(Names::INSTALL)->assertExitCode(Command::SUCCESS); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'baz'); - $this->artisan(Names::MIGRATE, ['--path' => $path])->assertSuccessful(); + $this->artisan(Names::MIGRATE, ['--path' => $path])->assertExitCode(Command::SUCCESS); $this->assertDatabaseCount($table, 1); $this->assertDatabaseCount($this->table, 1); @@ -378,12 +379,12 @@ public function testPathAsDirectory() $path = 'sub_path'; - $this->artisan(Names::INSTALL)->assertSuccessful(); + $this->artisan(Names::INSTALL)->assertExitCode(Command::SUCCESS); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'baz'); - $this->artisan(Names::MIGRATE, ['--path' => $path])->assertSuccessful(); + $this->artisan(Names::MIGRATE, ['--path' => $path])->assertExitCode(Command::SUCCESS); $this->assertDatabaseCount($table, 1); $this->assertDatabaseCount($this->table, 1); @@ -394,11 +395,11 @@ public function testMigrationNotFound() { $this->assertDatabaseDoesntTable($this->table); - $this->artisan(Names::INSTALL)->assertSuccessful(); + $this->artisan(Names::INSTALL)->assertExitCode(Command::SUCCESS); $this->assertDatabaseHasTable($this->table); - $this->artisan(Names::STATUS)->assertSuccessful(); + $this->artisan(Names::STATUS)->assertExitCode(Command::SUCCESS); } public function testDisabledBefore() @@ -407,19 +408,19 @@ public function testDisabledBefore() $table = 'before'; - $this->artisan(Names::INSTALL)->assertSuccessful(); + $this->artisan(Names::INSTALL)->assertExitCode(Command::SUCCESS); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'test_before_enabled'); $this->assertDatabaseMigrationDoesntLike($this->table, 'test_before_disabled'); - $this->artisan(Names::MIGRATE)->assertSuccessful(); + $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); $this->assertDatabaseCount($table, 2); $this->assertDatabaseCount($this->table, 11); $this->assertDatabaseMigrationHas($this->table, 'test_before_enabled'); $this->assertDatabaseMigrationHas($this->table, 'test_before_disabled'); - $this->artisan(Names::MIGRATE)->assertSuccessful(); + $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); $this->assertDatabaseCount($table, 2); $this->assertDatabaseCount($this->table, 11); @@ -433,19 +434,19 @@ public function testEnabledBefore() $table = 'before'; - $this->artisan(Names::INSTALL)->assertSuccessful(); + $this->artisan(Names::INSTALL)->assertExitCode(Command::SUCCESS); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'test_before_enabled'); $this->assertDatabaseMigrationDoesntLike($this->table, 'test_before_disabled'); - $this->artisan(Names::MIGRATE, ['--before' => true])->assertSuccessful(); + $this->artisan(Names::MIGRATE, ['--before' => true])->assertExitCode(Command::SUCCESS); $this->assertDatabaseCount($table, 1); $this->assertDatabaseCount($this->table, 10); $this->assertDatabaseMigrationHas($this->table, 'test_before_enabled'); $this->assertDatabaseMigrationDoesntLike($this->table, 'test_before_disabled'); - $this->artisan(Names::MIGRATE, ['--before' => true])->assertSuccessful(); + $this->artisan(Names::MIGRATE, ['--before' => true])->assertExitCode(Command::SUCCESS); $this->assertDatabaseCount($table, 1); $this->assertDatabaseCount($this->table, 10); @@ -459,31 +460,31 @@ public function testMixedBefore() $table = 'before'; - $this->artisan(Names::INSTALL)->assertSuccessful(); + $this->artisan(Names::INSTALL)->assertExitCode(Command::SUCCESS); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'test_before_enabled'); $this->assertDatabaseMigrationDoesntLike($this->table, 'test_before_disabled'); - $this->artisan(Names::MIGRATE, ['--before' => true])->assertSuccessful(); + $this->artisan(Names::MIGRATE, ['--before' => true])->assertExitCode(Command::SUCCESS); $this->assertDatabaseCount($table, 1); $this->assertDatabaseCount($this->table, 10); $this->assertDatabaseMigrationHas($this->table, 'test_before_enabled'); $this->assertDatabaseMigrationDoesntLike($this->table, 'test_before_disabled'); - $this->artisan(Names::MIGRATE, ['--before' => true])->assertSuccessful(); + $this->artisan(Names::MIGRATE, ['--before' => true])->assertExitCode(Command::SUCCESS); $this->assertDatabaseCount($table, 1); $this->assertDatabaseCount($this->table, 10); $this->assertDatabaseMigrationHas($this->table, 'test_before_enabled'); $this->assertDatabaseMigrationDoesntLike($this->table, 'test_before_disabled'); - $this->artisan(Names::MIGRATE)->assertSuccessful(); + $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); $this->assertDatabaseCount($table, 2); $this->assertDatabaseCount($this->table, 11); $this->assertDatabaseMigrationHas($this->table, 'test_before_enabled'); $this->assertDatabaseMigrationHas($this->table, 'test_before_disabled'); - $this->artisan(Names::MIGRATE)->assertSuccessful(); + $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); $this->assertDatabaseCount($table, 2); $this->assertDatabaseCount($this->table, 11); diff --git a/tests/Commands/RefreshTest.php b/tests/Commands/RefreshTest.php index 01e5be7a..d661d593 100644 --- a/tests/Commands/RefreshTest.php +++ b/tests/Commands/RefreshTest.php @@ -2,6 +2,7 @@ namespace Tests\Commands; +use DragonCode\LaravelActions\Console\Command; use DragonCode\LaravelActions\Constants\Names; use Tests\TestCase; @@ -11,18 +12,18 @@ public function testRefreshCommand() { $this->assertDatabaseDoesntTable($this->table); - $this->artisan(Names::INSTALL)->assertSuccessful(); + $this->artisan(Names::INSTALL)->assertExitCode(Command::SUCCESS); $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 0); - $this->artisan(Names::MAKE, ['name' => 'Refresh'])->assertSuccessful(); - $this->artisan(Names::MIGRATE)->assertSuccessful(); + $this->artisan(Names::MAKE, ['name' => 'Refresh'])->assertExitCode(Command::SUCCESS); + $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 1); - $this->artisan(Names::REFRESH)->assertSuccessful(); + $this->artisan(Names::REFRESH)->assertExitCode(Command::SUCCESS); $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 1); diff --git a/tests/Commands/ResetTest.php b/tests/Commands/ResetTest.php index 31ad1f71..4b88b637 100644 --- a/tests/Commands/ResetTest.php +++ b/tests/Commands/ResetTest.php @@ -2,6 +2,7 @@ namespace Tests\Commands; +use DragonCode\LaravelActions\Console\Command; use DragonCode\LaravelActions\Constants\Names; use Tests\TestCase; @@ -11,19 +12,19 @@ public function testResetCommand() { $this->assertDatabaseDoesntTable($this->table); - $this->artisan(Names::INSTALL)->assertSuccessful(); + $this->artisan(Names::INSTALL)->assertExitCode(Command::SUCCESS); $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 0); - $this->artisan(Names::MAKE, ['name' => 'Reset'])->assertSuccessful(); - $this->artisan(Names::MIGRATE)->assertSuccessful(); + $this->artisan(Names::MAKE, ['name' => 'Reset'])->assertExitCode(Command::SUCCESS); + $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 1); $this->assertDatabaseMigrationHas($this->table, 'reset'); - $this->artisan(Names::RESET)->assertSuccessful(); + $this->artisan(Names::RESET)->assertExitCode(Command::SUCCESS); $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 0); diff --git a/tests/Commands/RollbackTest.php b/tests/Commands/RollbackTest.php index 54bf2cfd..fa5638be 100644 --- a/tests/Commands/RollbackTest.php +++ b/tests/Commands/RollbackTest.php @@ -2,6 +2,7 @@ namespace Tests\Commands; +use DragonCode\LaravelActions\Console\Command; use DragonCode\LaravelActions\Constants\Names; use Exception; use Illuminate\Support\Str; @@ -14,15 +15,15 @@ public function testRollbackCommand() { $this->assertDatabaseDoesntTable($this->table); - $this->artisan(Names::INSTALL)->assertSuccessful(); + $this->artisan(Names::INSTALL)->assertExitCode(Command::SUCCESS); $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 0); - $this->artisan(Names::MAKE, ['name' => 'RollbackOne'])->assertSuccessful(); - $this->artisan(Names::MAKE, ['name' => 'RollbackTwo'])->assertSuccessful(); + $this->artisan(Names::MAKE, ['name' => 'RollbackOne'])->assertExitCode(Command::SUCCESS); + $this->artisan(Names::MAKE, ['name' => 'RollbackTwo'])->assertExitCode(Command::SUCCESS); - $this->artisan(Names::MIGRATE)->assertSuccessful(); + $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 2); @@ -31,18 +32,18 @@ public function testRollbackCommand() $this->assertDatabaseMigrationHas($this->table, 'rollback_two'); $this->assertDatabaseMigrationDoesntLike($this->table, 'rollback_tree'); - $this->artisan(Names::ROLLBACK)->assertSuccessful(); + $this->artisan(Names::ROLLBACK)->assertExitCode(Command::SUCCESS); $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 0); - $this->artisan(Names::MIGRATE)->assertSuccessful(); + $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 2); - $this->artisan(Names::MAKE, ['name' => 'RollbackTree'])->assertSuccessful(); - $this->artisan(Names::MIGRATE)->assertSuccessful(); + $this->artisan(Names::MAKE, ['name' => 'RollbackTree'])->assertExitCode(Command::SUCCESS); + $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 3); @@ -58,7 +59,7 @@ public function testEnvironment() $table = 'environment'; - $this->artisan(Names::INSTALL)->assertSuccessful(); + $this->artisan(Names::INSTALL)->assertExitCode(Command::SUCCESS); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); @@ -66,7 +67,7 @@ public function testEnvironment() $this->assertDatabaseMigrationDoesntLike($this->table, 'run_on_production'); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_on_testing'); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_on_many_environments'); - $this->artisan(Names::MIGRATE)->assertSuccessful(); + $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); $this->assertDatabaseCount($table, 5); $this->assertDatabaseCount($this->table, 11); @@ -74,9 +75,9 @@ public function testEnvironment() $this->assertDatabaseMigrationDoesntLike($this->table, 'run_on_production'); $this->assertDatabaseMigrationHas($this->table, 'run_on_testing'); $this->assertDatabaseMigrationHas($this->table, 'run_on_many_environments'); - $this->artisan(Names::MIGRATE)->assertSuccessful(); + $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); - $this->artisan(Names::ROLLBACK)->assertSuccessful(); + $this->artisan(Names::ROLLBACK)->assertExitCode(Command::SUCCESS); $this->assertDatabaseCount($table, 10); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_on_all'); @@ -91,18 +92,18 @@ public function testDownSuccess() $table = 'success'; - $this->artisan(Names::INSTALL)->assertSuccessful(); + $this->artisan(Names::INSTALL)->assertExitCode(Command::SUCCESS); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_success'); - $this->artisan(Names::MIGRATE)->assertSuccessful(); + $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); $this->assertDatabaseCount($table, 2); $this->assertDatabaseCount($this->table, 11); $this->assertDatabaseMigrationHas($this->table, 'run_success'); - $this->artisan(Names::ROLLBACK)->assertSuccessful(); + $this->artisan(Names::ROLLBACK)->assertExitCode(Command::SUCCESS); $this->assertDatabaseCount($table, 4); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_success'); @@ -114,12 +115,12 @@ public function testDownSuccessOnFailed() $table = 'success'; - $this->artisan(Names::INSTALL)->assertSuccessful(); + $this->artisan(Names::INSTALL)->assertExitCode(Command::SUCCESS); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_success_on_failed'); - $this->artisan(Names::MIGRATE)->assertSuccessful(); + $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); $this->assertDatabaseCount($table, 2); $this->assertDatabaseCount($this->table, 11); @@ -134,7 +135,7 @@ public function testDownSuccessOnFailed() $this->assertDatabaseCount($this->table, 12); $this->assertDatabaseMigrationHas($this->table, 'run_success_on_failed'); - $this->artisan(Names::ROLLBACK)->assertFailed(); + $this->artisan(Names::ROLLBACK)->assertExitCode(Command::FAILURE); } catch (Throwable $e) { $this->assertInstanceOf(Exception::class, $e); @@ -155,18 +156,18 @@ public function testDownFailed() $table = 'failed'; - $this->artisan(Names::INSTALL)->assertSuccessful(); + $this->artisan(Names::INSTALL)->assertExitCode(Command::SUCCESS); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_failed'); - $this->artisan(Names::MIGRATE)->assertSuccessful(); + $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 11); $this->assertDatabaseMigrationHas($this->table, 'run_failed'); - $this->artisan(Names::ROLLBACK)->assertSuccessful(); + $this->artisan(Names::ROLLBACK)->assertExitCode(Command::SUCCESS); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_failed'); @@ -178,12 +179,12 @@ public function testUpFailedOnException() $table = 'failed'; - $this->artisan(Names::INSTALL)->assertSuccessful(); + $this->artisan(Names::INSTALL)->assertExitCode(Command::SUCCESS); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_failed_failure'); - $this->artisan(Names::MIGRATE)->assertSuccessful(); + $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 11); @@ -194,7 +195,7 @@ public function testUpFailedOnException() $this->table()->insert(['action' => '2021_12_23_184029_run_failed_failure', 'batch' => 999]); - $this->artisan(Names::ROLLBACK)->assertSuccessful(); + $this->artisan(Names::ROLLBACK)->assertExitCode(Command::SUCCESS); } catch (Throwable $e) { $this->assertInstanceOf(Exception::class, $e); @@ -215,21 +216,21 @@ public function testDisabledBefore() $table = 'before'; - $this->artisan(Names::INSTALL)->assertSuccessful(); + $this->artisan(Names::INSTALL)->assertExitCode(Command::SUCCESS); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'test_before_enabled'); $this->assertDatabaseMigrationDoesntLike($this->table, 'test_before_disabled'); - $this->artisan(Names::MIGRATE)->assertSuccessful(); + $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); $this->assertDatabaseCount($table, 2); $this->assertDatabaseCount($this->table, 11); $this->assertDatabaseMigrationHas($this->table, 'test_before_enabled'); $this->assertDatabaseMigrationHas($this->table, 'test_before_disabled'); - $this->artisan(Names::MIGRATE)->assertSuccessful(); + $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); - $this->artisan(Names::ROLLBACK)->assertSuccessful(); + $this->artisan(Names::ROLLBACK)->assertExitCode(Command::SUCCESS); $this->assertDatabaseCount($table, 4); $this->assertDatabaseCount($this->table, 0); @@ -243,21 +244,21 @@ public function testEnabledBefore() $table = 'before'; - $this->artisan(Names::INSTALL)->assertSuccessful(); + $this->artisan(Names::INSTALL)->assertExitCode(Command::SUCCESS); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'test_before_enabled'); $this->assertDatabaseMigrationDoesntLike($this->table, 'test_before_disabled'); - $this->artisan(Names::MIGRATE, ['--before' => true])->assertSuccessful(); + $this->artisan(Names::MIGRATE, ['--before' => true])->assertExitCode(Command::SUCCESS); $this->assertDatabaseCount($table, 1); $this->assertDatabaseCount($this->table, 10); $this->assertDatabaseMigrationHas($this->table, 'test_before_enabled'); $this->assertDatabaseMigrationDoesntLike($this->table, 'test_before_disabled'); - $this->artisan(Names::MIGRATE, ['--before' => true])->assertSuccessful(); + $this->artisan(Names::MIGRATE, ['--before' => true])->assertExitCode(Command::SUCCESS); - $this->artisan(Names::ROLLBACK)->assertSuccessful(); + $this->artisan(Names::ROLLBACK)->assertExitCode(Command::SUCCESS); $this->assertDatabaseCount($table, 2); $this->assertDatabaseCount($this->table, 0); diff --git a/tests/Commands/StatusTest.php b/tests/Commands/StatusTest.php index fd82dc3c..eae94f5c 100644 --- a/tests/Commands/StatusTest.php +++ b/tests/Commands/StatusTest.php @@ -2,6 +2,7 @@ namespace Tests\Commands; +use DragonCode\LaravelActions\Console\Command; use DragonCode\LaravelActions\Constants\Names; use Tests\TestCase; @@ -11,7 +12,7 @@ public function testNotFound(): void { $this->assertDatabaseDoesntTable($this->table); - $this->artisan(Names::STATUS)->assertSuccessful(); + $this->artisan(Names::STATUS)->assertExitCode(Command::SUCCESS); $this->assertDatabaseDoesntTable($this->table); } @@ -20,19 +21,19 @@ public function testStatusCommand() { $this->assertDatabaseDoesntTable($this->table); - $this->artisan(Names::INSTALL)->assertSuccessful(); + $this->artisan(Names::INSTALL)->assertExitCode(Command::SUCCESS); $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 0); - $this->artisan(Names::STATUS)->expectsTable([], [])->assertSuccessful(); + $this->artisan(Names::STATUS)->expectsTable([], [])->assertExitCode(Command::SUCCESS); - $this->artisan(Names::MAKE, ['name' => 'Status'])->assertSuccessful(); - $this->artisan(Names::MIGRATE)->assertSuccessful(); + $this->artisan(Names::MAKE, ['name' => 'Status'])->assertExitCode(Command::SUCCESS); + $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); $this->assertDatabaseCount($this->table, 1); - $this->artisan(Names::STATUS)->assertSuccessful(); + $this->artisan(Names::STATUS)->assertExitCode(Command::SUCCESS); $this->assertDatabaseMigrationHas($this->table, 'status'); } From cadda4256b81994624620585f6e48818cca48094 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Tue, 11 Oct 2022 00:13:27 +0300 Subject: [PATCH 111/153] BadMethodCallException: Method Illuminate\Database\Schema\Blueprint::id does not exist. --- src/Repositories/ActionRepository.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Repositories/ActionRepository.php b/src/Repositories/ActionRepository.php index 3c028c79..5bb76319 100644 --- a/src/Repositories/ActionRepository.php +++ b/src/Repositories/ActionRepository.php @@ -74,7 +74,7 @@ public function delete(string $action): void public function createRepository(): void { $this->schema()->create($this->config->table(), function (Blueprint $table) { - $table->id(); + $table->bigIncrements('id'); $table->string('action'); From dbe892ae6a0f29e23b8b99275593ee6a484d20f2 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Tue, 11 Oct 2022 00:15:10 +0300 Subject: [PATCH 112/153] Undefined constant DragonCode\LaravelActions\Console\Command::SUCCESS --- tests/Commands/FreshTest.php | 8 +-- tests/Commands/InstallTest.php | 6 +- tests/Commands/MakeTest.php | 4 +- tests/Commands/MigrateTest.php | 108 ++++++++++++++++---------------- tests/Commands/RefreshTest.php | 8 +-- tests/Commands/ResetTest.php | 8 +-- tests/Commands/RollbackTest.php | 64 +++++++++---------- tests/Commands/StatusTest.php | 12 ++-- 8 files changed, 109 insertions(+), 109 deletions(-) diff --git a/tests/Commands/FreshTest.php b/tests/Commands/FreshTest.php index 7b4bbc11..6cce11c5 100644 --- a/tests/Commands/FreshTest.php +++ b/tests/Commands/FreshTest.php @@ -14,18 +14,18 @@ public function testFreshCommand(): void { $this->assertDatabaseDoesntTable($this->table); - $this->artisan(Names::INSTALL)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::INSTALL)->assertExitCode(0); $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 0); - $this->artisan(Names::MAKE, ['name' => 'Fresh'])->assertExitCode(Command::SUCCESS); - $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::MAKE, ['name' => 'Fresh'])->assertExitCode(0); + $this->artisan(Names::MIGRATE)->assertExitCode(0); $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 1); - $this->artisan(Names::FRESH)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::FRESH)->assertExitCode(0); $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 1); diff --git a/tests/Commands/InstallTest.php b/tests/Commands/InstallTest.php index 3858821b..f1c898e5 100644 --- a/tests/Commands/InstallTest.php +++ b/tests/Commands/InstallTest.php @@ -12,7 +12,7 @@ public function testCreate(): void { $this->assertDatabaseDoesntTable($this->table); - $this->artisan(Names::INSTALL)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::INSTALL)->assertExitCode(0); $this->assertDatabaseHasTable($this->table); } @@ -21,8 +21,8 @@ public function testAlreadyCreated(): void { $this->assertDatabaseDoesntTable($this->table); - $this->artisan(Names::INSTALL)->assertExitCode(Command::SUCCESS); - $this->artisan(Names::INSTALL)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::INSTALL)->assertExitCode(0); + $this->artisan(Names::INSTALL)->assertExitCode(0); $this->assertDatabaseHasTable($this->table); } diff --git a/tests/Commands/MakeTest.php b/tests/Commands/MakeTest.php index 1fa05d7f..e7e6445c 100644 --- a/tests/Commands/MakeTest.php +++ b/tests/Commands/MakeTest.php @@ -16,7 +16,7 @@ public function testMakingFiles() $this->assertFileDoesNotExist($path); - $this->artisan(Names::MAKE, compact('name'))->assertExitCode(Command::SUCCESS); + $this->artisan(Names::MAKE, compact('name'))->assertExitCode(0); $this->assertFileExists($path); @@ -32,7 +32,7 @@ public function testAutoName() $this->assertFileDoesNotExist($path); - $this->artisan(Names::MAKE)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::MAKE)->assertExitCode(0); $this->assertFileExists($path); } diff --git a/tests/Commands/MigrateTest.php b/tests/Commands/MigrateTest.php index 538a2599..ad5898b4 100644 --- a/tests/Commands/MigrateTest.php +++ b/tests/Commands/MigrateTest.php @@ -15,13 +15,13 @@ public function testMigrationCommand() { $this->assertDatabaseDoesntTable($this->table); - $this->artisan(Names::INSTALL)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::INSTALL)->assertExitCode(0); $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 0); - $this->artisan(Names::MAKE, ['name' => 'TestMigration'])->assertExitCode(Command::SUCCESS); - $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::MAKE, ['name' => 'TestMigration'])->assertExitCode(0); + $this->artisan(Names::MIGRATE)->assertExitCode(0); $this->assertDatabaseCount($this->table, 1); $this->assertDatabaseMigrationHas($this->table, 'test_migration'); @@ -31,17 +31,17 @@ public function testSameName() { $this->assertDatabaseDoesntTable($this->table); - $this->artisan(Names::INSTALL)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::INSTALL)->assertExitCode(0); $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 0); - $this->artisan(Names::MAKE, ['name' => 'TestMigration'])->assertExitCode(Command::SUCCESS); + $this->artisan(Names::MAKE, ['name' => 'TestMigration'])->assertExitCode(0); sleep(2); - $this->artisan(Names::MAKE, ['name' => 'TestMigration'])->assertExitCode(Command::SUCCESS); - $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::MAKE, ['name' => 'TestMigration'])->assertExitCode(0); + $this->artisan(Names::MIGRATE)->assertExitCode(0); $this->assertDatabaseCount($this->table, 2); $this->assertDatabaseMigrationHas($this->table, 'test_migration'); @@ -53,27 +53,27 @@ public function testOnce() $table = 'every_time'; - $this->artisan(Names::INSTALL)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::INSTALL)->assertExitCode(0); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, $table); - $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::MIGRATE)->assertExitCode(0); $this->assertDatabaseCount($table, 1); $this->assertDatabaseCount($this->table, 11); $this->assertDatabaseMigrationDoesntLike($this->table, $table); - $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::MIGRATE)->assertExitCode(0); $this->assertDatabaseCount($table, 2); $this->assertDatabaseCount($this->table, 11); $this->assertDatabaseMigrationDoesntLike($this->table, $table); - $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::MIGRATE)->assertExitCode(0); $this->assertDatabaseCount($table, 3); $this->assertDatabaseCount($this->table, 11); $this->assertDatabaseMigrationDoesntLike($this->table, $table); - $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::MIGRATE)->assertExitCode(0); $this->assertDatabaseCount($table, 4); $this->assertDatabaseCount($this->table, 11); @@ -86,12 +86,12 @@ public function testSuccessTransaction() $table = 'transactions'; - $this->artisan(Names::INSTALL)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::INSTALL)->assertExitCode(0); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, $table); - $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::MIGRATE)->assertExitCode(0); $this->assertDatabaseCount($table, 3); $this->assertDatabaseCount($this->table, 1); @@ -104,14 +104,14 @@ public function testFailedTransaction() $table = 'transactions'; - $this->artisan(Names::INSTALL)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::INSTALL)->assertExitCode(0); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, $table); try { - $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::MIGRATE)->assertExitCode(0); } catch (Exception $e) { $this->assertSame(Exception::class, get_class($e)); @@ -129,7 +129,7 @@ public function testSingleEnvironment() $table = 'environment'; - $this->artisan(Names::INSTALL)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::INSTALL)->assertExitCode(0); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); @@ -138,7 +138,7 @@ public function testSingleEnvironment() $this->assertDatabaseMigrationDoesntLike($this->table, 'run_on_testing'); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_except_production'); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_except_testing'); - $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::MIGRATE)->assertExitCode(0); $this->assertDatabaseCount($table, 5); $this->assertDatabaseCount($this->table, 11); @@ -147,7 +147,7 @@ public function testSingleEnvironment() $this->assertDatabaseMigrationHas($this->table, 'run_on_testing'); $this->assertDatabaseMigrationHas($this->table, 'run_except_production'); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_except_testing'); - $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::MIGRATE)->assertExitCode(0); $this->assertDatabaseCount($table, 5); $this->assertDatabaseCount($this->table, 11); @@ -164,7 +164,7 @@ public function testManyEnvironments() $table = 'environment'; - $this->artisan(Names::INSTALL)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::INSTALL)->assertExitCode(0); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); @@ -175,7 +175,7 @@ public function testManyEnvironments() $this->assertDatabaseMigrationDoesntLike($this->table, 'run_except_production'); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_except_testing'); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_except_many_environments'); - $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::MIGRATE)->assertExitCode(0); $this->assertDatabaseCount($table, 5); $this->assertDatabaseCount($this->table, 11); @@ -186,7 +186,7 @@ public function testManyEnvironments() $this->assertDatabaseMigrationHas($this->table, 'run_except_production'); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_except_testing'); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_except_many_environments'); - $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::MIGRATE)->assertExitCode(0); $this->assertDatabaseCount($table, 5); $this->assertDatabaseCount($this->table, 11); @@ -205,19 +205,19 @@ public function testAllow() $table = 'environment'; - $this->artisan(Names::INSTALL)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::INSTALL)->assertExitCode(0); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_allow'); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_disallow'); - $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::MIGRATE)->assertExitCode(0); $this->assertDatabaseCount($table, 5); $this->assertDatabaseCount($this->table, 11); $this->assertDatabaseMigrationHas($this->table, 'run_allow'); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_disallow'); - $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::MIGRATE)->assertExitCode(0); $this->assertDatabaseCount($table, 5); $this->assertDatabaseCount($this->table, 11); @@ -231,12 +231,12 @@ public function testUpSuccess() $table = 'success'; - $this->artisan(Names::INSTALL)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::INSTALL)->assertExitCode(0); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_success'); - $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::MIGRATE)->assertExitCode(0); $this->assertDatabaseCount($table, 2); $this->assertDatabaseCount($this->table, 11); @@ -249,12 +249,12 @@ public function testUpSuccessOnFailed() $table = 'success'; - $this->artisan(Names::INSTALL)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::INSTALL)->assertExitCode(0); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_success_on_failed'); - $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::MIGRATE)->assertExitCode(0); $this->assertDatabaseCount($table, 2); $this->assertDatabaseCount($this->table, 11); @@ -263,7 +263,7 @@ public function testUpSuccessOnFailed() try { $this->copySuccessFailureMethod(); - $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::MIGRATE)->assertExitCode(0); } catch (Throwable $e) { $this->assertInstanceOf(Exception::class, $e); @@ -284,12 +284,12 @@ public function testUpFailed() $table = 'failed'; - $this->artisan(Names::INSTALL)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::INSTALL)->assertExitCode(0); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_failed'); - $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::MIGRATE)->assertExitCode(0); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 11); @@ -302,12 +302,12 @@ public function testUpFailedOnException() $table = 'failed'; - $this->artisan(Names::INSTALL)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::INSTALL)->assertExitCode(0); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_failed_failure'); - $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::MIGRATE)->assertExitCode(0); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 11); @@ -316,7 +316,7 @@ public function testUpFailedOnException() try { $this->copyFailedMethod(); - $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::MIGRATE)->assertExitCode(0); } catch (Throwable $e) { $this->assertInstanceOf(Exception::class, $e); @@ -339,12 +339,12 @@ public function testPathAsFileWithExtension() $path = 'sub_path/2021_12_15_205804_baz.php'; - $this->artisan(Names::INSTALL)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::INSTALL)->assertExitCode(0); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'baz'); - $this->artisan(Names::MIGRATE, ['--path' => $path])->assertExitCode(Command::SUCCESS); + $this->artisan(Names::MIGRATE, ['--path' => $path])->assertExitCode(0); $this->assertDatabaseCount($table, 1); $this->assertDatabaseCount($this->table, 1); @@ -359,12 +359,12 @@ public function testPathAsFileWithoutExtension() $path = 'sub_path/2021_12_15_205804_baz'; - $this->artisan(Names::INSTALL)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::INSTALL)->assertExitCode(0); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'baz'); - $this->artisan(Names::MIGRATE, ['--path' => $path])->assertExitCode(Command::SUCCESS); + $this->artisan(Names::MIGRATE, ['--path' => $path])->assertExitCode(0); $this->assertDatabaseCount($table, 1); $this->assertDatabaseCount($this->table, 1); @@ -379,12 +379,12 @@ public function testPathAsDirectory() $path = 'sub_path'; - $this->artisan(Names::INSTALL)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::INSTALL)->assertExitCode(0); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'baz'); - $this->artisan(Names::MIGRATE, ['--path' => $path])->assertExitCode(Command::SUCCESS); + $this->artisan(Names::MIGRATE, ['--path' => $path])->assertExitCode(0); $this->assertDatabaseCount($table, 1); $this->assertDatabaseCount($this->table, 1); @@ -395,11 +395,11 @@ public function testMigrationNotFound() { $this->assertDatabaseDoesntTable($this->table); - $this->artisan(Names::INSTALL)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::INSTALL)->assertExitCode(0); $this->assertDatabaseHasTable($this->table); - $this->artisan(Names::STATUS)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::STATUS)->assertExitCode(0); } public function testDisabledBefore() @@ -408,19 +408,19 @@ public function testDisabledBefore() $table = 'before'; - $this->artisan(Names::INSTALL)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::INSTALL)->assertExitCode(0); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'test_before_enabled'); $this->assertDatabaseMigrationDoesntLike($this->table, 'test_before_disabled'); - $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::MIGRATE)->assertExitCode(0); $this->assertDatabaseCount($table, 2); $this->assertDatabaseCount($this->table, 11); $this->assertDatabaseMigrationHas($this->table, 'test_before_enabled'); $this->assertDatabaseMigrationHas($this->table, 'test_before_disabled'); - $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::MIGRATE)->assertExitCode(0); $this->assertDatabaseCount($table, 2); $this->assertDatabaseCount($this->table, 11); @@ -434,19 +434,19 @@ public function testEnabledBefore() $table = 'before'; - $this->artisan(Names::INSTALL)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::INSTALL)->assertExitCode(0); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'test_before_enabled'); $this->assertDatabaseMigrationDoesntLike($this->table, 'test_before_disabled'); - $this->artisan(Names::MIGRATE, ['--before' => true])->assertExitCode(Command::SUCCESS); + $this->artisan(Names::MIGRATE, ['--before' => true])->assertExitCode(0); $this->assertDatabaseCount($table, 1); $this->assertDatabaseCount($this->table, 10); $this->assertDatabaseMigrationHas($this->table, 'test_before_enabled'); $this->assertDatabaseMigrationDoesntLike($this->table, 'test_before_disabled'); - $this->artisan(Names::MIGRATE, ['--before' => true])->assertExitCode(Command::SUCCESS); + $this->artisan(Names::MIGRATE, ['--before' => true])->assertExitCode(0); $this->assertDatabaseCount($table, 1); $this->assertDatabaseCount($this->table, 10); @@ -460,31 +460,31 @@ public function testMixedBefore() $table = 'before'; - $this->artisan(Names::INSTALL)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::INSTALL)->assertExitCode(0); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'test_before_enabled'); $this->assertDatabaseMigrationDoesntLike($this->table, 'test_before_disabled'); - $this->artisan(Names::MIGRATE, ['--before' => true])->assertExitCode(Command::SUCCESS); + $this->artisan(Names::MIGRATE, ['--before' => true])->assertExitCode(0); $this->assertDatabaseCount($table, 1); $this->assertDatabaseCount($this->table, 10); $this->assertDatabaseMigrationHas($this->table, 'test_before_enabled'); $this->assertDatabaseMigrationDoesntLike($this->table, 'test_before_disabled'); - $this->artisan(Names::MIGRATE, ['--before' => true])->assertExitCode(Command::SUCCESS); + $this->artisan(Names::MIGRATE, ['--before' => true])->assertExitCode(0); $this->assertDatabaseCount($table, 1); $this->assertDatabaseCount($this->table, 10); $this->assertDatabaseMigrationHas($this->table, 'test_before_enabled'); $this->assertDatabaseMigrationDoesntLike($this->table, 'test_before_disabled'); - $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::MIGRATE)->assertExitCode(0); $this->assertDatabaseCount($table, 2); $this->assertDatabaseCount($this->table, 11); $this->assertDatabaseMigrationHas($this->table, 'test_before_enabled'); $this->assertDatabaseMigrationHas($this->table, 'test_before_disabled'); - $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::MIGRATE)->assertExitCode(0); $this->assertDatabaseCount($table, 2); $this->assertDatabaseCount($this->table, 11); diff --git a/tests/Commands/RefreshTest.php b/tests/Commands/RefreshTest.php index d661d593..63b16b37 100644 --- a/tests/Commands/RefreshTest.php +++ b/tests/Commands/RefreshTest.php @@ -12,18 +12,18 @@ public function testRefreshCommand() { $this->assertDatabaseDoesntTable($this->table); - $this->artisan(Names::INSTALL)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::INSTALL)->assertExitCode(0); $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 0); - $this->artisan(Names::MAKE, ['name' => 'Refresh'])->assertExitCode(Command::SUCCESS); - $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::MAKE, ['name' => 'Refresh'])->assertExitCode(0); + $this->artisan(Names::MIGRATE)->assertExitCode(0); $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 1); - $this->artisan(Names::REFRESH)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::REFRESH)->assertExitCode(0); $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 1); diff --git a/tests/Commands/ResetTest.php b/tests/Commands/ResetTest.php index 4b88b637..974f4b8c 100644 --- a/tests/Commands/ResetTest.php +++ b/tests/Commands/ResetTest.php @@ -12,19 +12,19 @@ public function testResetCommand() { $this->assertDatabaseDoesntTable($this->table); - $this->artisan(Names::INSTALL)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::INSTALL)->assertExitCode(0); $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 0); - $this->artisan(Names::MAKE, ['name' => 'Reset'])->assertExitCode(Command::SUCCESS); - $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::MAKE, ['name' => 'Reset'])->assertExitCode(0); + $this->artisan(Names::MIGRATE)->assertExitCode(0); $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 1); $this->assertDatabaseMigrationHas($this->table, 'reset'); - $this->artisan(Names::RESET)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::RESET)->assertExitCode(0); $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 0); diff --git a/tests/Commands/RollbackTest.php b/tests/Commands/RollbackTest.php index fa5638be..f06c1d10 100644 --- a/tests/Commands/RollbackTest.php +++ b/tests/Commands/RollbackTest.php @@ -15,15 +15,15 @@ public function testRollbackCommand() { $this->assertDatabaseDoesntTable($this->table); - $this->artisan(Names::INSTALL)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::INSTALL)->assertExitCode(0); $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 0); - $this->artisan(Names::MAKE, ['name' => 'RollbackOne'])->assertExitCode(Command::SUCCESS); - $this->artisan(Names::MAKE, ['name' => 'RollbackTwo'])->assertExitCode(Command::SUCCESS); + $this->artisan(Names::MAKE, ['name' => 'RollbackOne'])->assertExitCode(0); + $this->artisan(Names::MAKE, ['name' => 'RollbackTwo'])->assertExitCode(0); - $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::MIGRATE)->assertExitCode(0); $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 2); @@ -32,18 +32,18 @@ public function testRollbackCommand() $this->assertDatabaseMigrationHas($this->table, 'rollback_two'); $this->assertDatabaseMigrationDoesntLike($this->table, 'rollback_tree'); - $this->artisan(Names::ROLLBACK)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::ROLLBACK)->assertExitCode(0); $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 0); - $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::MIGRATE)->assertExitCode(0); $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 2); - $this->artisan(Names::MAKE, ['name' => 'RollbackTree'])->assertExitCode(Command::SUCCESS); - $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::MAKE, ['name' => 'RollbackTree'])->assertExitCode(0); + $this->artisan(Names::MIGRATE)->assertExitCode(0); $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 3); @@ -59,7 +59,7 @@ public function testEnvironment() $table = 'environment'; - $this->artisan(Names::INSTALL)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::INSTALL)->assertExitCode(0); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); @@ -67,7 +67,7 @@ public function testEnvironment() $this->assertDatabaseMigrationDoesntLike($this->table, 'run_on_production'); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_on_testing'); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_on_many_environments'); - $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::MIGRATE)->assertExitCode(0); $this->assertDatabaseCount($table, 5); $this->assertDatabaseCount($this->table, 11); @@ -75,9 +75,9 @@ public function testEnvironment() $this->assertDatabaseMigrationDoesntLike($this->table, 'run_on_production'); $this->assertDatabaseMigrationHas($this->table, 'run_on_testing'); $this->assertDatabaseMigrationHas($this->table, 'run_on_many_environments'); - $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::MIGRATE)->assertExitCode(0); - $this->artisan(Names::ROLLBACK)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::ROLLBACK)->assertExitCode(0); $this->assertDatabaseCount($table, 10); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_on_all'); @@ -92,18 +92,18 @@ public function testDownSuccess() $table = 'success'; - $this->artisan(Names::INSTALL)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::INSTALL)->assertExitCode(0); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_success'); - $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::MIGRATE)->assertExitCode(0); $this->assertDatabaseCount($table, 2); $this->assertDatabaseCount($this->table, 11); $this->assertDatabaseMigrationHas($this->table, 'run_success'); - $this->artisan(Names::ROLLBACK)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::ROLLBACK)->assertExitCode(0); $this->assertDatabaseCount($table, 4); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_success'); @@ -115,12 +115,12 @@ public function testDownSuccessOnFailed() $table = 'success'; - $this->artisan(Names::INSTALL)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::INSTALL)->assertExitCode(0); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_success_on_failed'); - $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::MIGRATE)->assertExitCode(0); $this->assertDatabaseCount($table, 2); $this->assertDatabaseCount($this->table, 11); @@ -135,7 +135,7 @@ public function testDownSuccessOnFailed() $this->assertDatabaseCount($this->table, 12); $this->assertDatabaseMigrationHas($this->table, 'run_success_on_failed'); - $this->artisan(Names::ROLLBACK)->assertExitCode(Command::FAILURE); + $this->artisan(Names::ROLLBACK)->assertExitCode(1); } catch (Throwable $e) { $this->assertInstanceOf(Exception::class, $e); @@ -156,18 +156,18 @@ public function testDownFailed() $table = 'failed'; - $this->artisan(Names::INSTALL)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::INSTALL)->assertExitCode(0); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_failed'); - $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::MIGRATE)->assertExitCode(0); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 11); $this->assertDatabaseMigrationHas($this->table, 'run_failed'); - $this->artisan(Names::ROLLBACK)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::ROLLBACK)->assertExitCode(0); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_failed'); @@ -179,12 +179,12 @@ public function testUpFailedOnException() $table = 'failed'; - $this->artisan(Names::INSTALL)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::INSTALL)->assertExitCode(0); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'run_failed_failure'); - $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::MIGRATE)->assertExitCode(0); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 11); @@ -195,7 +195,7 @@ public function testUpFailedOnException() $this->table()->insert(['action' => '2021_12_23_184029_run_failed_failure', 'batch' => 999]); - $this->artisan(Names::ROLLBACK)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::ROLLBACK)->assertExitCode(0); } catch (Throwable $e) { $this->assertInstanceOf(Exception::class, $e); @@ -216,21 +216,21 @@ public function testDisabledBefore() $table = 'before'; - $this->artisan(Names::INSTALL)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::INSTALL)->assertExitCode(0); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'test_before_enabled'); $this->assertDatabaseMigrationDoesntLike($this->table, 'test_before_disabled'); - $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::MIGRATE)->assertExitCode(0); $this->assertDatabaseCount($table, 2); $this->assertDatabaseCount($this->table, 11); $this->assertDatabaseMigrationHas($this->table, 'test_before_enabled'); $this->assertDatabaseMigrationHas($this->table, 'test_before_disabled'); - $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::MIGRATE)->assertExitCode(0); - $this->artisan(Names::ROLLBACK)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::ROLLBACK)->assertExitCode(0); $this->assertDatabaseCount($table, 4); $this->assertDatabaseCount($this->table, 0); @@ -244,21 +244,21 @@ public function testEnabledBefore() $table = 'before'; - $this->artisan(Names::INSTALL)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::INSTALL)->assertExitCode(0); $this->assertDatabaseCount($table, 0); $this->assertDatabaseCount($this->table, 0); $this->assertDatabaseMigrationDoesntLike($this->table, 'test_before_enabled'); $this->assertDatabaseMigrationDoesntLike($this->table, 'test_before_disabled'); - $this->artisan(Names::MIGRATE, ['--before' => true])->assertExitCode(Command::SUCCESS); + $this->artisan(Names::MIGRATE, ['--before' => true])->assertExitCode(0); $this->assertDatabaseCount($table, 1); $this->assertDatabaseCount($this->table, 10); $this->assertDatabaseMigrationHas($this->table, 'test_before_enabled'); $this->assertDatabaseMigrationDoesntLike($this->table, 'test_before_disabled'); - $this->artisan(Names::MIGRATE, ['--before' => true])->assertExitCode(Command::SUCCESS); + $this->artisan(Names::MIGRATE, ['--before' => true])->assertExitCode(0); - $this->artisan(Names::ROLLBACK)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::ROLLBACK)->assertExitCode(0); $this->assertDatabaseCount($table, 2); $this->assertDatabaseCount($this->table, 0); diff --git a/tests/Commands/StatusTest.php b/tests/Commands/StatusTest.php index eae94f5c..a426571d 100644 --- a/tests/Commands/StatusTest.php +++ b/tests/Commands/StatusTest.php @@ -12,7 +12,7 @@ public function testNotFound(): void { $this->assertDatabaseDoesntTable($this->table); - $this->artisan(Names::STATUS)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::STATUS)->assertExitCode(0); $this->assertDatabaseDoesntTable($this->table); } @@ -21,19 +21,19 @@ public function testStatusCommand() { $this->assertDatabaseDoesntTable($this->table); - $this->artisan(Names::INSTALL)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::INSTALL)->assertExitCode(0); $this->assertDatabaseHasTable($this->table); $this->assertDatabaseCount($this->table, 0); - $this->artisan(Names::STATUS)->expectsTable([], [])->assertExitCode(Command::SUCCESS); + $this->artisan(Names::STATUS)->expectsTable([], [])->assertExitCode(0); - $this->artisan(Names::MAKE, ['name' => 'Status'])->assertExitCode(Command::SUCCESS); - $this->artisan(Names::MIGRATE)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::MAKE, ['name' => 'Status'])->assertExitCode(0); + $this->artisan(Names::MIGRATE)->assertExitCode(0); $this->assertDatabaseCount($this->table, 1); - $this->artisan(Names::STATUS)->assertExitCode(Command::SUCCESS); + $this->artisan(Names::STATUS)->assertExitCode(0); $this->assertDatabaseMigrationHas($this->table, 'status'); } From 06dedc638538e827f68935bf6d44aa2300936c8e Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Tue, 11 Oct 2022 00:16:43 +0300 Subject: [PATCH 113/153] Drop Laravel 6.0 tests --- .github/workflows/laravel.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/laravel.yml b/.github/workflows/laravel.yml index 87b8bf98..fec0258f 100644 --- a/.github/workflows/laravel.yml +++ b/.github/workflows/laravel.yml @@ -9,7 +9,7 @@ jobs: fail-fast: true matrix: php: [ "8.0", "8.1", "8.2" ] - laravel: [ "6.0", "7.0", "8.0", "9.0", "10.0" ] + laravel: [ "7.0", "8.0", "9.0", "10.0" ] prefer: [ "stable", "lowest" ] exclude: - laravel: "6.0" From 40e2ba9c72c7f9919281a388af9b822369fdfbd3 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Tue, 11 Oct 2022 00:21:55 +0300 Subject: [PATCH 114/153] Bump min versions --- composer.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 46ed3612..1e98f6d0 100644 --- a/composer.json +++ b/composer.json @@ -49,10 +49,10 @@ "dragon-code/laravel-support": "^3.4", "dragon-code/simple-dto": "^2.5.1", "dragon-code/support": "^6.6", - "illuminate/console": "^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0", - "illuminate/container": "^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0", - "illuminate/database": "^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0", - "illuminate/support": "^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0", + "illuminate/console": "^6.20.42 || ^7.30.6 || ^8.75 || ^9.0 || ^10.0", + "illuminate/container": "^6.20.42 || ^7.30.6 || ^8.75 || ^9.0 || ^10.0", + "illuminate/database": "^6.20.42 || ^7.30.6 || ^8.75 || ^9.0 || ^10.0", + "illuminate/support": "^6.20.42 || ^7.30.6 || ^8.75 || ^9.0 || ^10.0", "symfony/console": "^4.0 || ^5.0 || ^6.0" }, "require-dev": { From 55ddf1745757bd2eb1c305e2e877aeb29dfc7031 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Tue, 11 Oct 2022 00:23:31 +0300 Subject: [PATCH 115/153] Remove lowest tests --- .github/workflows/laravel.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/laravel.yml b/.github/workflows/laravel.yml index fec0258f..e200ba70 100644 --- a/.github/workflows/laravel.yml +++ b/.github/workflows/laravel.yml @@ -10,7 +10,7 @@ jobs: matrix: php: [ "8.0", "8.1", "8.2" ] laravel: [ "7.0", "8.0", "9.0", "10.0" ] - prefer: [ "stable", "lowest" ] + prefer: [ "stable" ] exclude: - laravel: "6.0" php: "8.1" From 17f4e89d22548070210ce33b02815c106f27caa3 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Tue, 11 Oct 2022 00:26:54 +0300 Subject: [PATCH 116/153] Fixed code-style --- src/Events/ActionEnded.php | 2 +- src/Events/ActionStarted.php | 2 +- src/Processors/Fresh.php | 4 ++-- src/Processors/Processor.php | 18 +++++++++--------- src/Processors/Refresh.php | 4 ++-- src/Repositories/ActionRepository.php | 2 +- src/Services/Migrator.php | 8 ++++---- tests/Commands/FreshTest.php | 1 - tests/Commands/InstallTest.php | 1 - tests/Commands/MakeTest.php | 1 - tests/Commands/MigrateTest.php | 1 - tests/Commands/RefreshTest.php | 1 - tests/Commands/ResetTest.php | 1 - tests/Commands/RollbackTest.php | 1 - tests/Commands/StatusTest.php | 1 - 15 files changed, 20 insertions(+), 28 deletions(-) diff --git a/src/Events/ActionEnded.php b/src/Events/ActionEnded.php index 9ada724b..e52bdd3a 100644 --- a/src/Events/ActionEnded.php +++ b/src/Events/ActionEnded.php @@ -8,7 +8,7 @@ class ActionEnded extends BaseEvent { public function __construct( public string $method, - public bool $before + public bool $before ) { } } diff --git a/src/Events/ActionStarted.php b/src/Events/ActionStarted.php index 58b2ab1e..96bbe378 100644 --- a/src/Events/ActionStarted.php +++ b/src/Events/ActionStarted.php @@ -8,7 +8,7 @@ class ActionStarted extends BaseEvent { public function __construct( public string $method, - public bool $before + public bool $before ) { } } diff --git a/src/Processors/Fresh.php b/src/Processors/Fresh.php index 097af7a3..bba52c52 100644 --- a/src/Processors/Fresh.php +++ b/src/Processors/Fresh.php @@ -35,8 +35,8 @@ protected function migrate(): void { $this->runCommand(Names::MIGRATE, [ '--' . Options::CONNECTION => $this->options->connection, - '--' . Options::PATH => $this->options->path, - '--' . Options::REALPATH => $this->options->realpath, + '--' . Options::PATH => $this->options->path, + '--' . Options::REALPATH => $this->options->realpath, ]); } } diff --git a/src/Processors/Processor.php b/src/Processors/Processor.php index 2c7ac9fb..a4581412 100644 --- a/src/Processors/Processor.php +++ b/src/Processors/Processor.php @@ -26,16 +26,16 @@ 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 ) { $this->notification->setOutput($this->output); $this->repository->setConnection($this->options->connection); diff --git a/src/Processors/Refresh.php b/src/Processors/Refresh.php index ae7192c8..0ed70b15 100644 --- a/src/Processors/Refresh.php +++ b/src/Processors/Refresh.php @@ -12,8 +12,8 @@ class Refresh extends Processor public function handle(): void { $connection = $this->options->connection; - $path = $this->options->path; - $realPath = $this->options->realpath; + $path = $this->options->path; + $realPath = $this->options->realpath; $this->runReset($connection, $path, $realPath); $this->runMigrate($connection, $path, $realPath); diff --git a/src/Repositories/ActionRepository.php b/src/Repositories/ActionRepository.php index 5bb76319..4f03c627 100644 --- a/src/Repositories/ActionRepository.php +++ b/src/Repositories/ActionRepository.php @@ -19,7 +19,7 @@ class ActionRepository public function __construct( protected Resolver $resolver, - protected Config $config + protected Config $config ) { } diff --git a/src/Services/Migrator.php b/src/Services/Migrator.php index fb67afd3..6709439a 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 ) { } diff --git a/tests/Commands/FreshTest.php b/tests/Commands/FreshTest.php index 6cce11c5..e8251a13 100644 --- a/tests/Commands/FreshTest.php +++ b/tests/Commands/FreshTest.php @@ -4,7 +4,6 @@ namespace Tests\Commands; -use DragonCode\LaravelActions\Console\Command; use DragonCode\LaravelActions\Constants\Names; use Tests\TestCase; diff --git a/tests/Commands/InstallTest.php b/tests/Commands/InstallTest.php index f1c898e5..352332f4 100644 --- a/tests/Commands/InstallTest.php +++ b/tests/Commands/InstallTest.php @@ -2,7 +2,6 @@ namespace Tests\Commands; -use DragonCode\LaravelActions\Console\Command; use DragonCode\LaravelActions\Constants\Names; use Tests\TestCase; diff --git a/tests/Commands/MakeTest.php b/tests/Commands/MakeTest.php index e7e6445c..5ea5e4ce 100644 --- a/tests/Commands/MakeTest.php +++ b/tests/Commands/MakeTest.php @@ -2,7 +2,6 @@ namespace Tests\Commands; -use DragonCode\LaravelActions\Console\Command; use DragonCode\LaravelActions\Constants\Names; use Tests\TestCase; diff --git a/tests/Commands/MigrateTest.php b/tests/Commands/MigrateTest.php index ad5898b4..e1ad929b 100644 --- a/tests/Commands/MigrateTest.php +++ b/tests/Commands/MigrateTest.php @@ -2,7 +2,6 @@ namespace Tests\Commands; -use DragonCode\LaravelActions\Console\Command; use DragonCode\LaravelActions\Constants\Names; use Exception; use Illuminate\Support\Str; diff --git a/tests/Commands/RefreshTest.php b/tests/Commands/RefreshTest.php index 63b16b37..f6ea10ff 100644 --- a/tests/Commands/RefreshTest.php +++ b/tests/Commands/RefreshTest.php @@ -2,7 +2,6 @@ namespace Tests\Commands; -use DragonCode\LaravelActions\Console\Command; use DragonCode\LaravelActions\Constants\Names; use Tests\TestCase; diff --git a/tests/Commands/ResetTest.php b/tests/Commands/ResetTest.php index 974f4b8c..5be868cb 100644 --- a/tests/Commands/ResetTest.php +++ b/tests/Commands/ResetTest.php @@ -2,7 +2,6 @@ namespace Tests\Commands; -use DragonCode\LaravelActions\Console\Command; use DragonCode\LaravelActions\Constants\Names; use Tests\TestCase; diff --git a/tests/Commands/RollbackTest.php b/tests/Commands/RollbackTest.php index f06c1d10..6255192b 100644 --- a/tests/Commands/RollbackTest.php +++ b/tests/Commands/RollbackTest.php @@ -2,7 +2,6 @@ namespace Tests\Commands; -use DragonCode\LaravelActions\Console\Command; use DragonCode\LaravelActions\Constants\Names; use Exception; use Illuminate\Support\Str; diff --git a/tests/Commands/StatusTest.php b/tests/Commands/StatusTest.php index a426571d..28c8fae1 100644 --- a/tests/Commands/StatusTest.php +++ b/tests/Commands/StatusTest.php @@ -2,7 +2,6 @@ namespace Tests\Commands; -use DragonCode\LaravelActions\Console\Command; use DragonCode\LaravelActions\Constants\Names; use Tests\TestCase; From 3529203771f087e06f9b0b632fea7961fc2ec236 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Tue, 11 Oct 2022 00:30:39 +0300 Subject: [PATCH 117/153] Revert lowest tests --- .github/workflows/laravel.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/laravel.yml b/.github/workflows/laravel.yml index e200ba70..fec0258f 100644 --- a/.github/workflows/laravel.yml +++ b/.github/workflows/laravel.yml @@ -10,7 +10,7 @@ jobs: matrix: php: [ "8.0", "8.1", "8.2" ] laravel: [ "7.0", "8.0", "9.0", "10.0" ] - prefer: [ "stable" ] + prefer: [ "stable", "lowest" ] exclude: - laravel: "6.0" php: "8.1" From 01e5b3032272c35198fad6649a552e70b7020c65 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Tue, 11 Oct 2022 00:37:06 +0300 Subject: [PATCH 118/153] Bump `orchestra/testbench` --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 1e98f6d0..6fb88fe2 100644 --- a/composer.json +++ b/composer.json @@ -57,7 +57,7 @@ }, "require-dev": { "mockery/mockery": "^1.3.1", - "orchestra/testbench": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0", + "orchestra/testbench": "^4.18 || ^5.20 || ^6.25 || ^7.9 || ^8.0", "phpunit/phpunit": "^9.5", "ramsey/uuid": "^3.7 || ^4.0" }, From 3b2f4b1914471a8ffea8240e6df2741b2a57c7ea Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Tue, 11 Oct 2022 00:39:12 +0300 Subject: [PATCH 119/153] Error: Undefined constant DragonCode\LaravelActions\Console\Command::SUCCESS --- src/Console/Command.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Console/Command.php b/src/Console/Command.php index 22709cb1..a08a83bc 100644 --- a/src/Console/Command.php +++ b/src/Console/Command.php @@ -24,10 +24,10 @@ public function handle(): int $this->resolveProcessor()->handle(); $this->forgetProcessor(); - return self::SUCCESS; + return 0; } - return self::FAILURE; + return 1; } protected function resolveProcessor(): Processor From 2b7775ce75548f3423ec034abf4f804a66a75a17 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Tue, 11 Oct 2022 00:43:38 +0300 Subject: [PATCH 120/153] Bump `symfony/console` --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 6fb88fe2..4532bd04 100644 --- a/composer.json +++ b/composer.json @@ -53,7 +53,7 @@ "illuminate/container": "^6.20.42 || ^7.30.6 || ^8.75 || ^9.0 || ^10.0", "illuminate/database": "^6.20.42 || ^7.30.6 || ^8.75 || ^9.0 || ^10.0", "illuminate/support": "^6.20.42 || ^7.30.6 || ^8.75 || ^9.0 || ^10.0", - "symfony/console": "^4.0 || ^5.0 || ^6.0" + "symfony/console": "^4.0 || ^5.4 || ^6.0" }, "require-dev": { "mockery/mockery": "^1.3.1", From d610b37abe70e5defa19ff96a71d3982f587572a Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Tue, 11 Oct 2022 00:44:14 +0300 Subject: [PATCH 121/153] Bump `symfony/console` --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 4532bd04..4a4b03a7 100644 --- a/composer.json +++ b/composer.json @@ -53,7 +53,7 @@ "illuminate/container": "^6.20.42 || ^7.30.6 || ^8.75 || ^9.0 || ^10.0", "illuminate/database": "^6.20.42 || ^7.30.6 || ^8.75 || ^9.0 || ^10.0", "illuminate/support": "^6.20.42 || ^7.30.6 || ^8.75 || ^9.0 || ^10.0", - "symfony/console": "^4.0 || ^5.4 || ^6.0" + "symfony/console": "^4.0 || ^5.2 || ^6.0" }, "require-dev": { "mockery/mockery": "^1.3.1", From 457a463cd95a3a035dd93edbf5252d81a3423e43 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Tue, 11 Oct 2022 00:44:55 +0300 Subject: [PATCH 122/153] Bump `symfony/console` --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 4a4b03a7..8c7c932f 100644 --- a/composer.json +++ b/composer.json @@ -53,7 +53,7 @@ "illuminate/container": "^6.20.42 || ^7.30.6 || ^8.75 || ^9.0 || ^10.0", "illuminate/database": "^6.20.42 || ^7.30.6 || ^8.75 || ^9.0 || ^10.0", "illuminate/support": "^6.20.42 || ^7.30.6 || ^8.75 || ^9.0 || ^10.0", - "symfony/console": "^4.0 || ^5.2 || ^6.0" + "symfony/console": "^4.0 || ^5.3 || ^6.0" }, "require-dev": { "mockery/mockery": "^1.3.1", From b6c4ced594cca7c9de88dc8f5e18c3588ba95a6d Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Tue, 11 Oct 2022 00:47:49 +0300 Subject: [PATCH 123/153] `nesbot/carbon` --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 8c7c932f..1c73414f 100644 --- a/composer.json +++ b/composer.json @@ -59,7 +59,8 @@ "mockery/mockery": "^1.3.1", "orchestra/testbench": "^4.18 || ^5.20 || ^6.25 || ^7.9 || ^8.0", "phpunit/phpunit": "^9.5", - "ramsey/uuid": "^3.7 || ^4.0" + "ramsey/uuid": "^3.7 || ^4.0", + "nesbot/carbon": "^2.40" }, "conflict": { "andrey-helldar/laravel-actions": "*", From a0045c78eac7ad4be3354f9f2b576c77b484df18 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Tue, 11 Oct 2022 00:48:55 +0300 Subject: [PATCH 124/153] `nesbot/carbon` --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 1c73414f..dc0c4b6c 100644 --- a/composer.json +++ b/composer.json @@ -60,7 +60,7 @@ "orchestra/testbench": "^4.18 || ^5.20 || ^6.25 || ^7.9 || ^8.0", "phpunit/phpunit": "^9.5", "ramsey/uuid": "^3.7 || ^4.0", - "nesbot/carbon": "^2.40" + "nesbot/carbon": "^2.50" }, "conflict": { "andrey-helldar/laravel-actions": "*", From 62c83bcb53759754894b0df5cc1b76f9e49d9d2e Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Tue, 11 Oct 2022 00:49:50 +0300 Subject: [PATCH 125/153] `nesbot/carbon` --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index dc0c4b6c..84b71a29 100644 --- a/composer.json +++ b/composer.json @@ -60,7 +60,7 @@ "orchestra/testbench": "^4.18 || ^5.20 || ^6.25 || ^7.9 || ^8.0", "phpunit/phpunit": "^9.5", "ramsey/uuid": "^3.7 || ^4.0", - "nesbot/carbon": "^2.50" + "nesbot/carbon": "^2.60" }, "conflict": { "andrey-helldar/laravel-actions": "*", From 9ccfd1dc81085af085b6b2483834befa7750b815 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Tue, 11 Oct 2022 00:51:00 +0300 Subject: [PATCH 126/153] `nesbot/carbon` --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 84b71a29..5ed73b7b 100644 --- a/composer.json +++ b/composer.json @@ -60,7 +60,7 @@ "orchestra/testbench": "^4.18 || ^5.20 || ^6.25 || ^7.9 || ^8.0", "phpunit/phpunit": "^9.5", "ramsey/uuid": "^3.7 || ^4.0", - "nesbot/carbon": "^2.60" + "nesbot/carbon": "^2.61" }, "conflict": { "andrey-helldar/laravel-actions": "*", From a2a100035aa80bb9e7399ada5026ba9cecdd7ca8 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Tue, 11 Oct 2022 00:52:09 +0300 Subject: [PATCH 127/153] `nesbot/carbon` --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 5ed73b7b..aac0a0bf 100644 --- a/composer.json +++ b/composer.json @@ -60,7 +60,7 @@ "orchestra/testbench": "^4.18 || ^5.20 || ^6.25 || ^7.9 || ^8.0", "phpunit/phpunit": "^9.5", "ramsey/uuid": "^3.7 || ^4.0", - "nesbot/carbon": "^2.61" + "nesbot/carbon": "^2.62" }, "conflict": { "andrey-helldar/laravel-actions": "*", From f5e44f8b0e4545868804db396d07906434dec461 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Tue, 11 Oct 2022 00:53:08 +0300 Subject: [PATCH 128/153] `nesbot/carbon` --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index aac0a0bf..47bfda97 100644 --- a/composer.json +++ b/composer.json @@ -60,7 +60,7 @@ "orchestra/testbench": "^4.18 || ^5.20 || ^6.25 || ^7.9 || ^8.0", "phpunit/phpunit": "^9.5", "ramsey/uuid": "^3.7 || ^4.0", - "nesbot/carbon": "^2.62" + "nesbot/carbon": "^2.62.1" }, "conflict": { "andrey-helldar/laravel-actions": "*", From 2503d3deaf973f448158e6f961f91d78992bae76 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Tue, 11 Oct 2022 00:54:32 +0300 Subject: [PATCH 129/153] Revert Laravel 6 --- .github/workflows/laravel.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/laravel.yml b/.github/workflows/laravel.yml index fec0258f..87b8bf98 100644 --- a/.github/workflows/laravel.yml +++ b/.github/workflows/laravel.yml @@ -9,7 +9,7 @@ jobs: fail-fast: true matrix: php: [ "8.0", "8.1", "8.2" ] - laravel: [ "7.0", "8.0", "9.0", "10.0" ] + laravel: [ "6.0", "7.0", "8.0", "9.0", "10.0" ] prefer: [ "stable", "lowest" ] exclude: - laravel: "6.0" From d2aaf5870a24072f2e68ff7c663ff21648331321 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Tue, 11 Oct 2022 00:56:15 +0300 Subject: [PATCH 130/153] Drop Laravel 6 --- .github/workflows/laravel.yml | 8 +------- composer.json | 16 ++++++++-------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/.github/workflows/laravel.yml b/.github/workflows/laravel.yml index 87b8bf98..446a1da0 100644 --- a/.github/workflows/laravel.yml +++ b/.github/workflows/laravel.yml @@ -9,15 +9,9 @@ jobs: fail-fast: true matrix: php: [ "8.0", "8.1", "8.2" ] - laravel: [ "6.0", "7.0", "8.0", "9.0", "10.0" ] + laravel: [ "7.0", "8.0", "9.0", "10.0" ] prefer: [ "stable", "lowest" ] exclude: - - laravel: "6.0" - php: "8.1" - - - laravel: "6.0" - php: "8.2" - - laravel: "7.0" php: "8.1" diff --git a/composer.json b/composer.json index 47bfda97..af18ace7 100644 --- a/composer.json +++ b/composer.json @@ -49,18 +49,18 @@ "dragon-code/laravel-support": "^3.4", "dragon-code/simple-dto": "^2.5.1", "dragon-code/support": "^6.6", - "illuminate/console": "^6.20.42 || ^7.30.6 || ^8.75 || ^9.0 || ^10.0", - "illuminate/container": "^6.20.42 || ^7.30.6 || ^8.75 || ^9.0 || ^10.0", - "illuminate/database": "^6.20.42 || ^7.30.6 || ^8.75 || ^9.0 || ^10.0", - "illuminate/support": "^6.20.42 || ^7.30.6 || ^8.75 || ^9.0 || ^10.0", - "symfony/console": "^4.0 || ^5.3 || ^6.0" + "illuminate/console": "^7.30.6 || ^8.75 || ^9.0 || ^10.0", + "illuminate/container": "^7.30.6 || ^8.75 || ^9.0 || ^10.0", + "illuminate/database": "^7.30.6 || ^8.75 || ^9.0 || ^10.0", + "illuminate/support": "^7.30.6 || ^8.75 || ^9.0 || ^10.0", + "symfony/console": "^5.3 || ^6.0" }, "require-dev": { "mockery/mockery": "^1.3.1", - "orchestra/testbench": "^4.18 || ^5.20 || ^6.25 || ^7.9 || ^8.0", + "nesbot/carbon": "^2.62.1", + "orchestra/testbench": "^5.20 || ^6.25 || ^7.9 || ^8.0", "phpunit/phpunit": "^9.5", - "ramsey/uuid": "^3.7 || ^4.0", - "nesbot/carbon": "^2.62.1" + "ramsey/uuid": "^3.7 || ^4.0" }, "conflict": { "andrey-helldar/laravel-actions": "*", From b9cccf8289fefe8a3ab0eaa8cbe5dad1dc02f59f Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Tue, 11 Oct 2022 18:08:01 +0300 Subject: [PATCH 131/153] Update .gitattributes --- .gitattributes | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.gitattributes b/.gitattributes index 949650b4..3a55538c 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,13 +1,11 @@ * text=auto .github/ export-ignore +docs/ export-ignore tests/ export-ignore -.codecov.yml export-ignore .editorconfig export-ignore .gitattributes export-ignore .gitignore export-ignore -.scrutinizer.yml export-ignore -.styleci.yml export-ignore phpunit.xml export-ignore From af45b8e49ffcb5271f141d60cb957b3976092bd3 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Tue, 11 Oct 2022 18:24:13 +0300 Subject: [PATCH 132/153] Prepared docs --- docs/getting-started/helpers/artisan.md | 1 + docs/getting-started/helpers/events.md | 1 + .../helpers/execution-statuses.md | 1 + docs/getting-started/how-to-use/creating.md | 1 + docs/getting-started/how-to-use/execution.md | 1 + docs/getting-started/how-to-use/freshing.md | 1 + docs/getting-started/how-to-use/refreshing.md | 1 + docs/getting-started/how-to-use/resetting.md | 0 docs/getting-started/how-to-use/rollback.md | 0 docs/getting-started/how-to-use/status.md | 0 docs/getting-started/installation.md | 0 docs/index.md | 51 +++++++++++++++++++ docs/prologue/upgrade.md | 1 + src/Constants/Names.php | 2 +- 14 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 docs/getting-started/helpers/artisan.md create mode 100644 docs/getting-started/helpers/events.md create mode 100644 docs/getting-started/helpers/execution-statuses.md create mode 100644 docs/getting-started/how-to-use/creating.md create mode 100644 docs/getting-started/how-to-use/execution.md create mode 100644 docs/getting-started/how-to-use/freshing.md create mode 100644 docs/getting-started/how-to-use/refreshing.md create mode 100644 docs/getting-started/how-to-use/resetting.md create mode 100644 docs/getting-started/how-to-use/rollback.md create mode 100644 docs/getting-started/how-to-use/status.md create mode 100644 docs/getting-started/installation.md create mode 100644 docs/index.md create mode 100644 docs/prologue/upgrade.md diff --git a/docs/getting-started/helpers/artisan.md b/docs/getting-started/helpers/artisan.md new file mode 100644 index 00000000..a32e0143 --- /dev/null +++ b/docs/getting-started/helpers/artisan.md @@ -0,0 +1 @@ +# Artisan Command diff --git a/docs/getting-started/helpers/events.md b/docs/getting-started/helpers/events.md new file mode 100644 index 00000000..1f187df0 --- /dev/null +++ b/docs/getting-started/helpers/events.md @@ -0,0 +1 @@ +# Events diff --git a/docs/getting-started/helpers/execution-statuses.md b/docs/getting-started/helpers/execution-statuses.md new file mode 100644 index 00000000..3791d06e --- /dev/null +++ b/docs/getting-started/helpers/execution-statuses.md @@ -0,0 +1 @@ +# Execution Status diff --git a/docs/getting-started/how-to-use/creating.md b/docs/getting-started/how-to-use/creating.md new file mode 100644 index 00000000..ba33663c --- /dev/null +++ b/docs/getting-started/how-to-use/creating.md @@ -0,0 +1 @@ +# Creating Action diff --git a/docs/getting-started/how-to-use/execution.md b/docs/getting-started/how-to-use/execution.md new file mode 100644 index 00000000..634d96c9 --- /dev/null +++ b/docs/getting-started/how-to-use/execution.md @@ -0,0 +1 @@ +# Execution Actions diff --git a/docs/getting-started/how-to-use/freshing.md b/docs/getting-started/how-to-use/freshing.md new file mode 100644 index 00000000..7dba09a4 --- /dev/null +++ b/docs/getting-started/how-to-use/freshing.md @@ -0,0 +1 @@ +# Drop All Actions & Run Actions diff --git a/docs/getting-started/how-to-use/refreshing.md b/docs/getting-started/how-to-use/refreshing.md new file mode 100644 index 00000000..0b9bcb0a --- /dev/null +++ b/docs/getting-started/how-to-use/refreshing.md @@ -0,0 +1 @@ +# Refresh diff --git a/docs/getting-started/how-to-use/resetting.md b/docs/getting-started/how-to-use/resetting.md new file mode 100644 index 00000000..e69de29b diff --git a/docs/getting-started/how-to-use/rollback.md b/docs/getting-started/how-to-use/rollback.md new file mode 100644 index 00000000..e69de29b diff --git a/docs/getting-started/how-to-use/status.md b/docs/getting-started/how-to-use/status.md new file mode 100644 index 00000000..e69de29b diff --git a/docs/getting-started/installation.md b/docs/getting-started/installation.md new file mode 100644 index 00000000..e69de29b diff --git a/docs/index.md b/docs/index.md new file mode 100644 index 00000000..3434fef5 --- /dev/null +++ b/docs/index.md @@ -0,0 +1,51 @@ +# Laravel Migration Actions + +![the dragon code migration actions](https://preview.dragon-code.pro/the-dragon-code/migration-actions.svg?brand=laravel) + +[![Stable Version][badge_stable]][link_packagist] +[![Unstable Version][badge_unstable]][link_packagist] +[![Total Downloads][badge_downloads]][link_packagist] +[![Github Workflow Status][badge_build]][link_build] +[![License][badge_license]][link_license] + +> Actions are like version control for your actions process, allowing your team to modify and share the application's actionable schema. If you have ever had to tell a teammate +> to manually perform any action on a production server, you've come across an issue that actions solves. + +## Table of contents + +* Prologue + * [Upgrade Guide](prologue/upgrade.md) +* Getting Started + * [Installation](getting-started/installation.md) + * How to use + * [Creating](getting-started/how-to-use/creating.md) + * [Execution](getting-started/how-to-use/execution.md) + * [Rolling Back](getting-started/how-to-use/rollback.md) + * [Rolling Back & Actions Using A Single Command](getting-started/how-to-use/resetting.md) + * [Drop All Actions & Run Actions](getting-started/how-to-use/freshing.md) + * [Status](getting-started/how-to-use/status.md) + * Helpers + * [Execution Status](getting-started/helpers/execution-statuses.md) + * [Events](getting-started/helpers/events.md) + * [Artisan Command](getting-started/helpers/artisan.md) + +## License + +This package is licensed under the [MIT License](../LICENSE). + + +[badge_build]: https://img.shields.io/github/workflow/status/TheDragonCode/laravel-migration-actions/phpunit?style=flat-square + +[badge_downloads]: https://img.shields.io/packagist/dt/dragon-code/laravel-migration-actions.svg?style=flat-square + +[badge_license]: https://img.shields.io/packagist/l/dragon-code/laravel-migration-actions.svg?style=flat-square + +[badge_stable]: https://img.shields.io/github/v/release/TheDragonCode/laravel-migration-actions?label=stable&style=flat-square + +[badge_unstable]: https://img.shields.io/badge/unstable-dev--main-orange?style=flat-square + +[link_build]: https://github.com/TheDragonCode/laravel-migration-actions/actions + +[link_license]: ../LICENSE + +[link_packagist]: https://packagist.org/packages/dragon-code/laravel-migration-actions diff --git a/docs/prologue/upgrade.md b/docs/prologue/upgrade.md new file mode 100644 index 00000000..40e1497a --- /dev/null +++ b/docs/prologue/upgrade.md @@ -0,0 +1 @@ +# Upgrade Guide diff --git a/src/Constants/Names.php b/src/Constants/Names.php index bd027cb7..966cc1be 100644 --- a/src/Constants/Names.php +++ b/src/Constants/Names.php @@ -16,7 +16,7 @@ class Names public const RESET = 'migrate:actions:reset'; - public const ROLLBACK = 'migrate:actions:rollback'; + public const ROLLBACK = 'migrate:actions:rollback.md'; public const STATUS = 'migrate:actions:status'; From 98071b64f47c4bfd4335bcea99a0ed59c53769d6 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Tue, 11 Oct 2022 22:46:08 +0300 Subject: [PATCH 133/153] Added installation page --- docs/getting-started/installation.md | 45 ++++++++++++++++++++++++++++ src/ServiceProvider.php | 2 +- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/docs/getting-started/installation.md b/docs/getting-started/installation.md index e69de29b..f2e14d55 100644 --- a/docs/getting-started/installation.md +++ b/docs/getting-started/installation.md @@ -0,0 +1,45 @@ +# Installation + +To get the latest version of Laravel Actions, simply require the project using [Composer](https://getcomposer.org): + +```bash +composer require dragon-code/laravel-migration-actions +``` + +Or manually update `require` block of `composer.json` and run `composer update` console command. + +```json +{ + "require": { + "dragon-code/laravel-migration-actions": "^3.0" + } +} +``` + +## Laravel Framework + +Run the `php artisan vendor:publish --provider="DragonCode\LaravelActions\ServiceProvider"` console command for the config file publishing. + +## Lumen Framework + +This package is focused on Laravel development, but it can also be used in Lumen with some workarounds. Because Lumen works a little different, as it is like a barebone version of +Laravel and the main configuration parameters are instead located in `bootstrap/app.php`, some alterations must be made. + +You can install `Laravel Actions` in `app/Providers/AppServiceProvider.php`, and uncommenting this line that registers the App Service Providers so it can properly load. + +```php +// $app->register(App\Providers\AppServiceProvider::class); +``` + +If you are not using that line, that is usually handy to manage gracefully multiple Lumen installations, you will have to add this line of code under +the `Register Service Providers` section of your `bootstrap/app.php`. + +```php +$app->register(\DragonCode\LaravelActions\ServiceProvider::class); +``` + +Next, you can copy the config file: + +```bash +cp vendor/dragon-code/laravel-migration-actions/config/actions.php config/actions.php +``` diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index 0b2d5755..49c9fad5 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -67,7 +67,7 @@ protected function publishConfig(): void { $this->publishes([ __DIR__ . '/../config/actions.php' => $this->app->configPath('actions.php'), - ]); + ], 'config'); } protected function registerConfig(): void From 3052a34015a2228121c410383f102d3be895687a Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Tue, 11 Oct 2022 23:05:30 +0300 Subject: [PATCH 134/153] Added nested path --- docs/getting-started/how-to-use/creating.md | 60 ++++++++++++++++- src/Values/Options.php | 12 +++- tests/Commands/MakeTest.php | 72 +++++++++++++++++++++ 3 files changed, 142 insertions(+), 2 deletions(-) diff --git a/docs/getting-started/how-to-use/creating.md b/docs/getting-started/how-to-use/creating.md index ba33663c..177d0c87 100644 --- a/docs/getting-started/how-to-use/creating.md +++ b/docs/getting-started/how-to-use/creating.md @@ -1 +1,59 @@ -# Creating Action +# Creating Actions + +To create an action use the `make:migration:action` artisan command: + +```bash +php artisan make:migration:action some_name +``` + +The new action's file will be placed in your `actions` directory in the base path of your app. + +Each action file name contains a timestamp, which allows Laravel to determine the order of the actions. + + +## Automatically Generate A File Name + +If you do not specify the "name" attribute, then the file name will be generated automatically according to the rule: + +> git branch name ?: 'auto' + +```bash +php artisan make:migration:action + +### When the git repository is found (`base_path('.git')` directory is exists). +### For example, HEAD branch name is 'qwerty'. +# 2022_10_11_225116_qwerty.php +# 2022_10_11_225118_qwerty.php +# 2022_10_11_225227_qwerty.php + +### When the git repository is not found (`base_path('.git')` directory doesn't exists). +### For example, HEAD branch name is 'qwerty'. +# 2022_10_11_225116_auto.php +# 2022_10_11_225118_auto.php +# 2022_10_11_225227_auto.php +``` + +## Nested Files + +Since version `3.0` you can use nested paths to create actions: + +```bash +php artisan make:migration:action Foo/Bar/QweRty +php artisan make:migration:action Foo/Bar/QweRty.php + +php artisan make:migration:action Foo\Bar\QweRty +php artisan make:migration:action Foo\Bar\QweRty.php + +php artisan make:migration:action foo\bar\QweRty +php artisan make:migration:action foo\bar\QweRty.php +``` + +All of these commands will create a file called `actions/foo/bar/Y_m_d_His_qwe_rty.php`. + +For example: + +```bash +php artisan make:migration:action foo\bar\QweRty + +# actions/foo/bar/2022_10_11_225734_qwe_rty.php +``` diff --git a/src/Values/Options.php b/src/Values/Options.php index a8bb4480..560e3ed4 100644 --- a/src/Values/Options.php +++ b/src/Values/Options.php @@ -25,6 +25,16 @@ class Options extends DataTransferObject protected function castName(?string $value): ?string { - return empty($value) ? null : Str::snake($value); + if (empty($value)) { + return null; + } + + return Str::of($value) + ->replace('\\', '/') + ->replace('.php', '') + ->explode('/') + ->map(fn (string $path) => Str::snake($path)) + ->implode(DIRECTORY_SEPARATOR) + ->toString(); } } diff --git a/tests/Commands/MakeTest.php b/tests/Commands/MakeTest.php index 5ea5e4ce..d996bd97 100644 --- a/tests/Commands/MakeTest.php +++ b/tests/Commands/MakeTest.php @@ -35,4 +35,76 @@ public function testAutoName() $this->assertFileExists($path); } + + public function testNestedRightSlashWithoutExtension() + { + $name = 'Foo/bar/QweRty'; + + $path = $this->getActionsPath() . '/foo/bar/' . date('Y_m_d_His') . '_qwe_rty.php'; + + $this->assertFileDoesNotExist($path); + + $this->artisan(Names::MAKE, compact('name'))->assertExitCode(0); + + $this->assertFileExists($path); + + $this->assertEquals( + file_get_contents(__DIR__ . '/../fixtures/app/stubs/make_example.stub'), + file_get_contents($path) + ); + } + + public function testNestedRightSlashWithExtension() + { + $name = 'Foo/bar/QweRty.php'; + + $path = $this->getActionsPath() . '/foo/bar/' . date('Y_m_d_His') . '_qwe_rty.php'; + + $this->assertFileDoesNotExist($path); + + $this->artisan(Names::MAKE, compact('name'))->assertExitCode(0); + + $this->assertFileExists($path); + + $this->assertEquals( + file_get_contents(__DIR__ . '/../fixtures/app/stubs/make_example.stub'), + file_get_contents($path) + ); + } + + public function testNestedLeftSlashWithoutExtension() + { + $name = 'Foo\\bar\\QweRty'; + + $path = $this->getActionsPath() . '/foo/bar/' . date('Y_m_d_His') . '_qwe_rty.php'; + + $this->assertFileDoesNotExist($path); + + $this->artisan(Names::MAKE, compact('name'))->assertExitCode(0); + + $this->assertFileExists($path); + + $this->assertEquals( + file_get_contents(__DIR__ . '/../fixtures/app/stubs/make_example.stub'), + file_get_contents($path) + ); + } + + public function testNestedLeftSlashWithExtension() + { + $name = 'Foo\\bar\\QweRty.php'; + + $path = $this->getActionsPath() . '/foo/bar/' . date('Y_m_d_His') . '_qwe_rty.php'; + + $this->assertFileDoesNotExist($path); + + $this->artisan(Names::MAKE, compact('name'))->assertExitCode(0); + + $this->assertFileExists($path); + + $this->assertEquals( + file_get_contents(__DIR__ . '/../fixtures/app/stubs/make_example.stub'), + file_get_contents($path) + ); + } } From 2e38fe6bb6f1f6d76b972ed018fa28ebad32c68a Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Tue, 11 Oct 2022 23:06:33 +0300 Subject: [PATCH 135/153] Update creating.md --- docs/getting-started/how-to-use/creating.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/getting-started/how-to-use/creating.md b/docs/getting-started/how-to-use/creating.md index 177d0c87..187a57d1 100644 --- a/docs/getting-started/how-to-use/creating.md +++ b/docs/getting-started/how-to-use/creating.md @@ -54,6 +54,14 @@ For example: ```bash php artisan make:migration:action foo\bar\QweRty +# actions/foo/bar/2022_10_11_225734_qwe_rty.php + +php artisan make:migration:action foo\bar\QweRty.php +# actions/foo/bar/2022_10_11_225734_qwe_rty.php + +php artisan make:migration:action foo/bar/QweRty +# actions/foo/bar/2022_10_11_225734_qwe_rty.php +php artisan make:migration:action foo/bar/QweRty.php # actions/foo/bar/2022_10_11_225734_qwe_rty.php ``` From 747a3920182636e060feee2feccdc819c0da0d11 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Wed, 12 Oct 2022 00:13:44 +0300 Subject: [PATCH 136/153] Fixed invokable calling --- README.md | 50 +++++++------- docs/getting-started/how-to-use/creating.md | 68 +++++++++++++++++++ src/Action.php | 14 ---- src/Services/Migrator.php | 2 +- tests/Commands/MigrateTest.php | 28 ++++++++ tests/Commands/RollbackTest.php | 39 +++++++++++ tests/Concerns/AssertDatabase.php | 8 +-- tests/Concerns/Files.php | 8 +++ tests/Concerns/Some.php | 13 ++++ .../app/di/2022_10_11_234251_invoke.php | 21 ++++++ .../app/di/2022_10_11_234251_invoke_down.php | 28 ++++++++ .../app/di/2022_10_11_234312_up_down.php | 28 ++++++++ 12 files changed, 264 insertions(+), 43 deletions(-) create mode 100644 tests/Concerns/Some.php create mode 100644 tests/fixtures/app/di/2022_10_11_234251_invoke.php create mode 100644 tests/fixtures/app/di/2022_10_11_234251_invoke_down.php create mode 100644 tests/fixtures/app/di/2022_10_11_234312_up_down.php diff --git a/README.md b/README.md index e6e12478..2dea61bb 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ [![Github Workflow Status][badge_build]][link_build] [![License][badge_license]][link_license] -> Actions are like version control for your migration process, allowing your team to modify and share the application's actionable schema. If you have ever had to tell a teammate +> Actions are like version control for your migration process, allowing your team to modify and share the application's Action schema. If you have ever had to tell a teammate > to manually perform any action on a producton server, you've come across an issue that actions solves. ## Installation @@ -132,7 +132,7 @@ php artisan make:migration:action ```php /* 2022_01_28_184116_branch_2x_1643384476.php */ -class Branch2x1643384476 extends Actionable { } +class Branch2x1643384476 extends Action { } ``` ### Running actions @@ -159,9 +159,9 @@ In some cases, you need to call the code every time you deploy the application. To do this, override the `$once` variable in the action file: ```php -use DragonCode\LaravelActions\Services\Actionable; +use DragonCode\LaravelActions\Action; -return new class extends Actionable +return new class extends Action { protected $once = false; @@ -187,9 +187,9 @@ In some cases, it becomes necessary to execute an action in a specific environme For this you can use the `$environment` parameter: ```php -use DragonCode\LaravelActions\Services\Actionable; +use DragonCode\LaravelActions\Action; -return new class extends Actionable +return new class extends Action { /** @var string|array|null */ protected $environment = 'production'; @@ -204,9 +204,9 @@ return new class extends Actionable You can also specify multiple environment names: ```php -use DragonCode\LaravelActions\Services\Actionable; +use DragonCode\LaravelActions\Action; -return new class extends Actionable +return new class extends Action { /** @var string|array|null */ protected $environment = ['testing', 'staging']; @@ -227,9 +227,9 @@ In some cases, it becomes necessary to execute an action excluding certain envir For this you can use the `$except_environment` parameter: ```php -use DragonCode\LaravelActions\Services\Actionable; +use DragonCode\LaravelActions\Action; -return new class extends Actionable +return new class extends Action { /** @var string|array|null */ protected $except_environment = 'production'; @@ -244,9 +244,9 @@ return new class extends Actionable You can also specify multiple environment names: ```php -use DragonCode\LaravelActions\Services\Actionable; +use DragonCode\LaravelActions\Action; -return new class extends Actionable +return new class extends Action { /** @var string|array|null */ protected $except_environment = ['testing', 'staging']; @@ -275,9 +275,9 @@ When calling the `migrate:actions` command with the `before` parameter, the scri For backwards compatibility, the `before` parameter is set to `true` by default, but actions will only be executed if the option is explicitly passed. ```php -use DragonCode\LaravelActions\Services\Actionable; +use DragonCode\LaravelActions\Action; -return new class extends Actionable +return new class extends Action { protected $before = false; @@ -320,9 +320,9 @@ By setting the `$transactions = true` parameter, you will ensure that your code will reduce the time it takes to create the action. ```php -use DragonCode\LaravelActions\Services\Actionable; +use DragonCode\LaravelActions\Action; -return new class extends Actionable +return new class extends Action { protected $transactions = true; @@ -400,9 +400,9 @@ You can also override the `success` and `failed` methods, which are called on su #### If Success ```php -use DragonCode\LaravelActions\Services\Actionable;use Illuminate\Support\Facade\Log; +use DragonCode\LaravelActions\Action;use Illuminate\Support\Facade\Log; -return new class extends Actionable +return new class extends Action { public function up(): void { @@ -433,9 +433,11 @@ The log file will contain two `success` entries. #### If Failed ```php -use DragonCode\LaravelActions\Services\Actionable;use Exeption;use Illuminate\Support\Facade\Log; +use DragonCode\LaravelActions\Action; +use Exeption; +use Illuminate\Support\Facade\Log; -return new class extends Actionable +return new class extends Action { public function up(): void { @@ -468,9 +470,9 @@ The log file will contain two `failed` entries. Quite often, when working with actions, it becomes necessary to run one or another console command, and each time you have to write the following code: ```php -use DragonCode\LaravelActions\Services\Actionable;use Illuminate\Support\Facades\Artisan; +use DragonCode\LaravelActions\Action;use Illuminate\Support\Facades\Artisan; -return new class extends Actionable +return new class extends Action { public function up() { @@ -484,9 +486,9 @@ return new class extends Actionable Since version [`2.3`](https://github.com/TheDragonCode/laravel-migration-actions/releases/tag/v2.3.0) we have added a method call. Now calling commands has become much easier: ```php -use DragonCode\LaravelActions\Services\Actionable; +use DragonCode\LaravelActions\Action; -return new class extends Actionable +return new class extends Action { public function up() { diff --git a/docs/getting-started/how-to-use/creating.md b/docs/getting-started/how-to-use/creating.md index 187a57d1..53463f7a 100644 --- a/docs/getting-started/how-to-use/creating.md +++ b/docs/getting-started/how-to-use/creating.md @@ -65,3 +65,71 @@ php artisan make:migration:action foo/bar/QweRty php artisan make:migration:action foo/bar/QweRty.php # actions/foo/bar/2022_10_11_225734_qwe_rty.php ``` + +## Invokable Method + +By default, the new action class will contain the `__invoke` method, but you can easily replace it with public `up` name. + +```php +use DragonCode\LaravelActions\Action; + +return new class () extends Action +{ + public function __invoke(): void + { + // some code + } +}; +``` + +> Note that the `__invoke` method has been added as a single call. +> This means that when the action is running, it will be called, but not when it is rolled back. +> +> You should also pay attention to the fact that if there is an `__invoke` method in the class, the `down` method will not be called. + +```php +use DragonCode\LaravelActions\Action; + +return new class () extends Action +{ + public function __invoke(): void {} // called when `php artisan migrate:actions` running + + public function down(): void {} // doesn't call when `php artisan migrate:rollback` running + // and any other commands to revert the action. +}; +``` + +## Dependency Injection + +You can also use the dependency injection with `__invoke`, `up` and `down` methods: + +```php +use DragonCode\LaravelActions\Action; +use Tests\Concerns\Some; + +return new class () extends Action +{ + public function __invoke(Some $some): void + { + $value = $some->get('qwerty'); + } +}; +``` + +```php +use DragonCode\LaravelActions\Action; +use Tests\Concerns\Some; + +return new class () extends Action +{ + public function up(Some $some): void + { + $value = $some->get('qwerty'); + } + + public function down(Some $some): void + { + $value = $some->get('qwerty'); + } +}; +``` diff --git a/src/Action.php b/src/Action.php index 100e27ee..811a52e9 100644 --- a/src/Action.php +++ b/src/Action.php @@ -57,20 +57,6 @@ abstract class Action extends Migration */ protected bool $before = true; - /** - * Run the actions. - */ - public function up(): void - { - } - - /** - * Reverse the actions. - */ - public function down(): void - { - } - /** * Determines the type of launch of the action. * diff --git a/src/Services/Migrator.php b/src/Services/Migrator.php index 6709439a..2bca7b81 100644 --- a/src/Services/Migrator.php +++ b/src/Services/Migrator.php @@ -63,7 +63,7 @@ public function runDown(string $file): void $action = $this->resolvePath($file); $name = $this->resolveActionName($file); - if ($this->hasAction($action, 'down')) { + if (! $this->hasAction($action, '__invoke') && $this->hasAction($action, 'down')) { $this->runAction($action, $name, 'down'); } diff --git a/tests/Commands/MigrateTest.php b/tests/Commands/MigrateTest.php index e1ad929b..2027859d 100644 --- a/tests/Commands/MigrateTest.php +++ b/tests/Commands/MigrateTest.php @@ -490,4 +490,32 @@ public function testMixedBefore() $this->assertDatabaseMigrationHas($this->table, 'test_before_enabled'); $this->assertDatabaseMigrationHas($this->table, 'test_before_disabled'); } + + public function testDI(): void + { + $this->copyDI(); + + $table = 'test'; + + $this->artisan(Names::INSTALL)->assertExitCode(0); + + $this->assertDatabaseCount($table, 0); + $this->assertDatabaseCount($this->table, 0); + $this->assertDatabaseMigrationDoesntLike($this->table, 'invoke'); + $this->assertDatabaseMigrationDoesntLike($this->table, 'invoke_down'); + $this->assertDatabaseMigrationDoesntLike($this->table, 'up_down'); + $this->assertDatabaseMigrationDoesntLike($table, 'up_down', column: 'value'); + $this->assertDatabaseMigrationDoesntLike($table, 'invoke_down', column: 'value'); + $this->assertDatabaseMigrationDoesntLike($table, 'invoke', column: 'value'); + $this->artisan(Names::MIGRATE)->assertExitCode(0); + + $this->assertDatabaseCount($table, 3); + $this->assertDatabaseCount($this->table, 3); + $this->assertDatabaseMigrationHas($this->table, 'invoke'); + $this->assertDatabaseMigrationHas($this->table, 'invoke_down'); + $this->assertDatabaseMigrationHas($this->table, 'up_down'); + $this->assertDatabaseMigrationHas($table, 'up_down', column: 'value'); + $this->assertDatabaseMigrationHas($table, 'invoke_down', column: 'value'); + $this->assertDatabaseMigrationHas($table, 'invoke', column: 'value'); + } } diff --git a/tests/Commands/RollbackTest.php b/tests/Commands/RollbackTest.php index 6255192b..90c6b270 100644 --- a/tests/Commands/RollbackTest.php +++ b/tests/Commands/RollbackTest.php @@ -264,4 +264,43 @@ public function testEnabledBefore() $this->assertDatabaseMigrationDoesntLike($this->table, 'test_before_enabled'); $this->assertDatabaseMigrationDoesntLike($this->table, 'test_before_disabled'); } + + public function testDI(): void + { + $this->copyDI(); + + $table = 'test'; + + $this->artisan(Names::INSTALL)->assertExitCode(0); + + $this->assertDatabaseCount($table, 0); + $this->assertDatabaseCount($this->table, 0); + $this->assertDatabaseMigrationDoesntLike($this->table, 'invoke'); + $this->assertDatabaseMigrationDoesntLike($this->table, 'invoke_down'); + $this->assertDatabaseMigrationDoesntLike($this->table, 'up_down'); + $this->assertDatabaseMigrationDoesntLike($table, 'up_down', column: 'value'); + $this->assertDatabaseMigrationDoesntLike($table, 'invoke_down', column: 'value'); + $this->assertDatabaseMigrationDoesntLike($table, 'invoke', column: 'value'); + $this->artisan(Names::MIGRATE)->assertExitCode(0); + + $this->assertDatabaseCount($table, 3); + $this->assertDatabaseCount($this->table, 3); + $this->assertDatabaseMigrationHas($this->table, 'invoke'); + $this->assertDatabaseMigrationHas($this->table, 'invoke_down'); + $this->assertDatabaseMigrationHas($this->table, 'up_down'); + $this->assertDatabaseMigrationHas($table, 'up_down', column: 'value'); + $this->assertDatabaseMigrationHas($table, 'invoke_down', column: 'value'); + $this->assertDatabaseMigrationHas($table, 'invoke', column: 'value'); + + $this->artisan(Names::ROLLBACK)->assertExitCode(0); + + $this->assertDatabaseCount($table, 2); + $this->assertDatabaseCount($this->table, 0); + $this->assertDatabaseMigrationDoesntLike($this->table, 'invoke'); + $this->assertDatabaseMigrationDoesntLike($this->table, 'invoke_down'); + $this->assertDatabaseMigrationDoesntLike($this->table, 'up_down'); + $this->assertDatabaseMigrationDoesntLike($table, 'up_down', column: 'value'); + $this->assertDatabaseMigrationHas($table, 'invoke_down', column: 'value'); + $this->assertDatabaseMigrationHas($table, 'invoke', column: 'value'); + } } diff --git a/tests/Concerns/AssertDatabase.php b/tests/Concerns/AssertDatabase.php index a3a3780e..8c435bc0 100644 --- a/tests/Concerns/AssertDatabase.php +++ b/tests/Concerns/AssertDatabase.php @@ -22,9 +22,9 @@ protected function assertDatabaseDoesntTable(string $table): void ); } - protected function assertDatabaseMigrationHas(string $table, $value, $connection = null): void + protected function assertDatabaseMigrationHas(string $table, $value, $connection = null, string $column = 'action'): void { - $this->assertDatabaseHasLike($table, 'action', $value, $connection); + $this->assertDatabaseHasLike($table, $column, $value, $connection); } protected function assertDatabaseHasLike(string $table, string $column, $value, $connection = null): void @@ -37,9 +37,9 @@ protected function assertDatabaseHasLike(string $table, string $column, $value, $this->assertTrue($exists); } - protected function assertDatabaseMigrationDoesntLike(string $table, $value, $connection = null): void + protected function assertDatabaseMigrationDoesntLike(string $table, $value, $connection = null, string $column = 'action'): void { - $this->assertDatabaseDoesntLike($table, 'action', $value, $connection); + $this->assertDatabaseDoesntLike($table, $column, $value, $connection); } protected function assertDatabaseDoesntLike(string $table, string $column, $value, $connection = null): void diff --git a/tests/Concerns/Files.php b/tests/Concerns/Files.php index f6cb46c5..46d7b642 100644 --- a/tests/Concerns/Files.php +++ b/tests/Concerns/Files.php @@ -22,6 +22,14 @@ protected function copyFiles(): void ); } + protected function copyDI(): void + { + File::copyDirectory( + __DIR__ . '/../fixtures/app/di', + $this->targetDirectory() + ); + } + protected function copySuccessFailureMethod(): void { File::copy( diff --git a/tests/Concerns/Some.php b/tests/Concerns/Some.php new file mode 100644 index 00000000..5e88dc01 --- /dev/null +++ b/tests/Concerns/Some.php @@ -0,0 +1,13 @@ +table()->insert([ + 'value' => $some->get('invoke'), + ]); + } + + protected function table(): Builder + { + return DB::table('test'); + } +}; diff --git a/tests/fixtures/app/di/2022_10_11_234251_invoke_down.php b/tests/fixtures/app/di/2022_10_11_234251_invoke_down.php new file mode 100644 index 00000000..14b61b41 --- /dev/null +++ b/tests/fixtures/app/di/2022_10_11_234251_invoke_down.php @@ -0,0 +1,28 @@ +table()->insert([ + 'value' => $some->get('invoke_down'), + ]); + } + + public function down(Some $some): void + { + $this->table() + ->where('value', $some->get('invoke_down')) + ->delete(); + } + + protected function table(): Builder + { + return DB::table('test'); + } +}; diff --git a/tests/fixtures/app/di/2022_10_11_234312_up_down.php b/tests/fixtures/app/di/2022_10_11_234312_up_down.php new file mode 100644 index 00000000..945adb6a --- /dev/null +++ b/tests/fixtures/app/di/2022_10_11_234312_up_down.php @@ -0,0 +1,28 @@ +table()->insert([ + 'value' => $some->get('up_down'), + ]); + } + + public function down(Some $some): void + { + $this->table() + ->where('value', $some->get('up_down')) + ->delete(); + } + + protected function table(): Builder + { + return DB::table('test'); + } +}; From 9ec0b680c2de3a250a80a0bf78598cf10e6d64ce Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Wed, 12 Oct 2022 00:14:18 +0300 Subject: [PATCH 137/153] Update docs --- docs/getting-started/how-to-use/execution.md | 1 - docs/getting-started/how-to-use/running.md | 203 +++++++++++++++++++ docs/index.md | 2 +- 3 files changed, 204 insertions(+), 2 deletions(-) delete mode 100644 docs/getting-started/how-to-use/execution.md create mode 100644 docs/getting-started/how-to-use/running.md diff --git a/docs/getting-started/how-to-use/execution.md b/docs/getting-started/how-to-use/execution.md deleted file mode 100644 index 634d96c9..00000000 --- a/docs/getting-started/how-to-use/execution.md +++ /dev/null @@ -1 +0,0 @@ -# Execution Actions diff --git a/docs/getting-started/how-to-use/running.md b/docs/getting-started/how-to-use/running.md new file mode 100644 index 00000000..148208eb --- /dev/null +++ b/docs/getting-started/how-to-use/running.md @@ -0,0 +1,203 @@ +# Running Actions + +To run all of your outstanding actions, execute the `migrate:actions` artisan command: + +```bash +php artisan migrate:actions +``` + +## Split Launch Option + +Sometimes it becomes necessary to launch actions separately, for example, to notify about the successful deployment of a project. + +There is a `before` option for this when calling actions: + +```bash +php artisan migrate:actions --before +``` + +When calling the `migrate:actions` command with the `before` parameter, the script will execute only those actions within which the value of the `before` parameter is `true`. + +For backwards compatibility, the `before` parameter is set to `true` by default, but actions will only be executed if the option is explicitly passed. + +```php +use DragonCode\LaravelActions\Action; + +return new class () extends Action +{ + protected $before = false; + + public function __invoke(): void + { + // some code + } +}; +``` + +For example, you need to call actions when deploying an application. Some actions should be run after the migrations are deployed, and others after the application is fully +launched. + +To run, you need to pass the `before` parameter. For example, when using [`deployer`](https://github.com/deployphp/deployer) it would look like this: + +```php +task('deploy', [ + // ... + 'artisan:migrate', + 'artisan:migrate:actions --before', // here + 'deploy:publish', + 'php-fpm:reload', + 'artisan:queue:restart', + 'artisan:migrate:actions', // here +]); +``` + +Thus, when `migrate:actions` is called, all actions whose `before` parameter is `true` will be executed, and after that, the remaining tasks will be executed. + +> Note: +> If you call the `migrate:actions` command without the `before` parameter, +> then all tasks will be executed regardless of the value of the `$before` +> attribute inside the action class. + +## Forcing Actions To Run In Production + +> Some commands cannot be executed in production without confirmation. +> These include all commands except `migrate:actions:status` and `migrate:actions`. + +Some action operations are destructive, which means they may cause you to lose data. In order to protect you from running these commands against your production database, +you will be prompted for confirmation before the commands are executed. To force the commands to run without a prompt, use the `--force` flag: + +```bash +php artisan migrate:actions:install --force +``` + +## Execution Every Time + +In some cases, you need to call the code every time you deploy the application. For example, to call reindexing. + +To do this, override the `$once` variable in the action file: + +```php +use DragonCode\LaravelActions\Action; + +return new class () extends Action +{ + protected $once = false; + + public function __invoke(): void + { + // some code + } +}; +``` + +If the value is `$once = false`, the `up` method will be called every time the `migrate:actions` command called. + +In this case, information about it will not be written to the `migration_actions` table and, therefore, the `down` method will not be called when the rollback command is called. + +> Note +> +> When using the `before` parameter to run command, it is recommended to override the value of the `$before` attribute to `false`, otherwise this action will be executed twice. + +## Execution In A Specific Environment + +In some cases, it becomes necessary to execute an action in a specific environment. For example `production`. + +For this you can use the `$environment` parameter: + +```php +use DragonCode\LaravelActions\Action; + +return new class () extends Action +{ + /** @var string|array|null */ + protected $environment = 'production'; + + public function __invoke(): void + { + // some code + } +}; +``` + +You can also specify multiple environment names: + +```php +use DragonCode\LaravelActions\Action; + +return new class () extends Action +{ + /** @var string|array|null */ + protected $environment = ['testing', 'staging']; + + public function __invoke(): void + { + // some code + } +}; +``` + +By default, the action will run in all environments. The same will happen if you specify `null` or `[]` as the value. + +## Execution Excluding Certain Environments + +In some cases, it becomes necessary to execute an action excluding certain environments. For example `production`. + +For this you can use the `$except_environment` parameter: + +```php +use DragonCode\LaravelActions\Action; + +return new class () extends Action +{ + /** @var string|array|null */ + protected $except_environment = 'production'; + + public function __invoke(): void + { + // some code + } +}; +``` + +You can also specify multiple environment names: + +```php +use DragonCode\LaravelActions\Action; + +return new class () extends Action +{ + /** @var string|array|null */ + protected $except_environment = ['testing', 'staging']; + + public function __invoke(): void + { + // some code + } +}; +``` + +By default, no actions will be excluded. The same happens if you specify `null` or `[]` value. + +## Database Transactions + +In some cases, it becomes necessary to undo previously performed actions in the database. For example, when code execution throws an error. To do this, the code must be wrapped in +a transaction. + +By setting the `$transactions = true` parameter, you will ensure that your code is wrapped in a transaction without having to manually call the `DB::transaction()` method. This +will reduce the time it takes to create the action. + +```php +use DragonCode\LaravelActions\Action; + +return new class () extends Action +{ + protected $transactions = true; + + protected $transactionAttempts = 3; + + public function __invoke(): void + { + // some code + } +}; +``` diff --git a/docs/index.md b/docs/index.md index 3434fef5..e5b5cffc 100644 --- a/docs/index.md +++ b/docs/index.md @@ -19,7 +19,7 @@ * [Installation](getting-started/installation.md) * How to use * [Creating](getting-started/how-to-use/creating.md) - * [Execution](getting-started/how-to-use/execution.md) + * [Running Actions](getting-started/how-to-use/running.md) * [Rolling Back](getting-started/how-to-use/rollback.md) * [Rolling Back & Actions Using A Single Command](getting-started/how-to-use/resetting.md) * [Drop All Actions & Run Actions](getting-started/how-to-use/freshing.md) From c200cc1b331a15b59384f53cab04b773967eae74 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Wed, 12 Oct 2022 00:15:06 +0300 Subject: [PATCH 138/153] Update running.md --- docs/getting-started/how-to-use/running.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/getting-started/how-to-use/running.md b/docs/getting-started/how-to-use/running.md index 148208eb..bad1eadf 100644 --- a/docs/getting-started/how-to-use/running.md +++ b/docs/getting-started/how-to-use/running.md @@ -150,7 +150,7 @@ use DragonCode\LaravelActions\Action; return new class () extends Action { /** @var string|array|null */ - protected $except_environment = 'production'; + protected $exceptEnvironment = 'production'; public function __invoke(): void { @@ -167,7 +167,7 @@ use DragonCode\LaravelActions\Action; return new class () extends Action { /** @var string|array|null */ - protected $except_environment = ['testing', 'staging']; + protected $exceptEnvironment = ['testing', 'staging']; public function __invoke(): void { From 6b77dfd91f91d0380e322eebc993cd6b6ae1f3be Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Wed, 12 Oct 2022 00:39:03 +0300 Subject: [PATCH 139/153] Updated docs --- docs/getting-started/helpers/artisan.md | 16 +++++ docs/getting-started/helpers/events.md | 50 +++++++++++++ .../helpers/execution-status.md | 71 +++++++++++++++++++ .../helpers/execution-statuses.md | 1 - docs/getting-started/how-to-use/creating.md | 4 +- docs/getting-started/how-to-use/freshing.md | 1 - docs/getting-started/how-to-use/refreshing.md | 1 - docs/getting-started/how-to-use/resetting.md | 0 docs/getting-started/how-to-use/rollback.md | 43 +++++++++++ docs/getting-started/how-to-use/status.md | 7 ++ docs/index.md | 4 +- docs/prologue/upgrade.md | 2 + src/Events/ActionEnded.php | 5 -- src/Events/ActionFailed.php | 9 +++ src/Events/ActionStarted.php | 5 -- src/Events/BaseEvent.php | 5 ++ src/Events/NoPendingActions.php | 4 -- src/Processors/Migrate.php | 21 ++++-- src/Processors/Processor.php | 5 +- src/Processors/Rollback.php | 8 +-- 20 files changed, 226 insertions(+), 36 deletions(-) create mode 100644 docs/getting-started/helpers/execution-status.md delete mode 100644 docs/getting-started/helpers/execution-statuses.md delete mode 100644 docs/getting-started/how-to-use/freshing.md delete mode 100644 docs/getting-started/how-to-use/refreshing.md delete mode 100644 docs/getting-started/how-to-use/resetting.md create mode 100644 src/Events/ActionFailed.php diff --git a/docs/getting-started/helpers/artisan.md b/docs/getting-started/helpers/artisan.md index a32e0143..ba4458fe 100644 --- a/docs/getting-started/helpers/artisan.md +++ b/docs/getting-started/helpers/artisan.md @@ -1 +1,17 @@ # Artisan Command + +Quite often, when working with actions, it becomes necessary to run one or another console command, and each time you have to write the following code: + +```php +use DragonCode\LaravelActions\Action; + +return new class () extends Action +{ + public function __invoke(): void + { + $this->artisan('some_command', [ + // parameters + ]); + } +}; +``` diff --git a/docs/getting-started/helpers/events.md b/docs/getting-started/helpers/events.md index 1f187df0..fa3cc576 100644 --- a/docs/getting-started/helpers/events.md +++ b/docs/getting-started/helpers/events.md @@ -1 +1,51 @@ # Events + +You can also handle events when executing actions: + +``` +DragonCode\LaravelActions\Events\ActionStarted +DragonCode\LaravelActions\Events\ActionEnded +DragonCode\LaravelActions\Events\ActionFailed +DragonCode\LaravelActions\Events\NoPendingActions +``` + +If there are no action files to execute, the `NoPendingActions` event will be sent. + +In other cases, the `ActionStarted` event will be sent before processing starts, and the `ActionEnded` event will be sent after processing. + +For example: + +```php +namespace App\Providers; + +use App\Listeners\SomeActionsListener; +use DragonCode\LaravelActions\Events\ActionEnded; +use DragonCode\LaravelActions\Events\ActionStarted; +use DragonCode\LaravelActions\Events\NoPendingActions; +use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; + +class EventServiceProvider extends ServiceProvider +{ + protected $listen = [ + ActionStarted::class => [SomeActionsListener::class], + ActionEnded::class => [SomeActionsListener::class], + ActionFailed::class => [SomeActionsListener::class], + NoPendingActions::class => [SomeActionsListener::class], + ]; +} +``` + +```php +namespace App\Listeners; + +use DragonCode\LaravelActions\Events\BaseEvent; + +class SomeActionsListener +{ + public function handle(BaseEvent $event): void + { + $method = $event->method; // `up` or `down` string value + $isBefore = $event->before; // boolean + } +} +``` diff --git a/docs/getting-started/helpers/execution-status.md b/docs/getting-started/helpers/execution-status.md new file mode 100644 index 00000000..a93b2d0d --- /dev/null +++ b/docs/getting-started/helpers/execution-status.md @@ -0,0 +1,71 @@ +# Execution Status + +You can also override the `success` and `failed` methods, which are called on success or failure processing. + +## If Success + +```php +use DragonCode\LaravelActions\Action;use Illuminate\Support\Facade\Log; + +return new class () extends Action +{ + public function up(): void + { + // + } + + public function down(): void + { + // + } + + public function success(): void + { + Log::info('success'); + } + + public function failed(): void + { + Log::info('failed'); + } +}; +``` + +Call the `php artisan migrate:actions` command. + +The log file will contain two `success` entries. + +## If Failed + +```php +use DragonCode\LaravelActions\Action; +use Exeption; +use Illuminate\Support\Facade\Log; + +return new class extends Action +{ + public function up(): void + { + throw new Exeption(); + } + + public function down(): void + { + throw new Exeption(); + } + + public function success(): void + { + Log::info('success'); + } + + public function failed(): void + { + Log::info('failed'); + } +}; +``` + +Call the `php artisan migrate:actions` command. + +The log file will contain two `failed` entries. diff --git a/docs/getting-started/helpers/execution-statuses.md b/docs/getting-started/helpers/execution-statuses.md deleted file mode 100644 index 3791d06e..00000000 --- a/docs/getting-started/helpers/execution-statuses.md +++ /dev/null @@ -1 +0,0 @@ -# Execution Status diff --git a/docs/getting-started/how-to-use/creating.md b/docs/getting-started/how-to-use/creating.md index 53463f7a..7c675ec0 100644 --- a/docs/getting-started/how-to-use/creating.md +++ b/docs/getting-started/how-to-use/creating.md @@ -20,14 +20,12 @@ If you do not specify the "name" attribute, then the file name will be generated ```bash php artisan make:migration:action -### When the git repository is found (`base_path('.git')` directory is exists). -### For example, HEAD branch name is 'qwerty'. +### When the git repository is found (`base_path('.git')` directory is exists) and HEAD branch name is 'qwerty' # 2022_10_11_225116_qwerty.php # 2022_10_11_225118_qwerty.php # 2022_10_11_225227_qwerty.php ### When the git repository is not found (`base_path('.git')` directory doesn't exists). -### For example, HEAD branch name is 'qwerty'. # 2022_10_11_225116_auto.php # 2022_10_11_225118_auto.php # 2022_10_11_225227_auto.php diff --git a/docs/getting-started/how-to-use/freshing.md b/docs/getting-started/how-to-use/freshing.md deleted file mode 100644 index 7dba09a4..00000000 --- a/docs/getting-started/how-to-use/freshing.md +++ /dev/null @@ -1 +0,0 @@ -# Drop All Actions & Run Actions diff --git a/docs/getting-started/how-to-use/refreshing.md b/docs/getting-started/how-to-use/refreshing.md deleted file mode 100644 index 0b9bcb0a..00000000 --- a/docs/getting-started/how-to-use/refreshing.md +++ /dev/null @@ -1 +0,0 @@ -# Refresh diff --git a/docs/getting-started/how-to-use/resetting.md b/docs/getting-started/how-to-use/resetting.md deleted file mode 100644 index e69de29b..00000000 diff --git a/docs/getting-started/how-to-use/rollback.md b/docs/getting-started/how-to-use/rollback.md index e69de29b..6752f109 100644 --- a/docs/getting-started/how-to-use/rollback.md +++ b/docs/getting-started/how-to-use/rollback.md @@ -0,0 +1,43 @@ +# Rolling Back Actions + +To roll back the latest action operation, you may use the `rollback` command. This command rolls back the last "batch" of actions, which may include multiple action files: + +``` +php artisan migrate:actions:rollback +``` + +You may roll back a limited number of actions by providing the `step` option to the rollback command. For example, the following command will roll back the last five actions: + +``` +php artisan migrate:actions:rollback --step=5 +``` + +The `migrate:actions:reset` command will roll back all of your application's migrations: + +``` +php artisan migrate:actions:reset +``` + +## Roll Back & Action Using A Single Command + +The `migrate:actions:refresh` command will roll back all of your migrations and then execute the `migrate:actions` command. This command effectively re-creates your entire +database: + +``` +php artisan migrate:actions:refresh +``` + +You may roll back & re-migrate a limited number of migrations by providing the `step` option to the `refresh` command. For example, the following command will roll back & +re-migrate the last five migrations: + +``` +php artisan migrate:actions:refresh --step=5 +``` + +## Drop All Actions & Rerun Actions + +The `migrate:actions:fresh` command will drop all actions records from the actions table and then execute the migrate command: + +``` +php artisan migrate:actions:fresh +``` diff --git a/docs/getting-started/how-to-use/status.md b/docs/getting-started/how-to-use/status.md index e69de29b..3e170404 100644 --- a/docs/getting-started/how-to-use/status.md +++ b/docs/getting-started/how-to-use/status.md @@ -0,0 +1,7 @@ +# Actions Status + +The `migrate:actions:status` command displays the execution status of actions. In it you can see which actions were executed and which were not: + +``` +php artisan migrate:actions:status +``` diff --git a/docs/index.md b/docs/index.md index e5b5cffc..ea62cc3f 100644 --- a/docs/index.md +++ b/docs/index.md @@ -21,11 +21,9 @@ * [Creating](getting-started/how-to-use/creating.md) * [Running Actions](getting-started/how-to-use/running.md) * [Rolling Back](getting-started/how-to-use/rollback.md) - * [Rolling Back & Actions Using A Single Command](getting-started/how-to-use/resetting.md) - * [Drop All Actions & Run Actions](getting-started/how-to-use/freshing.md) * [Status](getting-started/how-to-use/status.md) * Helpers - * [Execution Status](getting-started/helpers/execution-statuses.md) + * [Execution Status](getting-started/helpers/execution-status.md) * [Events](getting-started/helpers/events.md) * [Artisan Command](getting-started/helpers/artisan.md) diff --git a/docs/prologue/upgrade.md b/docs/prologue/upgrade.md index 40e1497a..cc84cb28 100644 --- a/docs/prologue/upgrade.md +++ b/docs/prologue/upgrade.md @@ -1 +1,3 @@ # Upgrade Guide + +## Upgrading To 3.x from 2.x diff --git a/src/Events/ActionEnded.php b/src/Events/ActionEnded.php index e52bdd3a..2c855ef2 100644 --- a/src/Events/ActionEnded.php +++ b/src/Events/ActionEnded.php @@ -6,9 +6,4 @@ class ActionEnded extends BaseEvent { - public function __construct( - public string $method, - public bool $before - ) { - } } diff --git a/src/Events/ActionFailed.php b/src/Events/ActionFailed.php new file mode 100644 index 00000000..815cd3ac --- /dev/null +++ b/src/Events/ActionFailed.php @@ -0,0 +1,9 @@ +getNewFiles()) { - $this->fireEvent(new ActionStarted('up', $this->options->before)); + try { + if ($files = $this->getNewFiles()) { + $this->fireEvent(ActionStarted::class, 'up'); - $this->runEach($files, $this->getBatch()); + $this->runEach($files, $this->getBatch()); - $this->fireEvent(new ActionEnded('up', $this->options->before)); + $this->fireEvent(ActionEnded::class, 'up'); - return; + return; + } + + $this->fireEvent(NoPendingActions::class, 'up'); } + catch (Throwable $e) { + $this->fireEvent(ActionFailed::class, 'up'); - $this->fireEvent(new NoPendingActions('up')); + throw $e; + } } protected function runEach(array $files, int $batch): void diff --git a/src/Processors/Processor.php b/src/Processors/Processor.php index a4581412..c93e2ef2 100644 --- a/src/Processors/Processor.php +++ b/src/Processors/Processor.php @@ -7,7 +7,6 @@ use Closure; use DragonCode\LaravelActions\Concerns\Artisan; use DragonCode\LaravelActions\Contracts\Notification; -use DragonCode\LaravelActions\Events\BaseEvent; use DragonCode\LaravelActions\Helpers\Config; use DragonCode\LaravelActions\Helpers\Git; use DragonCode\LaravelActions\Repositories\ActionRepository; @@ -76,8 +75,8 @@ protected function tableNotFound(): bool return false; } - protected function fireEvent(BaseEvent $event): void + protected function fireEvent(string $event, string $method): void { - $this->events->dispatch($event); + $this->events->dispatch(new $event($method, $this->options->before)); } } diff --git a/src/Processors/Rollback.php b/src/Processors/Rollback.php index 0498c3a9..9a3420fa 100644 --- a/src/Processors/Rollback.php +++ b/src/Processors/Rollback.php @@ -14,22 +14,22 @@ class Rollback extends Processor public function handle(): void { if ($this->tableNotFound() || $this->nothingToRollback()) { - $this->fireEvent(new NoPendingActions('down')); + $this->fireEvent(NoPendingActions::class, 'down'); return; } if ($actions = $this->getActions($this->options->step)) { - $this->fireEvent(new ActionStarted('down', $this->options->before)); + $this->fireEvent(ActionStarted::class, 'down'); $this->run($actions); - $this->fireEvent(new ActionEnded('down', $this->options->before)); + $this->fireEvent(ActionEnded::class, 'down'); return; } - $this->fireEvent(new NoPendingActions('down')); + $this->fireEvent(NoPendingActions::class, 'down'); } protected function run(array $actions): void From e60259a5be14a9acc23b169c1fa7757366092fb7 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Wed, 12 Oct 2022 00:39:44 +0300 Subject: [PATCH 140/153] Fixed code-style --- src/Events/BaseEvent.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Events/BaseEvent.php b/src/Events/BaseEvent.php index 4b2957d5..49582aa0 100644 --- a/src/Events/BaseEvent.php +++ b/src/Events/BaseEvent.php @@ -8,7 +8,7 @@ abstract class BaseEvent { public function __construct( public string $method, - public bool $before + public bool $before ) { } } From d1147627292dece1b15017aac3fadc541ab02082 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Wed, 12 Oct 2022 00:55:55 +0300 Subject: [PATCH 141/153] Added notifications when upgrade command running --- docs/prologue/upgrade.md | 44 ++++++++++++++++++++++++++++++++++++++ src/Processors/Upgrade.php | 28 ++++++++++++++++-------- 2 files changed, 63 insertions(+), 9 deletions(-) diff --git a/docs/prologue/upgrade.md b/docs/prologue/upgrade.md index cc84cb28..c92d7c82 100644 --- a/docs/prologue/upgrade.md +++ b/docs/prologue/upgrade.md @@ -1,3 +1,47 @@ # Upgrade Guide +## High Impact Changes + +- Replacing named classes with anonymous ones +- Change the location of the configuration file +- Changing the namespace of the parent class +- Changing variable names from `snake_case` to `camelCase` +- Added recursive search for actions in a folder +- PHP 7.3 and 7.4 was dropped +- Laravel 6.0 was dropped +- Dragon Code: Contracts (`dragon-code/contracts`) was dropped + +## Medium Impact Changes + +- Changing the name of an action column in the database +- Action storage directory changed + ## Upgrading To 3.x from 2.x + +### Updating Dependencies + +#### PHP 8.0.2 Required + +Laravel Actions now requires PHP 8.0.2 or greater. + +#### Composer Dependencies + +You should update the following dependency in your application's `composer.json` file: + +- `dragon-code/laravel-migration-actions` to `^3.0` + +### Call Upgrade Command + +For your convenience, we have created an upgrade console command: + +```bash +php artisan migrate:actions:upgrade +``` + +It will do the following: + +- Change the namespace of the abstract class +- Add a strict type declaration +- Replace the `up` method with `__invoke` if the class does not have a `down` method +- Replace named classes with anonymous ones +- Create a configuration file according to the data saved in your project diff --git a/src/Processors/Upgrade.php b/src/Processors/Upgrade.php index c867f28f..67f04bf7 100644 --- a/src/Processors/Upgrade.php +++ b/src/Processors/Upgrade.php @@ -27,6 +27,7 @@ protected function run(): void { $this->moveFiles(); $this->moveConfig(); + $this->clean(); } protected function moveFiles(): void @@ -49,6 +50,13 @@ protected function move(string $filename): void $this->delete($filename); } + protected function clean(): void + { + $this->notification->task('Delete old directory', fn () => Directory::ensureDelete( + database_path('actions') + )); + } + protected function open(string $path): string { return file_get_contents(base_path('database/actions/' . $path)); @@ -100,23 +108,25 @@ protected function replaceWithInvoke(string $content): string protected function moveConfig(): void { - $this->artisan('vendor:publish', [ - '--provider' => ServiceProvider::class, - '--force' => true, - ]); + $this->notification->task('Moving config file', function () { + $this->artisan('vendor:publish', [ + '--provider' => ServiceProvider::class, + '--force' => true, + ]); - $path = config_path('actions.php'); + $path = config_path('actions.php'); - $table = config('database.actions', 'migration_actions'); + $table = config('database.actions', 'migration_actions'); - $content = Str::replace(file_get_contents($path), "'table' => 'migration_actions'", "'table' => '$table'"); + $content = Str::replace(file_get_contents($path), "'table' => 'migration_actions'", "'table' => '$table'"); - file_put_contents($path, $content); + file_put_contents($path, $content); + }); } protected function getOldFiles(): array { - return $this->getFiles(path: base_path('database/actions')); + return $this->getFiles(path: database_path('actions')); } protected function alreadyUpgraded(): bool From a966d4dfc75c01bdb72da045064a5e3db729b20c Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Wed, 12 Oct 2022 00:56:09 +0300 Subject: [PATCH 142/153] Bump min PHP version to 8.0.2 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index af18ace7..d63cf736 100644 --- a/composer.json +++ b/composer.json @@ -43,7 +43,7 @@ } ], "require": { - "php": "^8.0", + "php": "^8.0.2", "composer-runtime-api": "^2.2", "doctrine/dbal": "^2.13 || ^3.4", "dragon-code/laravel-support": "^3.4", From 50a1b1bccbe9f5bbb6c0b4706ead8d39ad0b0529 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Wed, 12 Oct 2022 02:13:42 +0300 Subject: [PATCH 143/153] Update README.md --- README.md | 488 +----------------------------------------------------- 1 file changed, 2 insertions(+), 486 deletions(-) diff --git a/README.md b/README.md index 2dea61bb..52605a21 100644 --- a/README.md +++ b/README.md @@ -11,493 +11,9 @@ > Actions are like version control for your migration process, allowing your team to modify and share the application's Action schema. If you have ever had to tell a teammate > to manually perform any action on a producton server, you've come across an issue that actions solves. -## Installation +## Documentation -To get the latest version of Laravel Actions, simply require the project using [Composer](https://getcomposer.org): - -```bash -$ composer require dragon-code/laravel-migration-actions -``` - -Or manually update `require` block of `composer.json` and run `composer update`. - -```json -{ - "require": { - "dragon-code/laravel-migration-actions": "^2.9" - } -} -``` - -### Upgrade From `dragon-code/laravel-actions` - -1. In your `composer.json` file, replace `dragon-code/laravel-actions` with `dragon-code/laravel-migration-actions`. -3. Run the `command composer` update. -4. Profit! - -### Upgrade From `andrey-helldar/laravel-actions` - -1. In your `composer.json` file, replace `"andrey-helldar/laravel-actions": "^1.0"` with `"dragon-code/laravel-migration-actions": "^2.0"`. -2. Replace the `Helldar\LaravelActions` namespace prefix with `DragonCode\LaravelActions` in your app; -3. Run the `command composer` update. -4. Profit! - -#### Laravel Framework - -Nothing else needs to be done. All is ready 😊 - -#### Lumen Framework - -This package is focused on Laravel development, but it can also be used in Lumen with some workarounds. Because Lumen works a little different, as it is like a barebone version of -Laravel and the main configuration parameters are instead located in `bootstrap/app.php`, some alterations must be made. - -You can install `Laravel Actions` in `app/Providers/AppServiceProvider.php`, and uncommenting this line that registers the App Service Providers so it can properly load. - -``` -// $app->register(App\Providers\AppServiceProvider::class); -``` - -If you are not using that line, that is usually handy to manage gracefully multiple Lumen installations, you will have to add this line of code under -the `Register Service Providers` section of your `bootstrap/app.php`. - -```php -$app->register(\DragonCode\LaravelActions\ServiceProvider::class); -``` - -## How To Use - -### Creating Actions - -To create a migration, use the `make:migration:action` Artisan command: - -``` -php artisan make:migration:action my_action -``` - -The new action will be placed in your `database/actions` directory. Each action file name contains a timestamp, which allows Laravel to determine the order of the actions. - -> At the first start, you need to create a table by running the `migrate:actions:install` command. -> -> If you execute `migrate:actions` with the first command, the `migrate:actions:install` command will be called automatically. -> -> Starting from version 2.9 the `down` method will not be shown by default when creating actions files. If you need this method, just override it in the class. - -#### Automatically Generate A File Name - -If you are not worried about the names of your files, then in version [2.6](https://github.com/TheDragonCode/laravel-migration-actions/releases/tag/v2.6.0) we added the ability to -automatically generate file names. - -Just don't include the name attribute when creating the migration. - -If a git repository is found in the main folder, then the name of the current active branch will be taken as a prefix: - -```bash -php artisan make:migration:action - -### Before Laravel 8.37 -# 2022_01_28_184116_main_1643384476.php -# 2022_01_28_184117_main_1643384477.php -# 2022_01_28_184118_crm_2345_1643384478.php -# 2022_01_28_184119_crm_2345_1643384479.php - -### Laravel 8.37 or higher -# 2022_01_28_184116_main.php -# 2022_01_28_184117_main.php -# 2022_01_28_184118_crm_2345.php -# 2022_01_28_184119_crm_2345.php -``` - -If the git repository is not found, then the default prefix will be used: - -```bash -php artisan make:migration:action - -### Before Laravel 8.37 -# 2022_01_28_184116_auto_1643384476.php -# 2022_01_28_184117_auto_1643384477.php -# 2022_01_28_184118_auto_1643384478.php - -### Laravel 8.37 or higher -# 2022_01_28_184116_auto.php -# 2022_01_28_184117_auto.php -# 2022_01_28_184118_auto.php -``` - -If you are using Laravel prior to version [8.37](https://github.com/laravel/framework/releases/tag/v8.37.0), then to ensure backward compatibility, if the current git repository -branch name starts with a number, the `branch` prefix will be automatically added to it: - -```bash -php artisan make:migration:action -``` - -```php -/* 2022_01_28_184116_branch_2x_1643384476.php */ -class Branch2x1643384476 extends Action { } -``` - -### Running actions - -To run all of your outstanding actions, execute the `migrate:actions` Artisan command: - -``` -php artisan migrate:actions -``` - -#### Forcing Actions To Run In Production - -Some action operations are destructive, which means they may cause you to lose data. In order to protect you from running these commands against your production database, you will -be prompted for confirmation before the commands are executed. To force the commands to run without a prompt, use the `--force` flag: - -``` -php artisan migrate:actions --force -``` - -#### Execution Every Time - -In some cases, you need to call the code every time you deploy the application. For example, to call reindexing. - -To do this, override the `$once` variable in the action file: - -```php -use DragonCode\LaravelActions\Action; - -return new class extends Action -{ - protected $once = false; - - public function up(): void - { - // your code - } -}; -``` - -If the value is `$once = false`, the `up` method will be called every time the `migrate:actions` command called. - -In this case, information about it will not be written to the `migration_actions` table and, therefore, the `down` method will not be called when the rollback command is called. - -> Note -> -> When using the `before` parameter to run command, it is recommended to override the value of the `$before` attribute to `false`, otherwise this action will be executed twice. - -#### Execution In A Specific Environment - -In some cases, it becomes necessary to execute an action in a specific environment. For example `production`. - -For this you can use the `$environment` parameter: - -```php -use DragonCode\LaravelActions\Action; - -return new class extends Action -{ - /** @var string|array|null */ - protected $environment = 'production'; - - public function up(): void - { - // your code - } -}; -``` - -You can also specify multiple environment names: - -```php -use DragonCode\LaravelActions\Action; - -return new class extends Action -{ - /** @var string|array|null */ - protected $environment = ['testing', 'staging']; - - public function up(): void - { - // your code - } -}; -``` - -By default, the action will run in all environments. The same will happen if you specify `null` or `[]` as the value. - -#### Execution Excluding Certain Environments - -In some cases, it becomes necessary to execute an action excluding certain environments. For example `production`. - -For this you can use the `$except_environment` parameter: - -```php -use DragonCode\LaravelActions\Action; - -return new class extends Action -{ - /** @var string|array|null */ - protected $except_environment = 'production'; - - public function up(): void - { - // your code - } -}; -``` - -You can also specify multiple environment names: - -```php -use DragonCode\LaravelActions\Action; - -return new class extends Action -{ - /** @var string|array|null */ - protected $except_environment = ['testing', 'staging']; - - public function up(): void - { - // your code - } -}; -``` - -By default, no actions will be excluded. The same happens if you specify `null` or `[]` value. - -#### Split Launch Option - -Sometimes it becomes necessary to launch actions separately, for example, to notify about the successful deployment of a project. - -There is a `before` option for this when calling actions: - -```bash -php artisan migrate:actions --before -``` - -When calling the `migrate:actions` command with the `before` parameter, the script will execute only those actions within which the value of the `before` parameter is `true`. - -For backwards compatibility, the `before` parameter is set to `true` by default, but actions will only be executed if the option is explicitly passed. - -```php -use DragonCode\LaravelActions\Action; - -return new class extends Action -{ - protected $before = false; - - public function up(): void - { - // your code - } -}; -``` - -For example, you need to call actions when deploying an application. Some actions should be run after the migrations are deployed, and others after the application is fully -launched. - -To run, you need to pass the `before` parameter. For example, when using [`deployer`](https://github.com/deployphp/deployer) it would look like this: - -```php -task('deploy', [ - // ... - 'artisan:migrate', - 'artisan:migrate:actions --before', // here - 'deploy:publish', - 'php-fpm:reload', - 'artisan:queue:restart', - 'artisan:migrate:actions', // here -]); -``` - -Thus, when `migrate:actions` is called, all actions whose `before` parameter is `true` will be executed, and after that, the remaining tasks will be executed. - -> Note: -> If you call the `migrate:actions` command without the `before` parameter, then all tasks will be executed regardless of the value of the `$before` attribute inside the action -> class. - -#### Database Transactions - -In some cases, it becomes necessary to undo previously performed actions in the database. For example, when code execution throws an error. To do this, the code must be wrapped in -a transaction. - -By setting the `$transactions = true` parameter, you will ensure that your code is wrapped in a transaction without having to manually call the `DB::transaction()` method. This -will reduce the time it takes to create the action. - -```php -use DragonCode\LaravelActions\Action; - -return new class extends Action -{ - protected $transactions = true; - - protected $transaction_attempts = 3; - - public function up(): void - { - // ... - - $post = Post::create([ - 'title' => 'Random Title' - ]); - - $post->tags()->sync($ids); - } -}; -``` - -### Rolling Back Actions - -To roll back the latest action operation, you may use the `rollback` command. This command rolls back the last "batch" of actions, which may include multiple action files: - -``` -php artisan migrate:actions:rollback -``` - -You may roll back a limited number of actions by providing the `step` option to the rollback command. For example, the following command will roll back the last five actions: - -``` -php artisan migrate:actions:rollback --step=5 -``` - -The `migrate:actions:reset` command will roll back all of your application's migrations: - -``` -php artisan migrate:actions:reset -``` - -### Roll Back & Action Using A Single Command - -The `migrate:actions:refresh` command will roll back all of your migrations and then execute the `migrate:actions` command. This command effectively re-creates your entire -database: - -``` -php artisan migrate:actions:refresh -``` - -You may roll back & re-migrate a limited number of migrations by providing the `step` option to the `refresh` command. For example, the following command will roll back & -re-migrate the last five migrations: - -``` -php artisan migrate:actions:refresh --step=5 -``` - -### Drop All Actions & Migrate Actions - -The `migrate:actions:fresh` command will drop all actions records from the actions table and then execute the migrate command: - -``` -php artisan migrate:actions:fresh -``` - -### Actions Status - -The `migrate:actions:status` command displays the execution status of actions. In it you can see which actions were executed and which were not: - -``` -php artisan migrate:actions:status -``` - -### Execution Status - -You can also override the `success` and `failed` methods, which are called on success or failure processing. - -#### If Success - -```php -use DragonCode\LaravelActions\Action;use Illuminate\Support\Facade\Log; - -return new class extends Action -{ - public function up(): void - { - // - } - - public function down(): void - { - // - } - - public function success(): void - { - Log::info('success'); - } - - public function failed(): void - { - Log::info('failed'); - } -}; -``` - -Call the `php artisan migrate:actions` command. - -The log file will contain two `success` entries. - -#### If Failed - -```php -use DragonCode\LaravelActions\Action; -use Exeption; -use Illuminate\Support\Facade\Log; - -return new class extends Action -{ - public function up(): void - { - throw new Exeption(); - } - - public function down(): void - { - throw new Exeption(); - } - - public function success(): void - { - Log::info('success'); - } - - public function failed(): void - { - Log::info('failed'); - } -}; -``` - -Call the `php artisan migrate:actions` command. - -The log file will contain two `failed` entries. - -### Artisan Command - -Quite often, when working with actions, it becomes necessary to run one or another console command, and each time you have to write the following code: - -```php -use DragonCode\LaravelActions\Action;use Illuminate\Support\Facades\Artisan; - -return new class extends Action -{ - public function up() - { - Artisan::call('command-name', [ - // parameters - ]); - } -}; -``` - -Since version [`2.3`](https://github.com/TheDragonCode/laravel-migration-actions/releases/tag/v2.3.0) we have added a method call. Now calling commands has become much easier: - -```php -use DragonCode\LaravelActions\Action; - -return new class extends Action -{ - public function up() - { - $this->artisan('command-name', [ - // parameters - ]); - } -}; -``` +See the [documentation](docs/index.md) for detailed installation and usage instructions. ## License From ad2c497f7f1b7ccc467278ac5befd9d328f76c68 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Wed, 12 Oct 2022 02:14:23 +0300 Subject: [PATCH 144/153] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 52605a21..b6486978 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,8 @@ [![Github Workflow Status][badge_build]][link_build] [![License][badge_license]][link_license] -> Actions are like version control for your migration process, allowing your team to modify and share the application's Action schema. If you have ever had to tell a teammate -> to manually perform any action on a producton server, you've come across an issue that actions solves. +> Actions are like version control for your actions process, allowing your team to modify and share the application's actionable schema. If you have ever had to tell a teammate +> to manually perform any action on a production server, you've come across an issue that actions solves. ## Documentation From 56794b9d07fdbdec12340638c3cfc62404ac92df Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Wed, 12 Oct 2022 02:16:12 +0300 Subject: [PATCH 145/153] Update creating.md --- docs/getting-started/how-to-use/creating.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/getting-started/how-to-use/creating.md b/docs/getting-started/how-to-use/creating.md index 7c675ec0..9dc1879e 100644 --- a/docs/getting-started/how-to-use/creating.md +++ b/docs/getting-started/how-to-use/creating.md @@ -33,7 +33,7 @@ php artisan make:migration:action ## Nested Files -Since version `3.0` you can use nested paths to create actions: +You can use nested paths to create actions: ```bash php artisan make:migration:action Foo/Bar/QweRty From 0594576e3ff799455b85daf47cf662bb5ff48bff Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Wed, 12 Oct 2022 02:17:54 +0300 Subject: [PATCH 146/153] Update upgrade.md --- docs/prologue/upgrade.md | 46 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/docs/prologue/upgrade.md b/docs/prologue/upgrade.md index c92d7c82..baaa0261 100644 --- a/docs/prologue/upgrade.md +++ b/docs/prologue/upgrade.md @@ -45,3 +45,49 @@ It will do the following: - Replace the `up` method with `__invoke` if the class does not have a `down` method - Replace named classes with anonymous ones - Create a configuration file according to the data saved in your project + +> Note +> If you used inheritance of actions from other actions, then you will need to process these files manually. + +### Configuration + +Publish the config file and migrate the settings from the `config/database.php` file. + +```bash +php artisan vendor:publish --provider="DragonCode\LaravelActions\ServiceProvider" +``` + +### Actions Location + +Move the action files to the `actions` folder in the project root, or update the `actions.path` option in the configuration file. + + +### Parent Namespace + +Replace `DragonCode\LaravelActions\Support\Actionable` with `DragonCode\LaravelActions\Action`. + +### Anonymous Classes + +Replace named calls to your application's classes with anonymous ones. + +For example: + +```php +// before +use DragonCode\LaravelActions\Support\Actionable; + +class Some extends Actionable {} + +// after +use DragonCode\LaravelActions\Action; + +return new class () extends Action {}; +``` + +### Invokable Method + +If your class does not contain a `down` method, then you can replace the `up` method with `__invoke`. + +### Changed Migration Repository + +Just call the `php artisan migrate` command to make changes to the action repository table. From 41d17c8c7edceac10b730f53e14a797bf1184b54 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Wed, 12 Oct 2022 02:20:57 +0300 Subject: [PATCH 147/153] Update rollback.md --- docs/getting-started/how-to-use/rollback.md | 28 +++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/docs/getting-started/how-to-use/rollback.md b/docs/getting-started/how-to-use/rollback.md index 6752f109..7044da3b 100644 --- a/docs/getting-started/how-to-use/rollback.md +++ b/docs/getting-started/how-to-use/rollback.md @@ -18,6 +18,34 @@ The `migrate:actions:reset` command will roll back all of your application's mig php artisan migrate:actions:reset ``` +For example: + +```bash +php artisan migrate:actions:rollback +# action batch +# 2022_10_12_021837_some 1 +# 2022_10_12_021838_some 2 +# 2022_10_12_021839_some 2 +# 2022_10_12_021840_some 3 // will be canceled +# 2022_10_12_021841_some 3 // will be canceled + +php artisan migrate:actions:rollback --step=1 +# action batch +# 2022_10_12_021837_some 1 +# 2022_10_12_021838_some 2 +# 2022_10_12_021839_some 2 +# 2022_10_12_021840_some 3 // will be canceled +# 2022_10_12_021841_some 3 // will be canceled + +php artisan migrate:actions:rollback --step=2 +# action batch +# 2022_10_12_021837_some 1 +# 2022_10_12_021838_some 2 // will be canceled +# 2022_10_12_021839_some 2 // will be canceled +# 2022_10_12_021840_some 3 // will be canceled +# 2022_10_12_021841_some 3 // will be canceled +``` + ## Roll Back & Action Using A Single Command The `migrate:actions:refresh` command will roll back all of your migrations and then execute the `migrate:actions` command. This command effectively re-creates your entire From 42a21ea076be0ede614de4d0fae35357bebf98f7 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Wed, 12 Oct 2022 21:09:36 +0300 Subject: [PATCH 148/153] Added docs with vuepress --- .gitattributes | 2 + .gitignore | 13 +- .run/build.run.xml | 13 ++ .run/dev.run.xml | 13 ++ docs/.vuepress/.gitignore | 4 + docs/.vuepress/config.js | 122 ++++++++++++++++++ docs/.vuepress/public/CNAME | 1 + .../public/fonts/Nunito-SemiBold.woff2 | Bin 0 -> 56088 bytes docs/.vuepress/public/images/logo.svg | 63 +++++++++ docs/.vuepress/styles/_fonts.scss | 9 ++ docs/.vuepress/styles/index.scss | 13 ++ .../index.md} | 0 docs/{getting-started => }/helpers/artisan.md | 0 docs/{getting-started => }/helpers/events.md | 0 .../helpers/execution-status.md | 0 .../how-to-use/creating.md | 0 .../how-to-use/rollback.md | 0 .../how-to-use/running.md | 0 .../how-to-use/status.md | 0 docs/index.md | 20 +-- docs/prologue/changelog/3.x.md | 5 + docs/prologue/changelog/index.md | 3 + docs/prologue/license.md | 21 +++ package.json | 28 ++++ 24 files changed, 319 insertions(+), 11 deletions(-) create mode 100644 .run/build.run.xml create mode 100644 .run/dev.run.xml create mode 100644 docs/.vuepress/.gitignore create mode 100644 docs/.vuepress/config.js create mode 100644 docs/.vuepress/public/CNAME create mode 100644 docs/.vuepress/public/fonts/Nunito-SemiBold.woff2 create mode 100644 docs/.vuepress/public/images/logo.svg create mode 100644 docs/.vuepress/styles/_fonts.scss create mode 100644 docs/.vuepress/styles/index.scss rename docs/getting-started/{installation.md => installation/index.md} (100%) rename docs/{getting-started => }/helpers/artisan.md (100%) rename docs/{getting-started => }/helpers/events.md (100%) rename docs/{getting-started => }/helpers/execution-status.md (100%) rename docs/{getting-started => }/how-to-use/creating.md (100%) rename docs/{getting-started => }/how-to-use/rollback.md (100%) rename docs/{getting-started => }/how-to-use/running.md (100%) rename docs/{getting-started => }/how-to-use/status.md (100%) create mode 100644 docs/prologue/changelog/3.x.md create mode 100644 docs/prologue/changelog/index.md create mode 100644 docs/prologue/license.md create mode 100644 package.json diff --git a/.gitattributes b/.gitattributes index 3a55538c..a33e50e1 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,6 +1,7 @@ * text=auto .github/ export-ignore +.run/ export-ignore docs/ export-ignore tests/ export-ignore @@ -8,4 +9,5 @@ tests/ export-ignore .gitattributes export-ignore .gitignore export-ignore +package.json export-ignore phpunit.xml export-ignore diff --git a/.gitignore b/.gitignore index ba34f846..227cca8b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,16 @@ .idea/ -vendor/ +_site/ build/ +node_modules/ +tmp/ +vendor/ + +.cache +.DS_Store +.env +.php_cs.cache +.phpintel +.temp *.bak *.cache @@ -8,3 +18,4 @@ build/ *.orig composer.lock +package-lock.json diff --git a/.run/build.run.xml b/.run/build.run.xml new file mode 100644 index 00000000..2c9d697a --- /dev/null +++ b/.run/build.run.xml @@ -0,0 +1,13 @@ + + + + + +