Skip to content

Commit

Permalink
Fix more failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Dec 30, 2024
1 parent afa72fb commit f4af7bf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
36 changes: 18 additions & 18 deletions tests/TestCase/Db/Adapter/PhinxAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,12 @@ public function testRollbackTransaction()

public function testQuoteTableName()
{
$this->assertEquals('`test_table`', $this->adapter->quoteTableName('test_table'));
$this->assertEquals('"test_table"', $this->adapter->quoteTableName('test_table'));
}

public function testQuoteColumnName()
{
$this->assertEquals('`test_column`', $this->adapter->quoteColumnName('test_column'));
$this->assertEquals('"test_column"', $this->adapter->quoteColumnName('test_column'));
}

public function testCreateTable()
Expand Down Expand Up @@ -296,10 +296,10 @@ public function testCreateTableWithIndexesAndForeignKey()
$this->assertTrue($this->adapter->hasForeignKey('tbl_child', ['master_id']));

$row = $this->adapter->fetchRow(
"SELECT * FROM sqlite_master WHERE `type` = 'table' AND `tbl_name` = 'tbl_child'"
"SELECT * FROM sqlite_master WHERE \"type\" = 'table' AND \"tbl_name\" = 'tbl_child'"
);
$this->assertStringContainsString(
'CONSTRAINT `fk_master_id` FOREIGN KEY (`master_id`) REFERENCES `tbl_master` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION',
'CONSTRAINT "fk_master_id" FOREIGN KEY ("master_id") REFERENCES "tbl_master" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION',
$row['sql']
);
}
Expand All @@ -323,10 +323,10 @@ public function testCreateTableWithoutAutoIncrementingPrimaryKeyAndWithForeignKe
$this->assertTrue($this->adapter->hasForeignKey('tbl_child', ['master_id']));

$row = $this->adapter->fetchRow(
"SELECT * FROM sqlite_master WHERE `type` = 'table' AND `tbl_name` = 'tbl_child'"
"SELECT * FROM sqlite_master WHERE \"type\" = 'table' AND \"tbl_name\" = 'tbl_child'"
);
$this->assertStringContainsString(
'CONSTRAINT `fk_master_id` FOREIGN KEY (`master_id`) REFERENCES `tbl_master` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION',
'CONSTRAINT "fk_master_id" FOREIGN KEY ("master_id") REFERENCES "tbl_master" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION',
$row['sql']
);
}
Expand Down Expand Up @@ -1115,7 +1115,7 @@ public function testDumpCreateTable()
->save();

$expectedOutput = <<<'OUTPUT'
CREATE TABLE `table1` (`id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, `column1` VARCHAR NOT NULL, `column2` INTEGER NULL, `column3` VARCHAR NULL DEFAULT 'test');
CREATE TABLE "table1" ("id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, "column1" VARCHAR NOT NULL, "column2" INTEGER NULL, "column3" VARCHAR NULL DEFAULT 'test');
OUTPUT;
$actualOutput = join("\n", $this->out->messages());
$this->assertStringContainsString($expectedOutput, $actualOutput, 'Passing the --dry-run option does not dump create table query to the output');
Expand Down Expand Up @@ -1147,9 +1147,9 @@ public function testDumpInsert()
]);

$expectedOutput = <<<'OUTPUT'
INSERT INTO `table1` (`string_col`) VALUES ('test data');
INSERT INTO `table1` (`string_col`) VALUES (null);
INSERT INTO `table1` (`int_col`) VALUES (23);
INSERT INTO "table1" ("string_col") VALUES ('test data');
INSERT INTO "table1" ("string_col") VALUES (null);
INSERT INTO "table1" ("int_col") VALUES (23);
OUTPUT;
$actualOutput = join("\n", $this->out->messages());
$actualOutput = preg_replace("/\r\n|\r/", "\n", $actualOutput); // normalize line endings for Windows
Expand Down Expand Up @@ -1186,7 +1186,7 @@ public function testDumpBulkinsert()
]);

$expectedOutput = <<<'OUTPUT'
INSERT INTO `table1` (`string_col`, `int_col`) VALUES ('test_data1', 23), (null, 42);
INSERT INTO "table1" ("string_col", "int_col") VALUES ('test_data1', 23), (null, 42);
OUTPUT;
$actualOutput = join("\n", $this->out->messages());
$this->assertStringContainsString($expectedOutput, $actualOutput, 'Passing the --dry-run option doesn\'t dump the bulkinsert to the output');
Expand Down Expand Up @@ -1216,8 +1216,8 @@ public function testDumpCreateTableAndThenInsert()
])->save();

$expectedOutput = <<<'OUTPUT'
CREATE TABLE `table1` (`column1` VARCHAR NOT NULL, `column2` INTEGER NULL, PRIMARY KEY (`column1`));
INSERT INTO `table1` (`column1`, `column2`) VALUES ('id1', 1);
CREATE TABLE "table1" ("column1" VARCHAR NOT NULL, "column2" INTEGER NULL, PRIMARY KEY ("column1"));
INSERT INTO "table1" ("column1", "column2") VALUES ('id1', 1);
OUTPUT;
$actualOutput = join("\n", $this->out->messages());
$actualOutput = preg_replace("/\r\n|\r/", "\n", $actualOutput); // normalize line endings for Windows
Expand Down Expand Up @@ -1618,7 +1618,7 @@ public function testForeignKeyReferenceCorrectAfterRenameColumn()
$sql = $row['sql'];
}
}
$this->assertStringContainsString("REFERENCES `{$refTable->getName()}` (`id`)", $sql);
$this->assertStringContainsString("REFERENCES \"{$refTable->getName()}\" (\"id\")", $sql);
}

public function testForeignKeyReferenceCorrectAfterChangeColumn()
Expand All @@ -1645,7 +1645,7 @@ public function testForeignKeyReferenceCorrectAfterChangeColumn()
$sql = $row['sql'];
}
}
$this->assertStringContainsString("REFERENCES `{$refTable->getName()}` (`id`)", $sql);
$this->assertStringContainsString("REFERENCES \"{$refTable->getName()}\" (\"id\")", $sql);
}

public function testForeignKeyReferenceCorrectAfterRemoveColumn()
Expand All @@ -1666,13 +1666,13 @@ public function testForeignKeyReferenceCorrectAfterRemoveColumn()
$this->assertFalse($this->adapter->hasTable("tmp_{$refTable->getName()}"));
$this->assertFalse($this->adapter->hasColumn($refTable->getName(), $refTableColumnToRemove));

$rows = $this->adapter->fetchAll('select * from sqlite_master where `type` = \'table\'');
$rows = $this->adapter->fetchAll('select * from sqlite_master where "type" = \'table\'');
foreach ($rows as $row) {
if ($row['tbl_name'] === $table->getName()) {
$sql = $row['sql'];
}
}
$this->assertStringContainsString("REFERENCES `{$refTable->getName()}` (`id`)", $sql);
$this->assertStringContainsString("REFERENCES \"{$refTable->getName()}\" (\"id\")", $sql);
}

public function testForeignKeyReferenceCorrectAfterChangePrimaryKey()
Expand Down Expand Up @@ -1702,6 +1702,6 @@ public function testForeignKeyReferenceCorrectAfterChangePrimaryKey()
$sql = $row['sql'];
}
}
$this->assertStringContainsString("REFERENCES `{$refTable->getName()}` (`id`)", $sql);
$this->assertStringContainsString("REFERENCES \"{$refTable->getName()}\" (\"id\")", $sql);
}
}
4 changes: 2 additions & 2 deletions tests/TestCase/Db/Adapter/SqliteAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -527,12 +527,12 @@ public function testAddColumnWithDefaultEmptyString()
$this->assertEquals("''", $rows[1]['dflt_value']);
}

public static function irregularCreateTableProvider()
public static function irregularCreateTableProvider(): array
{
return [
["CREATE TABLE \"users\"\n( \"id\" INTEGER NOT NULL )", ['id', 'foo']],
['CREATE TABLE users ( id INTEGER NOT NULL )', ['id', 'foo']],
["CREATE TABLE `users` (`id` INTEGER NOT NULL )", ['id', 'foo']],
['CREATE TABLE `users` (`id` INTEGER NOT NULL )', ['id', 'foo']],
["CREATE TABLE [users]\n(\nid INTEGER NOT NULL)", ['id', 'foo']],
["CREATE TABLE \"users\" ([id] \n INTEGER NOT NULL\n, \"bar\" INTEGER)", ['id', 'bar', 'foo']],
];
Expand Down

0 comments on commit f4af7bf

Please sign in to comment.