Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deprecations related to CakePHP 4.5 #663

Merged
merged 3 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix deprecations related to CakePHP 4.5
  • Loading branch information
ishanvyas22 committed Nov 24, 2023
commit 88c970f8c04aa1fe4bd8c1dc45c21c4fcd470b0a
6 changes: 2 additions & 4 deletions src/Command/BakeMigrationDiffCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 150,9 @@

$migratedItems = [];
if ($tableExists) {
$query = $connection->newQuery();
/** @var array $migratedItems */
$migratedItems = $query
->select(['version'])
->from($this->phinxTable)
$migratedItems = $connection

Check failure on line 154 in src/Command/BakeMigrationDiffCommand.php

View workflow job for this annotation

GitHub Actions / Coding Standard & Static Analysis

Call to an undefined method Cake\Datasource\ConnectionInterface::selectQuery().
->selectQuery(['version'], $this->phinxTable)

Check failure on line 155 in src/Command/BakeMigrationDiffCommand.php

View workflow job for this annotation

GitHub Actions / Coding Standard & Static Analysis

UndefinedInterfaceMethod

src/Command/BakeMigrationDiffCommand.php:155:19: UndefinedInterfaceMethod: Method Cake\Datasource\ConnectionInterface::selectQuery does not exist (see https://psalm.dev/181)

Check warning on line 155 in src/Command/BakeMigrationDiffCommand.php

View check run for this annotation

Codecov / codecov/patch

src/Command/BakeMigrationDiffCommand.php#L154-L155

Added lines #L154 - L155 were not covered by tests
->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
2 changes: 1 addition & 1 deletion tests/TestCase/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 17,7 @@
namespace Migrations\Test\TestCase;

use Cake\Routing\Router;
use Cake\TestSuite\ConsoleIntegrationTestTrait;
use Cake\Console\TestSuite\ConsoleIntegrationTestTrait;

Check failure on line 20 in tests/TestCase/TestCase.php

View workflow job for this annotation

GitHub Actions / Coding Standard & Static Analysis

Use statements should be sorted alphabetically. The first wrong one is Cake\Console\TestSuite\ConsoleIntegrationTestTrait.
use Cake\TestSuite\StringCompareTrait;
use Cake\TestSuite\TestCase as BaseTestCase;

Expand Down
Loading
Loading