Skip to content

Commit 7dbc620

Browse files
dereuromarkmarkstoryjamisonbryant
authored
Fix test deprecations and failures (#994)
* Fix test deprecations and failures - Fix EntryCommandTest assertion for changed help output format - Fix ManagerFactoryTest dynamic property deprecations (PHP 8.4) - Add missing plugin classes for Blog and Migrator test plugins - Add proper assertions to PendingMigrationsMiddlewareTest risky tests * Update tests/TestCase/Command/EntryCommandTest.php * Fix character location * Fix EntryCommandTest to work across all PHP versions Remove the assertion for 'migrations:</info>' as the help output format differs between PHP versions. The remaining assertions adequately verify the help output is displayed correctly. * Fix PostgreSQL dump tests for varying identity column syntax The identity column syntax varies between CakePHP/database versions (SERIAL vs GENERATED BY DEFAULT AS IDENTITY). Update the tests to check for the key parts of the CREATE TABLE statement without being strict about the identity column syntax. --------- Co-authored-by: Mark Story <[email protected]> Co-authored-by: Jamison Bryant <[email protected]>
1 parent cd1e47d commit 7dbc620

File tree

7 files changed

+48
-35
lines changed

7 files changed

+48
-35
lines changed

composer.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,10 @@
4747
},
4848
"autoload-dev": {
4949
"psr-4": {
50+
"Blog\\": "tests/test_app/Plugin/Blog/src/",
5051
"Cake\\Test\\": "./vendor/cakephp/cakephp/tests/",
5152
"Migrations\\Test\\": "tests/",
53+
"Migrator\\": "tests/test_app/Plugin/Migrator/src/",
5254
"SimpleSnapshot\\": "tests/test_app/Plugin/SimpleSnapshot/src/",
5355
"TestApp\\": "tests/test_app/App/",
5456
"TestBlog\\": "tests/test_app/Plugin/TestBlog/src/"

tests/TestCase/Command/EntryCommandTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ public function testExecuteHelp()
4545

4646
$this->assertExitSuccess();
4747
$this->assertOutputContains('Using <info>builtin</info> backend');
48-
$this->assertOutputContains('Available Commands');
4948
$this->assertOutputContains('migrations migrate');
5049
$this->assertOutputContains('migrations status');
5150
$this->assertOutputContains('migrations rollback');

tests/TestCase/Db/Adapter/PostgresAdapterTest.php

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2505,23 +2505,18 @@ public function testDumpCreateTable()
25052505
->addColumn('column3', 'string', ['default' => 'test', 'null' => false])
25062506
->save();
25072507

2508-
if ($this->usingPostgres10()) {
2509-
$expectedOutput = 'CREATE TABLE "public"."table1" ("id" SERIAL NOT NULL, ' .
2510-
'"column1" VARCHAR DEFAULT NULL, ' .
2511-
'"column2" INT DEFAULT NULL, "column3" VARCHAR NOT NULL DEFAULT \'test\', ' .
2512-
'CONSTRAINT "table1_pkey" PRIMARY KEY ("id"));';
2513-
} else {
2514-
$expectedOutput = 'CREATE TABLE "public"."table1" ("id" SERIAL NOT NULL, ' .
2515-
'"column1" VARCHAR DEFAULT NULL, ' .
2516-
'"column2" INT DEFAULT NULL, "column3" VARCHAR NOT NULL DEFAULT \'test\', ' .
2517-
'CONSTRAINT "table1_pkey" PRIMARY KEY ("id"));';
2518-
}
25192508
$actualOutput = join("\n", $this->out->messages());
2509+
// Check for key parts of the CREATE TABLE statement
2510+
// The identity column syntax varies between CakePHP/database versions
25202511
$this->assertStringContainsString(
2521-
$expectedOutput,
2512+
'CREATE TABLE "public"."table1"',
25222513
$actualOutput,
25232514
'Passing the --dry-run option does not dump create table query',
25242515
);
2516+
$this->assertStringContainsString('"column1" VARCHAR DEFAULT NULL', $actualOutput);
2517+
$this->assertStringContainsString('"column2" INT DEFAULT NULL', $actualOutput);
2518+
$this->assertStringContainsString('"column3" VARCHAR NOT NULL DEFAULT \'test\'', $actualOutput);
2519+
$this->assertStringContainsString('CONSTRAINT "table1_pkey" PRIMARY KEY ("id")', $actualOutput);
25252520
}
25262521

25272522
public function testDumpCreateTableWithSchema()
@@ -2537,21 +2532,18 @@ public function testDumpCreateTableWithSchema()
25372532
->addColumn('column3', 'string', ['default' => 'test', 'null' => false])
25382533
->save();
25392534

2540-
if ($this->usingPostgres10()) {
2541-
$expectedOutput = 'CREATE TABLE "schema1"."table1" ("id" SERIAL NOT NULL, "column1" VARCHAR DEFAULT NULL, ' .
2542-
'"column2" INT DEFAULT NULL, "column3" VARCHAR NOT NULL DEFAULT \'test\', CONSTRAINT ' .
2543-
'"table1_pkey" PRIMARY KEY ("id"));';
2544-
} else {
2545-
$expectedOutput = 'CREATE TABLE "schema1"."table1" ("id" SERIAL NOT NULL, "column1" VARCHAR DEFAULT NULL, ' .
2546-
'"column2" INT DEFAULT NULL, "column3" VARCHAR NOT NULL DEFAULT \'test\', CONSTRAINT ' .
2547-
'"table1_pkey" PRIMARY KEY ("id"));';
2548-
}
25492535
$actualOutput = join("\n", $this->out->messages());
2536+
// Check for key parts of the CREATE TABLE statement
2537+
// The identity column syntax varies between CakePHP/database versions
25502538
$this->assertStringContainsString(
2551-
$expectedOutput,
2539+
'CREATE TABLE "schema1"."table1"',
25522540
$actualOutput,
25532541
'Passing the --dry-run option does not dump create table query',
25542542
);
2543+
$this->assertStringContainsString('"column1" VARCHAR DEFAULT NULL', $actualOutput);
2544+
$this->assertStringContainsString('"column2" INT DEFAULT NULL', $actualOutput);
2545+
$this->assertStringContainsString('"column3" VARCHAR NOT NULL DEFAULT \'test\'', $actualOutput);
2546+
$this->assertStringContainsString('CONSTRAINT "table1_pkey" PRIMARY KEY ("id")', $actualOutput);
25552547
}
25562548

25572549
/**

tests/TestCase/Middleware/PendingMigrationsMiddlewareTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ public function testAppMigrationsFail(): void
7878
}
7979

8080
/**
81-
* @doesNotPerformAssertions
8281
* @return void
8382
*/
8483
public function testAppMigrationsSuccess(): void
@@ -103,7 +102,8 @@ public function testAppMigrationsSuccess(): void
103102
$handler = new TestRequestHandler(function ($req) {
104103
return new Response();
105104
});
106-
$middleware->process($request, $handler);
105+
$result = $middleware->process($request, $handler);
106+
$this->assertInstanceOf(Response::class, $result);
107107
}
108108

109109
/**
@@ -130,7 +130,6 @@ public function testAppAndPluginsMigrationsFail(): void
130130
}
131131

132132
/**
133-
* @doesNotPerformAssertions
134133
* @return void
135134
*/
136135
public function testAppAndPluginsMigrationsSuccess(): void
@@ -160,6 +159,7 @@ public function testAppAndPluginsMigrationsSuccess(): void
160159
return new Response();
161160
});
162161

163-
$middleware->process($request, $handler);
162+
$result = $middleware->process($request, $handler);
163+
$this->assertInstanceOf(Response::class, $result);
164164
}
165165
}

tests/TestCase/Migration/ManagerFactoryTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ class ManagerFactoryTest extends TestCase
1414
{
1515
public function testConnection(): void
1616
{
17-
$this->out = new StubConsoleOutput();
18-
$this->out->setOutputAs(StubConsoleOutput::PLAIN);
19-
$this->in = new StubConsoleInput([]);
17+
$out = new StubConsoleOutput();
18+
$out->setOutputAs(StubConsoleOutput::PLAIN);
19+
$in = new StubConsoleInput([]);
2020

21-
$io = new ConsoleIo($this->out, $this->out, $this->in);
21+
$io = new ConsoleIo($out, $out, $in);
2222

2323
$factory = new ManagerFactory(['connection' => 'test']);
2424
$result = $factory->createManager($io);
@@ -28,11 +28,11 @@ public function testConnection(): void
2828

2929
public function testDsnConnection(): void
3030
{
31-
$this->out = new StubConsoleOutput();
32-
$this->out->setOutputAs(StubConsoleOutput::PLAIN);
33-
$this->in = new StubConsoleInput([]);
31+
$out = new StubConsoleOutput();
32+
$out->setOutputAs(StubConsoleOutput::PLAIN);
33+
$in = new StubConsoleInput([]);
3434

35-
$io = new ConsoleIo($this->out, $this->out, $this->in);
35+
$io = new ConsoleIo($out, $out, $in);
3636

3737
$factory = new ManagerFactory(['connection' => 'mysql://[email protected]/db_tmp']);
3838
$result = $factory->createManager($io);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Blog;
5+
6+
use Cake\Core\BasePlugin;
7+
8+
class BlogPlugin extends BasePlugin
9+
{
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Migrator;
5+
6+
use Cake\Core\BasePlugin;
7+
8+
class MigratorPlugin extends BasePlugin
9+
{
10+
}

0 commit comments

Comments
 (0)