From cd9bff3fdd3d4bc8d22563446d806969fbcfd77d Mon Sep 17 00:00:00 2001 From: Kevin Pfeifer Date: Mon, 16 Nov 2026 19:06:39 +0100 Subject: [PATCH] Add PHP 8.6 compatibility --- .github/workflows/ci.yml | 2 +- composer.json | 6 ++--- rector.php | 5 +++++ src/Command/BakeSimpleMigrationCommand.php | 5 +++-- .../Command/BakeMigrationCommandTest.php | 22 ++++++++++++++++--- tests/TestCase/Migration/ManagerTest.php | 2 +- 6 files changed, 32 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b1ca9ed4..9792bcf8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,7 +25,7 @@ jobs: strategy: fail-fast: false matrix: - php-version: ['8.2', '8.5'] + php-version: ['8.2', '8.5', '8.6'] db-type: [mariadb, mysql, pgsql, sqlite] prefer-lowest: [''] legacy-tables: [''] diff --git a/composer.json b/composer.json index d4e58905..303e0e20 100644 --- a/composer.json +++ b/composer.json @@ -24,12 +24,12 @@ "require": { "php": ">=8.2", "cakephp/cache": "^5.3.0", - "cakephp/database": "^5.3.2", + "cakephp/database": "^5.4.4", "cakephp/orm": "^5.3.0" }, "require-dev": { "cakephp/bake": "^3.3", - "cakephp/cakephp": "^5.3.0", + "cakephp/cakephp": "^5.4.4", "cakephp/cakephp-codesniffer": "^5.0", "phpunit/phpunit": "^11.5.3 || ^12.1.3 || ^13.0" }, @@ -76,7 +76,7 @@ "stan-setup": "phive install", "lowest": "validate-prefer-lowest", "lowest-setup": "composer update --prefer-lowest --prefer-stable --prefer-dist --no-interaction && cp composer.json composer.backup && composer require --dev dereuromark/composer-prefer-lowest && mv composer.backup composer.json", - "rector-setup": "cp composer.json composer.backup && composer require --dev rector/rector:\"~2.7.0\" phpstan/phpstan:\"~2.3.0\" && mv composer.backup composer.json", + "rector-setup": "cp composer.json composer.backup && composer require --dev rector/rector:\"~2.7.0\" phpstan/phpstan:\"2.3.0\" && mv composer.backup composer.json", "rector-check": "vendor/bin/rector process --dry-run", "rector-fix": "vendor/bin/rector process", "test": "phpunit", diff --git a/rector.php b/rector.php index fd378e4a..b3b31f8a 100644 --- a/rector.php +++ b/rector.php @@ -17,6 +17,7 @@ use Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector; use Rector\Set\ValueObject\SetList; use Rector\TypeDeclaration\Rector\Class_\TypedPropertyFromCreateMockAssignRector; +use Rector\TypeDeclaration\Rector\ClassMethod\AddReturnTypeDeclarationBasedOnParentClassMethodRector; use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictFluentReturnRector; $cacheDir = getenv('RECTOR_CACHE_DIR') ?: sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'rector'; @@ -45,6 +46,10 @@ ]) ->withSkip([ + // Keep Config::offsetGet() compatible with subclasses that omit its return type. + AddReturnTypeDeclarationBasedOnParentClassMethodRector::class => [ + __DIR__ . '/src/Config/Config.php', + ], ClassPropertyAssignToConstructorPromotionRector::class, CatchExceptionNameMatchingTypeRector::class, ClosureToArrowFunctionRector::class, diff --git a/src/Command/BakeSimpleMigrationCommand.php b/src/Command/BakeSimpleMigrationCommand.php index b85f0f7e..ea5bdadf 100644 --- a/src/Command/BakeSimpleMigrationCommand.php +++ b/src/Command/BakeSimpleMigrationCommand.php @@ -39,7 +39,8 @@ abstract class BakeSimpleMigrationCommand extends SimpleBakeCommand 'continue', 'declare', 'default', 'die', 'do', 'echo', 'else', 'elseif', 'empty', 'enddeclare', 'endfor', 'endforeach', 'endif', 'endswitch', 'endwhile', 'eval', 'exit', 'extends', 'final', 'finally', 'for', 'foreach', 'function', 'global', 'goto', 'if', 'implements', 'include', 'include_once', 'instanceof', 'insteadof', 'interface', - 'isset', 'list', 'namespace', 'new', 'or', 'parent', 'private', 'protected', 'public', 'return','static', + 'is', 'isset', 'let', 'list', 'namespace', 'new', 'or', 'parent', 'private', 'protected', 'public', + 'return', 'static', ]; /** @@ -181,8 +182,8 @@ protected function bake(string $name, Arguments $args, ConsoleIo $io): void } $renderer = new TemplateRenderer($this->theme); - $renderer->set('name', $name); $renderer->set($this->templateData($args)); + $renderer->set('name', $name); $contents = $renderer->generate($this->template()); diff --git a/tests/TestCase/Command/BakeMigrationCommandTest.php b/tests/TestCase/Command/BakeMigrationCommandTest.php index aa1fd0f6..b4c660bf 100644 --- a/tests/TestCase/Command/BakeMigrationCommandTest.php +++ b/tests/TestCase/Command/BakeMigrationCommandTest.php @@ -144,12 +144,28 @@ public function testCreateDuplicateName(): void /** * Tests that baking a migration with the name as reserved keyword triggers prefixing. */ - public function testCreateWithReservedKeyword(): void + #[DataProvider('reservedMigrationNames')] + public function testCreateWithReservedKeyword(string $name, string $className): void { - $this->exec('bake migration New --connection test', ['Prefix']); + $this->exec(sprintf('bake migration %s --connection test', $name), ['Prefix']); + $files = glob(ROOT . DS . 'config' . DS . 'Migrations' . DS . '*_Prefix' . $className . '.php'); + $this->generatedFile = current($files); $this->assertExitCode(BaseCommand::CODE_SUCCESS); - $this->assertOutputRegExp('/Wrote.*?PrefixNew\.php/'); + $this->assertOutputRegExp('/Wrote.*?Prefix' . $className . '\.php/'); + $this->assertFileContains('class Prefix' . $className . ' extends BaseMigration', $this->generatedFile); + } + + /** + * @return array + */ + public static function reservedMigrationNames(): array + { + return [ + 'new' => ['New', 'New'], + 'let' => ['let', 'Let'], + 'is' => ['IS', 'IS'], + ]; } public function testCreateBuiltInAlias(): void diff --git a/tests/TestCase/Migration/ManagerTest.php b/tests/TestCase/Migration/ManagerTest.php index 8d88b575..5d51988b 100644 --- a/tests/TestCase/Migration/ManagerTest.php +++ b/tests/TestCase/Migration/ManagerTest.php @@ -941,7 +941,7 @@ public function testRollbackToVersionByName(array $availableRollbacks, ?string $ $this->manager = new Manager($config, $this->io); $this->manager->setEnvironment($envStub); - $this->manager->rollback($availableRollbacks[$version]['migration_name'] ?? $version); + $this->manager->rollback($availableRollbacks[(string)$version]['migration_name'] ?? $version); $output = $this->getOutput();