Skip to content

Commit a30328a

Browse files
authored
Merge pull request #663 from ishanvyas22/fix-deprecations
Fix deprecations related to CakePHP 4.5
2 parents 58446fd + f9d742a commit a30328a

11 files changed

Lines changed: 74 additions & 85 deletions

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
},
2929
"require-dev": {
3030
"phpunit/phpunit": "^9.5.0",
31-
"cakephp/cakephp": "^4.3.0",
31+
"cakephp/cakephp": "^4.5.0",
3232
"cakephp/bake": "^2.6.0",
3333
"cakephp/cakephp-codesniffer": "^4.1"
3434
},

src/Command/BakeMigrationDiffCommand.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,17 +144,16 @@ protected function setup(Arguments $args)
144144
$this->migrationsFiles = glob($this->migrationsPath . '*.php') ?: [];
145145
$this->phinxTable = $this->getPhinxTable($this->plugin);
146146

147+
/** @var \Cake\Database\Connection $connection */
147148
$connection = ConnectionManager::get($this->connection);
148149
$this->tables = $connection->getSchemaCollection()->listTables();
149150
$tableExists = in_array($this->phinxTable, $this->tables, true);
150151

151152
$migratedItems = [];
152153
if ($tableExists) {
153-
$query = $connection->newQuery();
154154
/** @var array $migratedItems */
155-
$migratedItems = $query
156-
->select(['version'])
157-
->from($this->phinxTable)
155+
$migratedItems = $connection
156+
->selectQuery(['version'], $this->phinxTable)
158157
->order(['version DESC'])
159158
->execute()->fetchAll('assoc');
160159
}

tests/TestCase/Command/BakeMigrationDiffCommandTest.php

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,7 @@ public function testBakingDiff()
148148
copy($diffDumpPath, $destinationDumpPath);
149149

150150
$connection = ConnectionManager::get('test_comparisons');
151-
$connection->newQuery()
152-
->delete('phinxlog')
151+
$connection->deleteQuery('phinxlog')
153152
->where(['version' => 20160415220805])
154153
->execute();
155154

@@ -177,9 +176,8 @@ public function testBakingDiff()
177176
rename($destinationConfigDir . $generatedMigration, $destination);
178177
$versionParts = explode('_', $generatedMigration);
179178

180-
$connection->newQuery()
179+
$connection->insertQuery('phinxlog')
181180
->insert(['version', 'migration_name', 'start_time', 'end_time'])
182-
->into('phinxlog')
183181
->values([
184182
'version' => 20160415220805,
185183
'migration_name' => $versionParts[1],
@@ -224,8 +222,7 @@ public function testBakingDiffSimple()
224222
copy($diffDumpPath, $destinationDumpPath);
225223

226224
$connection = ConnectionManager::get('test_comparisons');
227-
$connection->newQuery()
228-
->delete('phinxlog')
225+
$connection->deleteQuery('phinxlog')
229226
->where(['version' => 20160415220805])
230227
->execute();
231228

@@ -245,9 +242,8 @@ public function testBakingDiffSimple()
245242
rename($destinationConfigDir . $generatedMigration, $destination);
246243
$versionParts = explode('_', $generatedMigration);
247244

248-
$connection->newQuery()
245+
$connection->insertQuery('phinxlog')
249246
->insert(['version', 'migration_name', 'start_time', 'end_time'])
250-
->into('phinxlog')
251247
->values([
252248
'version' => 20160415220805,
253249
'migration_name' => $versionParts[1],
@@ -288,8 +284,7 @@ public function testBakingDiffAddRemove()
288284
copy($diffDumpPath, $destinationDumpPath);
289285

290286
$connection = ConnectionManager::get('test_comparisons');
291-
$connection->newQuery()
292-
->delete('phinxlog')
287+
$connection->deleteQuery('phinxlog')
293288
->where(['version' => 20160415220805])
294289
->execute();
295290

@@ -310,9 +305,8 @@ public function testBakingDiffAddRemove()
310305
rename($destinationConfigDir . $generatedMigration, $destination);
311306
$versionParts = explode('_', $generatedMigration);
312307

313-
$connection->newQuery()
308+
$connection->insertQuery('phinxlog')
314309
->insert(['version', 'migration_name', 'start_time', 'end_time'])
315-
->into('phinxlog')
316310
->values([
317311
'version' => 20160415220805,
318312
'migration_name' => $versionParts[1],

tests/TestCase/Command/CompletionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*/
1414
namespace Migrations\Test\TestCase\Command;
1515

16-
use Cake\TestSuite\ConsoleIntegrationTestTrait;
16+
use Cake\Console\TestSuite\ConsoleIntegrationTestTrait;
1717
use Cake\TestSuite\TestCase;
1818

1919
/**

tests/TestCase/Command/Phinx/DumpTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function setUp(): void
7575
parent::setUp();
7676

7777
$this->connection = ConnectionManager::get('test');
78-
$this->connection->connect();
78+
$this->connection->getDriver()->connect();
7979
$this->pdo = $this->connection->getDriver()->getConnection();
8080
$application = new MigrationsDispatcher('testing');
8181
$this->command = $application->find('dump');

tests/TestCase/Command/Phinx/MarkMigratedTest.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function setUp(): void
6262
parent::setUp();
6363

6464
$this->connection = ConnectionManager::get('test');
65-
$this->connection->connect();
65+
$this->connection->getDriver()->connect();
6666
$this->pdo = $this->connection->getDriver()->getConnection();
6767
$this->connection->execute('DROP TABLE IF EXISTS phinxlog');
6868
$this->connection->execute('DROP TABLE IF EXISTS numbers');
@@ -110,7 +110,7 @@ public function testExecute()
110110
$this->commandTester->getDisplay()
111111
);
112112

113-
$result = $this->connection->newQuery()->select(['*'])->from('phinxlog')->execute()->fetchAll('assoc');
113+
$result = $this->connection->selectQuery(['*'], 'phinxlog')->execute()->fetchAll('assoc');
114114
$this->assertEquals('20150704160200', $result[0]['version']);
115115
$this->assertEquals('20150724233100', $result[1]['version']);
116116
$this->assertEquals('20150826191400', $result[2]['version']);
@@ -134,7 +134,7 @@ public function testExecute()
134134
$this->commandTester->getDisplay()
135135
);
136136

137-
$result = $this->connection->newQuery()->select(['*'])->from('phinxlog')->execute()->count();
137+
$result = $this->connection->selectQuery(['*'], 'phinxlog')->execute()->count();
138138
$this->assertSame(3, $result);
139139

140140
$config = $this->command->getConfig();
@@ -202,7 +202,7 @@ public function testExecuteAll()
202202
$this->commandTester->getDisplay()
203203
);
204204

205-
$result = $this->connection->newQuery()->select(['*'])->from('phinxlog')->execute()->fetchAll('assoc');
205+
$result = $this->connection->selectQuery(['*'], 'phinxlog')->execute()->fetchAll('assoc');
206206
$this->assertEquals('20150704160200', $result[0]['version']);
207207
$this->assertEquals('20150724233100', $result[1]['version']);
208208
$this->assertEquals('20150826191400', $result[2]['version']);
@@ -246,7 +246,7 @@ public function testExecuteTarget()
246246
$this->commandTester->getDisplay()
247247
);
248248

249-
$result = $this->connection->newQuery()->select(['*'])->from('phinxlog')->execute()->fetchAll('assoc');
249+
$result = $this->connection->selectQuery(['*'], 'phinxlog')->execute()->fetchAll('assoc');
250250
$this->assertEquals('20150704160200', $result[0]['version']);
251251

252252
$this->commandTester->execute([
@@ -269,11 +269,11 @@ public function testExecuteTarget()
269269
$this->commandTester->getDisplay()
270270
);
271271

272-
$result = $this->connection->newQuery()->select(['*'])->from('phinxlog')->execute()->fetchAll('assoc');
272+
$result = $this->connection->selectQuery(['*'], 'phinxlog')->execute()->fetchAll('assoc');
273273
$this->assertEquals('20150704160200', $result[0]['version']);
274274
$this->assertEquals('20150724233100', $result[1]['version']);
275275
$this->assertEquals('20150826191400', $result[2]['version']);
276-
$result = $this->connection->newQuery()->select(['*'])->from('phinxlog')->execute()->count();
276+
$result = $this->connection->selectQuery(['*'], 'phinxlog')->execute()->count();
277277
$this->assertSame(3, $result);
278278

279279
$this->commandTester->execute([
@@ -304,7 +304,7 @@ public function testExecuteTargetWithExclude()
304304
$this->commandTester->getDisplay()
305305
);
306306

307-
$result = $this->connection->newQuery()->select(['*'])->from('phinxlog')->execute()->fetchAll('assoc');
307+
$result = $this->connection->selectQuery(['*'], 'phinxlog')->execute()->fetchAll('assoc');
308308
$this->assertEquals('20150704160200', $result[0]['version']);
309309

310310
$this->commandTester->execute([
@@ -324,10 +324,10 @@ public function testExecuteTargetWithExclude()
324324
$this->commandTester->getDisplay()
325325
);
326326

327-
$result = $this->connection->newQuery()->select(['*'])->from('phinxlog')->execute()->fetchAll('assoc');
327+
$result = $this->connection->selectQuery(['*'], 'phinxlog')->execute()->fetchAll('assoc');
328328
$this->assertEquals('20150704160200', $result[0]['version']);
329329
$this->assertEquals('20150724233100', $result[1]['version']);
330-
$result = $this->connection->newQuery()->select(['*'])->from('phinxlog')->execute()->count();
330+
$result = $this->connection->selectQuery(['*'], 'phinxlog')->execute()->count();
331331
$this->assertSame(2, $result);
332332

333333
$this->commandTester->execute([
@@ -359,7 +359,7 @@ public function testExecuteTargetWithOnly()
359359
$this->commandTester->getDisplay()
360360
);
361361

362-
$result = $this->connection->newQuery()->select(['*'])->from('phinxlog')->execute()->fetchAll('assoc');
362+
$result = $this->connection->selectQuery(['*'], 'phinxlog')->execute()->fetchAll('assoc');
363363
$this->assertEquals('20150724233100', $result[0]['version']);
364364

365365
$this->commandTester->execute([
@@ -375,10 +375,10 @@ public function testExecuteTargetWithOnly()
375375
$this->commandTester->getDisplay()
376376
);
377377

378-
$result = $this->connection->newQuery()->select(['*'])->from('phinxlog')->execute()->fetchAll('assoc');
378+
$result = $this->connection->selectQuery(['*'], 'phinxlog')->execute()->fetchAll('assoc');
379379
$this->assertEquals('20150826191400', $result[1]['version']);
380380
$this->assertEquals('20150724233100', $result[0]['version']);
381-
$result = $this->connection->newQuery()->select(['*'])->from('phinxlog')->execute()->count();
381+
$result = $this->connection->selectQuery(['*'], 'phinxlog')->execute()->count();
382382
$this->assertSame(2, $result);
383383

384384
$this->commandTester->execute([
@@ -414,7 +414,7 @@ public function testExecuteWithVersionAsArgument()
414414
$this->commandTester->getDisplay()
415415
);
416416

417-
$result = $this->connection->newQuery()->select(['*'])->from('phinxlog')->execute()->fetchAll('assoc');
417+
$result = $this->connection->selectQuery(['*'], 'phinxlog')->execute()->fetchAll('assoc');
418418
$this->assertSame(1, count($result));
419419
$this->assertEquals('20150724233100', $result[0]['version']);
420420
}
@@ -428,7 +428,7 @@ public function testExecuteInvalidUseOfOnlyAndExclude()
428428
'--source' => 'TestsMigrations',
429429
]);
430430

431-
$result = $this->connection->newQuery()->select(['*'])->from('phinxlog')->execute()->count();
431+
$result = $this->connection->selectQuery(['*'], 'phinxlog')->execute()->count();
432432
$this->assertSame(0, $result);
433433
$this->assertStringContainsString(
434434
'You should use `--exclude` OR `--only` (not both) along with a `--target` !',
@@ -442,7 +442,7 @@ public function testExecuteInvalidUseOfOnlyAndExclude()
442442
'--source' => 'TestsMigrations',
443443
]);
444444

445-
$result = $this->connection->newQuery()->select(['*'])->from('phinxlog')->execute()->count();
445+
$result = $this->connection->selectQuery(['*'], 'phinxlog')->execute()->count();
446446
$this->assertSame(0, $result);
447447
$this->assertStringContainsString(
448448
'You should use `--exclude` OR `--only` (not both) along with a `--target` !',
@@ -458,7 +458,7 @@ public function testExecuteInvalidUseOfOnlyAndExclude()
458458
'--source' => 'TestsMigrations',
459459
]);
460460

461-
$result = $this->connection->newQuery()->select(['*'])->from('phinxlog')->execute()->count();
461+
$result = $this->connection->selectQuery(['*'], 'phinxlog')->execute()->count();
462462
$this->assertSame(0, $result);
463463
$this->assertStringContainsString(
464464
'You should use `--exclude` OR `--only` (not both) along with a `--target` !',

tests/TestCase/Command/Phinx/SeedTest.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function setUp(): void
6464
parent::setUp();
6565

6666
$this->connection = ConnectionManager::get('test');
67-
$this->connection->connect();
67+
$this->connection->getDriver()->connect();
6868
$this->pdo = $this->connection->getDriver()->getConnection();
6969
$application = new MigrationsDispatcher('testing');
7070
$this->command = $application->find('seed');
@@ -106,9 +106,8 @@ public function testExecute()
106106
$display = $this->getDisplayFromOutput();
107107
$this->assertTextContains('== NumbersSeed: seeded', $display);
108108

109-
$result = $this->connection->newQuery()
110-
->select(['*'])
111-
->from('numbers')
109+
$result = $this->connection
110+
->selectQuery(['*'], 'numbers')
112111
->order('id DESC')
113112
->limit(1)
114113
->execute()->fetchAll('assoc');
@@ -148,9 +147,8 @@ public function testExecuteCustomParams()
148147
$display = $this->getDisplayFromOutput();
149148
$this->assertTextContains('== NumbersAltSeed: seeded', $display);
150149

151-
$result = $this->connection->newQuery()
152-
->select(['*'])
153-
->from('numbers')
150+
$result = $this->connection
151+
->selectQuery(['*'], 'numbers')
154152
->order('id DESC')
155153
->limit(1)
156154
->execute()->fetchAll('assoc');

tests/TestCase/Command/Phinx/StatusTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function setUp(): void
7171
parent::setUp();
7272

7373
$this->Connection = ConnectionManager::get('test');
74-
$this->Connection->connect();
74+
$this->Connection->getDriver()->connect();
7575
$this->pdo = $this->Connection->getDriver()->getConnection();
7676
$this->Connection->execute('DROP TABLE IF EXISTS phinxlog');
7777
$this->Connection->execute('DROP TABLE IF EXISTS numbers');

tests/TestCase/MigrationsTest.php

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -687,10 +687,10 @@ public function testSeed()
687687
$seed = $this->migrations->seed(['source' => 'Seeds']);
688688
$this->assertTrue($seed);
689689

690-
$result = $this->Connection->newQuery()
691-
->select(['*'])
692-
->from('numbers')
693-
->execute()->fetchAll('assoc');
690+
$result = $this->Connection
691+
->selectQuery(['*'], 'numbers')
692+
->execute()
693+
->fetchAll('assoc');
694694
$expected = [
695695
[
696696
'id' => '1',
@@ -702,10 +702,10 @@ public function testSeed()
702702

703703
$seed = $this->migrations->seed(['source' => 'Seeds']);
704704
$this->assertTrue($seed);
705-
$result = $this->Connection->newQuery()
706-
->select(['*'])
707-
->from('numbers')
708-
->execute()->fetchAll('assoc');
705+
$result = $this->Connection
706+
->selectQuery(['*'], 'numbers')
707+
->execute()
708+
->fetchAll('assoc');
709709
$expected = [
710710
[
711711
'id' => '1',
@@ -722,10 +722,10 @@ public function testSeed()
722722

723723
$seed = $this->migrations->seed(['source' => 'AltSeeds']);
724724
$this->assertTrue($seed);
725-
$result = $this->Connection->newQuery()
726-
->select(['*'])
727-
->from('numbers')
728-
->execute()->fetchAll('assoc');
725+
$result = $this->Connection
726+
->selectQuery(['*'], 'numbers')
727+
->execute()
728+
->fetchAll('assoc');
729729
$expected = [
730730
[
731731
'id' => '1',
@@ -763,10 +763,10 @@ public function testSeedOneSeeder()
763763

764764
$seed = $this->migrations->seed(['source' => 'AltSeeds', 'seed' => 'AnotherNumbersSeed']);
765765
$this->assertTrue($seed);
766-
$result = $this->Connection->newQuery()
767-
->select(['*'])
768-
->from('numbers')
769-
->execute()->fetchAll('assoc');
766+
$result = $this->Connection
767+
->selectQuery(['*'], 'numbers')
768+
->execute()
769+
->fetchAll('assoc');
770770

771771
$expected = [
772772
[
@@ -779,10 +779,10 @@ public function testSeedOneSeeder()
779779

780780
$seed = $this->migrations->seed(['source' => 'AltSeeds', 'seed' => 'NumbersAltSeed']);
781781
$this->assertTrue($seed);
782-
$result = $this->Connection->newQuery()
783-
->select(['*'])
784-
->from('numbers')
785-
->execute()->fetchAll('assoc');
782+
$result = $this->Connection
783+
->selectQuery(['*'], 'numbers')
784+
->execute()
785+
->fetchAll('assoc');
786786

787787
$expected = [
788788
[
@@ -812,10 +812,10 @@ public function testSeedCallSeeder()
812812

813813
$seed = $this->migrations->seed(['source' => 'CallSeeds', 'seed' => 'DatabaseSeed']);
814814
$this->assertTrue($seed);
815-
$result = $this->Connection->newQuery()
816-
->select(['*'])
817-
->from('numbers')
818-
->execute()->fetchAll('assoc');
815+
$result = $this->Connection
816+
->selectQuery(['*'], 'numbers')
817+
->execute()
818+
->fetchAll('assoc');
819819

820820
$expected = [
821821
[
@@ -826,10 +826,10 @@ public function testSeedCallSeeder()
826826
];
827827
$this->assertEquals($expected, $result);
828828

829-
$result = $this->Connection->newQuery()
830-
->select(['*'])
831-
->from('letters')
832-
->execute()->fetchAll('assoc');
829+
$result = $this->Connection
830+
->selectQuery(['*'], 'letters')
831+
->execute()
832+
->fetchAll('assoc');
833833

834834
$expected = [
835835
[

0 commit comments

Comments
 (0)