Skip to content

Commit

Permalink
Merge pull request #663 from ishanvyas22/fix-deprecations
Browse files Browse the repository at this point in the history
Fix deprecations related to CakePHP 4.5
  • Loading branch information
markstory authored Nov 24, 2023
2 parents 58446fd f9d742a commit a30328a
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 85 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
7 changes: 3 additions & 4 deletions src/Command/BakeMigrationDiffCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down
18 changes: 6 additions & 12 deletions tests/TestCase/Command/BakeMigrationDiffCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -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();

Expand All @@ -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],
Expand Down Expand Up @@ -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();

Expand All @@ -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],
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Command/CompletionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 13,7 @@
*/
namespace Migrations\Test\TestCase\Command;

use Cake\TestSuite\ConsoleIntegrationTestTrait;
use Cake\Console\TestSuite\ConsoleIntegrationTestTrait;
use Cake\TestSuite\TestCase;

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Command/Phinx/DumpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
34 changes: 17 additions & 17 deletions tests/TestCase/Command/Phinx/MarkMigratedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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']);
Expand All @@ -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();
Expand Down Expand Up @@ -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']);
Expand Down Expand Up @@ -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([
Expand All @@ -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([
Expand Down Expand Up @@ -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([
Expand All @@ -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([
Expand Down Expand Up @@ -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([
Expand All @@ -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([
Expand Down Expand Up @@ -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']);
}
Expand All @@ -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` !',
Expand All @@ -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` !',
Expand All @@ -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` !',
Expand Down
12 changes: 5 additions & 7 deletions tests/TestCase/Command/Phinx/SeedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Command/Phinx/StatusTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
56 changes: 28 additions & 28 deletions tests/TestCase/MigrationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand Down Expand Up @@ -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 = [
[
Expand All @@ -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 = [
[
Expand Down Expand Up @@ -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 = [
[
Expand All @@ -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 = [
[
Expand Down
Loading

0 comments on commit a30328a

Please sign in to comment.