diff --git a/composer.json b/composer.json index 0962fade..48622a77 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,7 @@ }, "require-dev": { "phpunit/phpunit": "^9.5.0", - "cakephp/cakephp": "^4.3.0", + "cakephp/cakephp": "^4.5.0", "cakephp/bake": "^2.6.0", "cakephp/cakephp-codesniffer": "^4.1" }, diff --git a/src/Command/BakeMigrationDiffCommand.php b/src/Command/BakeMigrationDiffCommand.php index 6fc28f15..e53b3408 100644 --- a/src/Command/BakeMigrationDiffCommand.php +++ b/src/Command/BakeMigrationDiffCommand.php @@ -144,17 +144,16 @@ protected function setup(Arguments $args) $this->migrationsFiles = glob($this->migrationsPath . '*.php') ?: []; $this->phinxTable = $this->getPhinxTable($this->plugin); + /** @var \Cake\Database\Connection $connection */ $connection = ConnectionManager::get($this->connection); $this->tables = $connection->getSchemaCollection()->listTables(); $tableExists = in_array($this->phinxTable, $this->tables, true); $migratedItems = []; if ($tableExists) { - $query = $connection->newQuery(); /** @var array $migratedItems */ - $migratedItems = $query - ->select(['version']) - ->from($this->phinxTable) + $migratedItems = $connection + ->selectQuery(['version'], $this->phinxTable) ->order(['version DESC']) ->execute()->fetchAll('assoc'); } diff --git a/tests/TestCase/Command/BakeMigrationDiffCommandTest.php b/tests/TestCase/Command/BakeMigrationDiffCommandTest.php index 6bd5dd15..2f400101 100644 --- a/tests/TestCase/Command/BakeMigrationDiffCommandTest.php +++ b/tests/TestCase/Command/BakeMigrationDiffCommandTest.php @@ -148,8 +148,7 @@ public function testBakingDiff() copy($diffDumpPath, $destinationDumpPath); $connection = ConnectionManager::get('test_comparisons'); - $connection->newQuery() - ->delete('phinxlog') + $connection->deleteQuery('phinxlog') ->where(['version' => 20160415220805]) ->execute(); @@ -177,9 +176,8 @@ public function testBakingDiff() rename($destinationConfigDir . $generatedMigration, $destination); $versionParts = explode('_', $generatedMigration); - $connection->newQuery() + $connection->insertQuery('phinxlog') ->insert(['version', 'migration_name', 'start_time', 'end_time']) - ->into('phinxlog') ->values([ 'version' => 20160415220805, 'migration_name' => $versionParts[1], @@ -224,8 +222,7 @@ public function testBakingDiffSimple() copy($diffDumpPath, $destinationDumpPath); $connection = ConnectionManager::get('test_comparisons'); - $connection->newQuery() - ->delete('phinxlog') + $connection->deleteQuery('phinxlog') ->where(['version' => 20160415220805]) ->execute(); @@ -245,9 +242,8 @@ public function testBakingDiffSimple() rename($destinationConfigDir . $generatedMigration, $destination); $versionParts = explode('_', $generatedMigration); - $connection->newQuery() + $connection->insertQuery('phinxlog') ->insert(['version', 'migration_name', 'start_time', 'end_time']) - ->into('phinxlog') ->values([ 'version' => 20160415220805, 'migration_name' => $versionParts[1], @@ -288,8 +284,7 @@ public function testBakingDiffAddRemove() copy($diffDumpPath, $destinationDumpPath); $connection = ConnectionManager::get('test_comparisons'); - $connection->newQuery() - ->delete('phinxlog') + $connection->deleteQuery('phinxlog') ->where(['version' => 20160415220805]) ->execute(); @@ -310,9 +305,8 @@ public function testBakingDiffAddRemove() rename($destinationConfigDir . $generatedMigration, $destination); $versionParts = explode('_', $generatedMigration); - $connection->newQuery() + $connection->insertQuery('phinxlog') ->insert(['version', 'migration_name', 'start_time', 'end_time']) - ->into('phinxlog') ->values([ 'version' => 20160415220805, 'migration_name' => $versionParts[1], diff --git a/tests/TestCase/Command/CompletionTest.php b/tests/TestCase/Command/CompletionTest.php index 9ce4d9d2..bebe5d86 100644 --- a/tests/TestCase/Command/CompletionTest.php +++ b/tests/TestCase/Command/CompletionTest.php @@ -13,7 +13,7 @@ */ namespace Migrations\Test\TestCase\Command; -use Cake\TestSuite\ConsoleIntegrationTestTrait; +use Cake\Console\TestSuite\ConsoleIntegrationTestTrait; use Cake\TestSuite\TestCase; /** diff --git a/tests/TestCase/Command/Phinx/DumpTest.php b/tests/TestCase/Command/Phinx/DumpTest.php index 1225efc6..31e99927 100644 --- a/tests/TestCase/Command/Phinx/DumpTest.php +++ b/tests/TestCase/Command/Phinx/DumpTest.php @@ -75,7 +75,7 @@ public function setUp(): void parent::setUp(); $this->connection = ConnectionManager::get('test'); - $this->connection->connect(); + $this->connection->getDriver()->connect(); $this->pdo = $this->connection->getDriver()->getConnection(); $application = new MigrationsDispatcher('testing'); $this->command = $application->find('dump'); diff --git a/tests/TestCase/Command/Phinx/MarkMigratedTest.php b/tests/TestCase/Command/Phinx/MarkMigratedTest.php index 826de32a..2ad86a39 100644 --- a/tests/TestCase/Command/Phinx/MarkMigratedTest.php +++ b/tests/TestCase/Command/Phinx/MarkMigratedTest.php @@ -62,7 +62,7 @@ public function setUp(): void parent::setUp(); $this->connection = ConnectionManager::get('test'); - $this->connection->connect(); + $this->connection->getDriver()->connect(); $this->pdo = $this->connection->getDriver()->getConnection(); $this->connection->execute('DROP TABLE IF EXISTS phinxlog'); $this->connection->execute('DROP TABLE IF EXISTS numbers'); @@ -110,7 +110,7 @@ public function testExecute() $this->commandTester->getDisplay() ); - $result = $this->connection->newQuery()->select(['*'])->from('phinxlog')->execute()->fetchAll('assoc'); + $result = $this->connection->selectQuery(['*'], 'phinxlog')->execute()->fetchAll('assoc'); $this->assertEquals('20150704160200', $result[0]['version']); $this->assertEquals('20150724233100', $result[1]['version']); $this->assertEquals('20150826191400', $result[2]['version']); @@ -134,7 +134,7 @@ public function testExecute() $this->commandTester->getDisplay() ); - $result = $this->connection->newQuery()->select(['*'])->from('phinxlog')->execute()->count(); + $result = $this->connection->selectQuery(['*'], 'phinxlog')->execute()->count(); $this->assertSame(3, $result); $config = $this->command->getConfig(); @@ -202,7 +202,7 @@ public function testExecuteAll() $this->commandTester->getDisplay() ); - $result = $this->connection->newQuery()->select(['*'])->from('phinxlog')->execute()->fetchAll('assoc'); + $result = $this->connection->selectQuery(['*'], 'phinxlog')->execute()->fetchAll('assoc'); $this->assertEquals('20150704160200', $result[0]['version']); $this->assertEquals('20150724233100', $result[1]['version']); $this->assertEquals('20150826191400', $result[2]['version']); @@ -246,7 +246,7 @@ public function testExecuteTarget() $this->commandTester->getDisplay() ); - $result = $this->connection->newQuery()->select(['*'])->from('phinxlog')->execute()->fetchAll('assoc'); + $result = $this->connection->selectQuery(['*'], 'phinxlog')->execute()->fetchAll('assoc'); $this->assertEquals('20150704160200', $result[0]['version']); $this->commandTester->execute([ @@ -269,11 +269,11 @@ public function testExecuteTarget() $this->commandTester->getDisplay() ); - $result = $this->connection->newQuery()->select(['*'])->from('phinxlog')->execute()->fetchAll('assoc'); + $result = $this->connection->selectQuery(['*'], 'phinxlog')->execute()->fetchAll('assoc'); $this->assertEquals('20150704160200', $result[0]['version']); $this->assertEquals('20150724233100', $result[1]['version']); $this->assertEquals('20150826191400', $result[2]['version']); - $result = $this->connection->newQuery()->select(['*'])->from('phinxlog')->execute()->count(); + $result = $this->connection->selectQuery(['*'], 'phinxlog')->execute()->count(); $this->assertSame(3, $result); $this->commandTester->execute([ @@ -304,7 +304,7 @@ public function testExecuteTargetWithExclude() $this->commandTester->getDisplay() ); - $result = $this->connection->newQuery()->select(['*'])->from('phinxlog')->execute()->fetchAll('assoc'); + $result = $this->connection->selectQuery(['*'], 'phinxlog')->execute()->fetchAll('assoc'); $this->assertEquals('20150704160200', $result[0]['version']); $this->commandTester->execute([ @@ -324,10 +324,10 @@ public function testExecuteTargetWithExclude() $this->commandTester->getDisplay() ); - $result = $this->connection->newQuery()->select(['*'])->from('phinxlog')->execute()->fetchAll('assoc'); + $result = $this->connection->selectQuery(['*'], 'phinxlog')->execute()->fetchAll('assoc'); $this->assertEquals('20150704160200', $result[0]['version']); $this->assertEquals('20150724233100', $result[1]['version']); - $result = $this->connection->newQuery()->select(['*'])->from('phinxlog')->execute()->count(); + $result = $this->connection->selectQuery(['*'], 'phinxlog')->execute()->count(); $this->assertSame(2, $result); $this->commandTester->execute([ @@ -359,7 +359,7 @@ public function testExecuteTargetWithOnly() $this->commandTester->getDisplay() ); - $result = $this->connection->newQuery()->select(['*'])->from('phinxlog')->execute()->fetchAll('assoc'); + $result = $this->connection->selectQuery(['*'], 'phinxlog')->execute()->fetchAll('assoc'); $this->assertEquals('20150724233100', $result[0]['version']); $this->commandTester->execute([ @@ -375,10 +375,10 @@ public function testExecuteTargetWithOnly() $this->commandTester->getDisplay() ); - $result = $this->connection->newQuery()->select(['*'])->from('phinxlog')->execute()->fetchAll('assoc'); + $result = $this->connection->selectQuery(['*'], 'phinxlog')->execute()->fetchAll('assoc'); $this->assertEquals('20150826191400', $result[1]['version']); $this->assertEquals('20150724233100', $result[0]['version']); - $result = $this->connection->newQuery()->select(['*'])->from('phinxlog')->execute()->count(); + $result = $this->connection->selectQuery(['*'], 'phinxlog')->execute()->count(); $this->assertSame(2, $result); $this->commandTester->execute([ @@ -414,7 +414,7 @@ public function testExecuteWithVersionAsArgument() $this->commandTester->getDisplay() ); - $result = $this->connection->newQuery()->select(['*'])->from('phinxlog')->execute()->fetchAll('assoc'); + $result = $this->connection->selectQuery(['*'], 'phinxlog')->execute()->fetchAll('assoc'); $this->assertSame(1, count($result)); $this->assertEquals('20150724233100', $result[0]['version']); } @@ -428,7 +428,7 @@ public function testExecuteInvalidUseOfOnlyAndExclude() '--source' => 'TestsMigrations', ]); - $result = $this->connection->newQuery()->select(['*'])->from('phinxlog')->execute()->count(); + $result = $this->connection->selectQuery(['*'], 'phinxlog')->execute()->count(); $this->assertSame(0, $result); $this->assertStringContainsString( 'You should use `--exclude` OR `--only` (not both) along with a `--target` !', @@ -442,7 +442,7 @@ public function testExecuteInvalidUseOfOnlyAndExclude() '--source' => 'TestsMigrations', ]); - $result = $this->connection->newQuery()->select(['*'])->from('phinxlog')->execute()->count(); + $result = $this->connection->selectQuery(['*'], 'phinxlog')->execute()->count(); $this->assertSame(0, $result); $this->assertStringContainsString( 'You should use `--exclude` OR `--only` (not both) along with a `--target` !', @@ -458,7 +458,7 @@ public function testExecuteInvalidUseOfOnlyAndExclude() '--source' => 'TestsMigrations', ]); - $result = $this->connection->newQuery()->select(['*'])->from('phinxlog')->execute()->count(); + $result = $this->connection->selectQuery(['*'], 'phinxlog')->execute()->count(); $this->assertSame(0, $result); $this->assertStringContainsString( 'You should use `--exclude` OR `--only` (not both) along with a `--target` !', diff --git a/tests/TestCase/Command/Phinx/SeedTest.php b/tests/TestCase/Command/Phinx/SeedTest.php index 82bbd76f..fdaaa78b 100644 --- a/tests/TestCase/Command/Phinx/SeedTest.php +++ b/tests/TestCase/Command/Phinx/SeedTest.php @@ -64,7 +64,7 @@ public function setUp(): void parent::setUp(); $this->connection = ConnectionManager::get('test'); - $this->connection->connect(); + $this->connection->getDriver()->connect(); $this->pdo = $this->connection->getDriver()->getConnection(); $application = new MigrationsDispatcher('testing'); $this->command = $application->find('seed'); @@ -106,9 +106,8 @@ public function testExecute() $display = $this->getDisplayFromOutput(); $this->assertTextContains('== NumbersSeed: seeded', $display); - $result = $this->connection->newQuery() - ->select(['*']) - ->from('numbers') + $result = $this->connection + ->selectQuery(['*'], 'numbers') ->order('id DESC') ->limit(1) ->execute()->fetchAll('assoc'); @@ -148,9 +147,8 @@ public function testExecuteCustomParams() $display = $this->getDisplayFromOutput(); $this->assertTextContains('== NumbersAltSeed: seeded', $display); - $result = $this->connection->newQuery() - ->select(['*']) - ->from('numbers') + $result = $this->connection + ->selectQuery(['*'], 'numbers') ->order('id DESC') ->limit(1) ->execute()->fetchAll('assoc'); diff --git a/tests/TestCase/Command/Phinx/StatusTest.php b/tests/TestCase/Command/Phinx/StatusTest.php index 1655d446..0a0ae187 100644 --- a/tests/TestCase/Command/Phinx/StatusTest.php +++ b/tests/TestCase/Command/Phinx/StatusTest.php @@ -71,7 +71,7 @@ public function setUp(): void parent::setUp(); $this->Connection = ConnectionManager::get('test'); - $this->Connection->connect(); + $this->Connection->getDriver()->connect(); $this->pdo = $this->Connection->getDriver()->getConnection(); $this->Connection->execute('DROP TABLE IF EXISTS phinxlog'); $this->Connection->execute('DROP TABLE IF EXISTS numbers'); diff --git a/tests/TestCase/MigrationsTest.php b/tests/TestCase/MigrationsTest.php index 493798fc..ad3d79ed 100644 --- a/tests/TestCase/MigrationsTest.php +++ b/tests/TestCase/MigrationsTest.php @@ -687,10 +687,10 @@ public function testSeed() $seed = $this->migrations->seed(['source' => 'Seeds']); $this->assertTrue($seed); - $result = $this->Connection->newQuery() - ->select(['*']) - ->from('numbers') - ->execute()->fetchAll('assoc'); + $result = $this->Connection + ->selectQuery(['*'], 'numbers') + ->execute() + ->fetchAll('assoc'); $expected = [ [ 'id' => '1', @@ -702,10 +702,10 @@ public function testSeed() $seed = $this->migrations->seed(['source' => 'Seeds']); $this->assertTrue($seed); - $result = $this->Connection->newQuery() - ->select(['*']) - ->from('numbers') - ->execute()->fetchAll('assoc'); + $result = $this->Connection + ->selectQuery(['*'], 'numbers') + ->execute() + ->fetchAll('assoc'); $expected = [ [ 'id' => '1', @@ -722,10 +722,10 @@ public function testSeed() $seed = $this->migrations->seed(['source' => 'AltSeeds']); $this->assertTrue($seed); - $result = $this->Connection->newQuery() - ->select(['*']) - ->from('numbers') - ->execute()->fetchAll('assoc'); + $result = $this->Connection + ->selectQuery(['*'], 'numbers') + ->execute() + ->fetchAll('assoc'); $expected = [ [ 'id' => '1', @@ -763,10 +763,10 @@ public function testSeedOneSeeder() $seed = $this->migrations->seed(['source' => 'AltSeeds', 'seed' => 'AnotherNumbersSeed']); $this->assertTrue($seed); - $result = $this->Connection->newQuery() - ->select(['*']) - ->from('numbers') - ->execute()->fetchAll('assoc'); + $result = $this->Connection + ->selectQuery(['*'], 'numbers') + ->execute() + ->fetchAll('assoc'); $expected = [ [ @@ -779,10 +779,10 @@ public function testSeedOneSeeder() $seed = $this->migrations->seed(['source' => 'AltSeeds', 'seed' => 'NumbersAltSeed']); $this->assertTrue($seed); - $result = $this->Connection->newQuery() - ->select(['*']) - ->from('numbers') - ->execute()->fetchAll('assoc'); + $result = $this->Connection + ->selectQuery(['*'], 'numbers') + ->execute() + ->fetchAll('assoc'); $expected = [ [ @@ -812,10 +812,10 @@ public function testSeedCallSeeder() $seed = $this->migrations->seed(['source' => 'CallSeeds', 'seed' => 'DatabaseSeed']); $this->assertTrue($seed); - $result = $this->Connection->newQuery() - ->select(['*']) - ->from('numbers') - ->execute()->fetchAll('assoc'); + $result = $this->Connection + ->selectQuery(['*'], 'numbers') + ->execute() + ->fetchAll('assoc'); $expected = [ [ @@ -826,10 +826,10 @@ public function testSeedCallSeeder() ]; $this->assertEquals($expected, $result); - $result = $this->Connection->newQuery() - ->select(['*']) - ->from('letters') - ->execute()->fetchAll('assoc'); + $result = $this->Connection + ->selectQuery(['*'], 'letters') + ->execute() + ->fetchAll('assoc'); $expected = [ [ diff --git a/tests/TestCase/TestCase.php b/tests/TestCase/TestCase.php index 6680f42c..859e9c2e 100644 --- a/tests/TestCase/TestCase.php +++ b/tests/TestCase/TestCase.php @@ -16,8 +16,8 @@ */ namespace Migrations\Test\TestCase; +use Cake\Console\TestSuite\ConsoleIntegrationTestTrait; use Cake\Routing\Router; -use Cake\TestSuite\ConsoleIntegrationTestTrait; use Cake\TestSuite\StringCompareTrait; use Cake\TestSuite\TestCase as BaseTestCase; diff --git a/tests/TestCase/TestSuite/MigratorTest.php b/tests/TestCase/TestSuite/MigratorTest.php index b39b0268..023a3f4c 100644 --- a/tests/TestCase/TestSuite/MigratorTest.php +++ b/tests/TestCase/TestSuite/MigratorTest.php @@ -61,7 +61,7 @@ public function testMigrateDropTruncate(): void $tables = $connection->getSchemaCollection()->listTables(); $this->assertContains('migrator', $tables); - $this->assertCount(0, $connection->query('SELECT * FROM migrator')->fetchAll()); + $this->assertCount(0, $connection->selectQuery(['*'], 'migrator')->execute()->fetchAll()); } public function testMigrateDropNoTruncate(): void @@ -73,7 +73,7 @@ public function testMigrateDropNoTruncate(): void $tables = $connection->getSchemaCollection()->listTables(); $this->assertContains('migrator', $tables); - $this->assertCount(1, $connection->query('SELECT * FROM migrator')->fetchAll()); + $this->assertCount(1, $connection->selectQuery(['*'], 'migrator')->execute()->fetchAll()); } public function testMigrateSkipTables(): void @@ -92,7 +92,7 @@ public function testMigrateSkipTables(): void $tables = $connection->getSchemaCollection()->listTables(); $this->assertContains('migrator', $tables); $this->assertContains('skipme', $tables); - $this->assertCount(1, $connection->query('SELECT * FROM skipme')->fetchAll()); + $this->assertCount(1, $connection->selectQuery(['*'], 'skipme')->execute()->fetchAll()); } public function testRunManyDropTruncate(): void @@ -106,8 +106,8 @@ public function testRunManyDropTruncate(): void $connection = ConnectionManager::get('test'); $tables = $connection->getSchemaCollection()->listTables(); $this->assertContains('migrator', $tables); - $this->assertCount(0, $connection->query('SELECT * FROM migrator')->fetchAll()); - $this->assertCount(2, $connection->query('SELECT * FROM migrator_phinxlog')->fetchAll()); + $this->assertCount(0, $connection->selectQuery(['*'], 'migrator')->execute()->fetchAll()); + $this->assertCount(2, $connection->selectQuery(['*'], 'migrator_phinxlog')->execute()->fetchAll()); } public function testRunManyMultipleSkip(): void @@ -146,23 +146,21 @@ public function testTruncateAfterMigrations(): void $migrator->truncate('test'); $connection = ConnectionManager::get('test'); - $this->assertCount(0, $connection->query('SELECT * FROM migrator')->fetchAll()); + $this->assertCount(0, $connection->selectQuery(['*'], 'migrator')->execute()->fetchAll()); } private function setMigrationEndDateToYesterday() { - ConnectionManager::get('test')->newQuery() - ->update('migrator_phinxlog') + ConnectionManager::get('test')->updateQuery('migrator_phinxlog') ->set('end_time', FrozenDate::yesterday(), 'timestamp') ->execute(); } private function fetchMigrationEndDate(): ChronosInterface { - $endTime = ConnectionManager::get('test')->newQuery() - ->select('end_time') - ->from('migrator_phinxlog') - ->execute()->fetchColumn(0); + $endTime = ConnectionManager::get('test')->selectQuery(['end_time'], 'migrator_phinxlog') + ->execute() + ->fetchColumn(0); return FrozenDate::parse($endTime); }