Skip to content

Commit

Permalink
Add rector rules to update migration base classes (#304)
Browse files Browse the repository at this point in the history
Part of the work to separate migrations from phinx
  • Loading branch information
markstory authored Dec 20, 2024
1 parent b0a7b72 commit 29eed0a
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
DEV_DEPENDENCIES = cakephp/cakephp:5.x-dev \
cakephp/cakephp-codesniffer:^5.0 \
mikey179/vfsstream:^1.6.8 \
phpunit/phpunit:^10.5.38
phpunit/phpunit:^10.5.38 \
cakephp/migrations:^4.5.0

install-dev:
composer require --dev $(DEV_DEPENDENCIES)
Expand Down
9 changes: 9 additions & 0 deletions config/rector/migrations45.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
declare(strict_types=1);

use Cake\Upgrade\Rector\Set\CakePHPSetList;
use Rector\Config\RectorConfig;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->sets([CakePHPSetList::MIGRATIONS_45]);
};
15 changes: 15 additions & 0 deletions config/rector/sets/migrations45.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\Renaming\Rector\Name\RenameClassRector;

/**
* @see https://github.com/cakephp/migrations/releases/4.5.0/
*/
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->ruleWithConfiguration(RenameClassRector::class, [
'Migrations\AbstractMigration' => 'Migrations\BaseMigration',
'Migrations\AbstractSeed' => 'Migrations\BaseSeed',
]);
};
5 changes: 5 additions & 0 deletions src/Rector/Set/CakePHPSetList.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ final class CakePHPSetList
*/
public const CHRONOS_3 = __DIR__ . '/../../../config/rector/sets/chronos3.php';

/**
* @var string
*/
public const MIGRATIONS_45 = __DIR__ . '/../../../config/rector/sets/migrations45.php';

/**
* @var string
*/
Expand Down
7 changes: 7 additions & 0 deletions tests/TestCase/Command/RectorCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,11 @@ public function testApply52()
$this->exec('upgrade rector --rules cakephp52 ' . TEST_APP);
$this->assertTestAppUpgraded();
}

public function testApplyMigrations45()
{
$this->setupTestApp(__FUNCTION__);
$this->exec('upgrade rector --rules migrations45 ' . TEST_APP);
$this->assertTestAppUpgraded();
}
}
2 changes: 2 additions & 0 deletions tests/TestCase/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class TestCase extends BaseTestCase
{
use ConsoleIntegrationTestTrait;

public $appPluginsToLoad = [];

/**
* @var string
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
use Migrations\AbstractMigration;
use Migrations\AbstractSeed;

class Migrations45 extends AbstractMigration {
public function change() {
}
}

class Seed45 extends AbstractSeed {
public function run() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
use Migrations\AbstractMigration;
use Migrations\AbstractSeed;

class Migrations45 extends \Migrations\BaseMigration {
public function change() {
}
}

class Seed45 extends \Migrations\BaseSeed {
public function run() {
}
}

0 comments on commit 29eed0a

Please sign in to comment.