diff --git a/packages/console/src/Testing/ConsoleTester.php b/packages/console/src/Testing/ConsoleTester.php index e8edf7975..e19d70eda 100644 --- a/packages/console/src/Testing/ConsoleTester.php +++ b/packages/console/src/Testing/ConsoleTester.php @@ -320,4 +320,11 @@ public function dd(): self return $this; } + + public function dump(): self + { + lw($this->output->asUnformattedString()); + + return $this; + } } diff --git a/rector.php b/rector.php index 4e86569fd..e9731eeed 100644 --- a/rector.php +++ b/rector.php @@ -5,13 +5,11 @@ use Rector\Arguments\Rector\ClassMethod\ArgumentAdderRector; use Rector\Caching\ValueObject\Storage\FileCacheStorage; use Rector\CodingStyle\Rector\Encapsed\EncapsedStringsToSprintfRector; -use Rector\CodingStyle\Rector\Stmt\NewlineAfterStatementRector; use Rector\Config\RectorConfig; use Rector\DeadCode\Rector\PropertyProperty\RemoveNullPropertyInitializationRector; use Rector\Php70\Rector\StaticCall\StaticCallOnNonStaticToInstanceCallRector; use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector; use Rector\Php74\Rector\Property\RestoreDefaultNullToNullableTypePropertyRector; -use Rector\Php74\Rector\Ternary\ParenthesizeNestedTernaryRector; use Rector\Php81\Rector\Array_\FirstClassCallableRector; use Rector\Php81\Rector\FuncCall\NullToStrictStringFuncCallArgRector; use Rector\Php81\Rector\Property\ReadOnlyPropertyRector; @@ -19,6 +17,7 @@ use Rector\Php82\Rector\Param\AddSensitiveParameterAttributeRector; use Rector\Php83\Rector\ClassMethod\AddOverrideAttributeToOverriddenMethodsRector; use Rector\Php84\Rector\Param\ExplicitNullableParamTypeRector; +use Rector\Renaming\Rector\Name\RenameClassRector; use Rector\TypeDeclaration\Rector\ArrowFunction\AddArrowFunctionReturnTypeRector; use Rector\TypeDeclaration\Rector\ClassMethod\ReturnNeverTypeRector; use Rector\TypeDeclaration\Rector\Closure\ClosureReturnTypeRector; @@ -36,6 +35,9 @@ 'secret', ], ]) + ->withConfiguredRule(RenameClassRector::class, [ + 'Tempest\\Database\\Id' => 'Tempest\\Database\\PrimaryKey', + ]) ->withRules([ ExplicitNullableParamTypeRector::class, ]) diff --git a/src/Tempest/Framework/Commands/UpgradeCommand.php b/src/Tempest/Framework/Commands/UpgradeCommand.php new file mode 100644 index 000000000..2b7fa4489 --- /dev/null +++ b/src/Tempest/Framework/Commands/UpgradeCommand.php @@ -0,0 +1,77 @@ +console->info('Dry run enabled'); + $command .= ' --dry-run'; + } + + $rectors = $this->getRectorsForVersion($version); + if (! $rectors->valid()) { + $this->console->info('No rectors found for this version'); + + return ExitCode::SUCCESS; + } + + foreach ($rectors as $rule) { + $command .= " --only=\"{$rule}\""; + } + + $this->console->info("Running {$command}"); + try { + $processed = Process::fromShellCommandline($command)->mustRun(); + } catch (ProcessFailedException $e) { + $this->console->error($e->getProcess()->getErrorOutput()); + + return ExitCode::ERROR; + } + + $this->console->info(trim($processed->getOutput())); + + return ExitCode::SUCCESS; + } + + private function getRectorsForVersion(string $version): \Generator + { + return match (true) { + Semver::satisfies($version, '^1.0.0') => [], + Semver::satisfies($version, '^2.0.0') => [ + yield 'Rector\Renaming\Rector\Name\RenameClassRector', + ], + default => [], + }; + } +} diff --git a/tests/Integration/Console/Commands/UpgradeCommandTest.php b/tests/Integration/Console/Commands/UpgradeCommandTest.php new file mode 100644 index 000000000..9513feded --- /dev/null +++ b/tests/Integration/Console/Commands/UpgradeCommandTest.php @@ -0,0 +1,32 @@ +console + ->call('upgrade:tempest', ['version' => 'v1.0.0', 'dry-run' => true]) + ->assertContains(' No rectors found for this version') + ->assertExitCode(ExitCode::SUCCESS); + } + + #[Test] + public function upgrade_to_v2(): void + { + $this->console + ->call('upgrade:tempest', ['version' => 'v2.0.0', 'dry-run' => true]) + ->assertContains('vendor/bin/rector --no-ansi --no-progress-bar --no-diffs --dry-run --only="Rector\Renaming\Rector\Name\RenameClassRector"') + ->assertContains('[OK] Rector is done!') + ->dump() + ->assertExitCode(ExitCode::SUCCESS); + } +}