Skip to content

Commit 0ac0837

Browse files
authored
fix: properly quote table names with schema definition #84 (#86)
1 parent 8a295c4 commit 0ac0837

File tree

5 files changed

+21
-12
lines changed

5 files changed

+21
-12
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141
--health-timeout 5s
4242
--health-retries 5
4343
postgres:
44-
image: postgres
44+
image: postgres:16.4
4545
env:
4646
POSTGRES_PASSWORD: postgres
4747
POSTGRES_DB: codeception_test

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"codeception/codeception": "*@dev"
2323
},
2424
"require-dev": {
25+
"behat/gherkin": "~4.10.0",
2526
"squizlabs/php_codesniffer": "*"
2627
},
2728
"conflict": {

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ services:
3030
- "3306:3306"
3131

3232
postgres:
33-
image: postgres
33+
image: postgres:16.4
3434
environment:
3535
POSTGRES_PASSWORD: codeception
3636
POSTGRES_DB: codeception

src/Codeception/Lib/Driver/PostgreSql.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public function getPrimaryKey(string $tableName): array
164164
FROM pg_index i
165165
JOIN pg_attribute a ON a.attrelid = i.indrelid
166166
AND a.attnum = ANY(i.indkey)
167-
WHERE i.indrelid = '\"{$tableName}\"'::regclass
167+
WHERE i.indrelid = '" . $this->getQuotedName($tableName) . "'::regclass
168168
AND i.indisprimary";
169169
$stmt = $this->executeQuery($query, []);
170170
$columns = $stmt->fetchAll(PDO::FETCH_ASSOC);

tests/unit/Codeception/Module/Db/PostgreSqlDbTest.php

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,20 @@ public function getConfig(): array
1717
$this->markTestSkipped();
1818
}
1919

20-
$host = getenv('PG_HOST') ?: 'localhost';
21-
$user = getenv('PG_USER') ?: 'postgres';
20+
$host = getenv('PG_HOST') ?: 'localhost';
21+
$user = getenv('PG_USER') ?: 'postgres';
2222
$password = getenv('PG_PASSWORD') ?: null;
2323
$database = getenv('PG_DB') ?: 'codeception_test';
24-
$dsn = getenv('PG_DSN') ?: 'pgsql:host=' . $host . ';dbname=' . $database;
24+
$dsn = getenv('PG_DSN') ?: 'pgsql:host=' . $host . ';dbname=' . $database;
2525

2626
return [
27-
'dsn' => $dsn,
28-
'user' => $user,
29-
'password' => $password,
30-
'dump' => 'tests/data/dumps/postgres.sql',
27+
'dsn' => $dsn,
28+
'user' => $user,
29+
'password' => $password,
30+
'dump' => 'tests/data/dumps/postgres.sql',
3131
'reconnect' => true,
32-
'cleanup' => true,
33-
'populate' => true
32+
'cleanup' => true,
33+
'populate' => true,
3434
];
3535
}
3636

@@ -39,4 +39,12 @@ public function testHaveInDatabaseWithUppercaseTableName()
3939
$testData = ['Status' => 'test'];
4040
$this->module->haveInDatabase('NoPk', $testData);
4141
}
42+
43+
public function testHaveInDatabaseWithAnotherSchema()
44+
{
45+
$userId = $this->module->haveInDatabase('anotherschema.users', ['name' => 'anotherschema', 'email' => '[email protected]']);
46+
$this->assertIsInt($userId);
47+
48+
$this->module->seeInDatabase('anotherschema.users', ['name' => 'anotherschema', 'email' => '[email protected]']);
49+
}
4250
}

0 commit comments

Comments
 (0)