|
16 | 16 | use Cake\Chronos\ChronosDate; |
17 | 17 | use Cake\Core\Configure; |
18 | 18 | use Cake\Database\Driver\Postgres; |
| 19 | +use Cake\Database\Schema\TableSchema; |
19 | 20 | use Cake\Datasource\ConnectionManager; |
20 | 21 | use Cake\TestSuite\ConnectionHelper; |
21 | 22 | use Cake\TestSuite\TestCase; |
@@ -55,6 +56,47 @@ protected function getMigratorWhereClause(): array |
55 | 56 | : []; |
56 | 57 | } |
57 | 58 |
|
| 59 | + protected function makeInspectableMigrator(): Migrator |
| 60 | + { |
| 61 | + return new class () extends Migrator { |
| 62 | + /** |
| 63 | + * @return array<string> |
| 64 | + */ |
| 65 | + public function exposedGetMigrationTables(string $connection): array |
| 66 | + { |
| 67 | + return array_values($this->getMigrationTables($connection)); |
| 68 | + } |
| 69 | + |
| 70 | + /** |
| 71 | + * @return array<string> |
| 72 | + */ |
| 73 | + public function exposedGetNonPhinxTables(string $connection, array $skip = []): array |
| 74 | + { |
| 75 | + return array_values($this->getNonPhinxTables($connection, $skip)); |
| 76 | + } |
| 77 | + }; |
| 78 | + } |
| 79 | + |
| 80 | + protected function createPortableTable(string $name, bool $withPlugin = false): void |
| 81 | + { |
| 82 | + $connection = ConnectionManager::get('test'); |
| 83 | + $schema = new TableSchema($name); |
| 84 | + $schema |
| 85 | + ->addColumn('version', ['type' => 'biginteger', 'null' => false]) |
| 86 | + ->addColumn('migration_name', ['type' => 'string', 'limit' => 100, 'null' => false]) |
| 87 | + ->addColumn('start_time', ['type' => 'timestamp', 'default' => null, 'null' => true]) |
| 88 | + ->addColumn('end_time', ['type' => 'timestamp', 'default' => null, 'null' => true]) |
| 89 | + ->addColumn('breakpoint', ['type' => 'boolean', 'default' => false, 'null' => false]); |
| 90 | + |
| 91 | + if ($withPlugin) { |
| 92 | + $schema->addColumn('plugin', ['type' => 'string', 'limit' => 100, 'default' => null, 'null' => true]); |
| 93 | + } |
| 94 | + |
| 95 | + foreach ($schema->createSql($connection) as $statement) { |
| 96 | + $connection->execute($statement); |
| 97 | + } |
| 98 | + } |
| 99 | + |
58 | 100 | protected function setUp(): void |
59 | 101 | { |
60 | 102 | parent::setUp(); |
@@ -95,6 +137,32 @@ public function testMigrateDropTruncate(): void |
95 | 137 | $this->assertCount(0, $connection->selectQuery()->select(['*'])->from('migrator')->execute()->fetchAll()); |
96 | 138 | } |
97 | 139 |
|
| 140 | + public function testGetMigrationTablesIncludesUnifiedLedger(): void |
| 141 | + { |
| 142 | + $this->skipIf(Configure::read('Migrations.legacyTables') !== false); |
| 143 | + |
| 144 | + $connection = ConnectionManager::get('test'); |
| 145 | + $connection->execute('CREATE TABLE sample_table (id INT)'); |
| 146 | + $this->createPortableTable('cake_migrations', true); |
| 147 | + |
| 148 | + $migrator = $this->makeInspectableMigrator(); |
| 149 | + |
| 150 | + $this->assertSame(['cake_migrations'], $migrator->exposedGetMigrationTables('test')); |
| 151 | + $this->assertSame(['sample_table'], $migrator->exposedGetNonPhinxTables('test')); |
| 152 | + } |
| 153 | + |
| 154 | + public function testGetMigrationTablesIncludesLegacyLedger(): void |
| 155 | + { |
| 156 | + $connection = ConnectionManager::get('test'); |
| 157 | + $connection->execute('CREATE TABLE sample_table (id INT)'); |
| 158 | + $this->createPortableTable('app_phinxlog'); |
| 159 | + |
| 160 | + $migrator = $this->makeInspectableMigrator(); |
| 161 | + |
| 162 | + $this->assertSame(['app_phinxlog'], $migrator->exposedGetMigrationTables('test')); |
| 163 | + $this->assertSame(['sample_table'], $migrator->exposedGetNonPhinxTables('test')); |
| 164 | + } |
| 165 | + |
98 | 166 | public function testMigrateDropNoTruncate(): void |
99 | 167 | { |
100 | 168 | $migrator = new Migrator(); |
|
0 commit comments