Skip to content

Commit

Permalink
Fix mariadb CI build (#721)
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm authored Nov 27, 2024
1 parent 6dac52e commit a2d990f
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 11 deletions.
1 change: 1 addition & 0 deletions .env.dist
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
DBA_PLATFORM=mysql
DBA_HOST=mysql80.ab
DBA_USER=testuser
DBA_PASSWORD=test
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ jobs:
dependencies: "highest"
- php-version: '8.1'
db-image: 'mariadb:latest'
platform: 'mariadb'
reflector: "mysqli"
mode: "recording"
dependencies: "highest"
Expand All @@ -60,6 +61,7 @@ jobs:
dependencies: "highest"
- php-version: '8.2'
db-image: 'mariadb:latest'
platform: 'mariadb'
reflector: "mysqli"
mode: "recording"
dependencies: "highest"
Expand All @@ -82,6 +84,7 @@ jobs:
dependencies: "highest"

env:
DBA_PLATFORM: ${{ matrix.platform }}
DBA_REFLECTOR: ${{ matrix.reflector }}
DBA_MODE: ${{ matrix.mode }}

Expand Down
3 changes: 3 additions & 0 deletions tests/ReflectorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public static function create(string $cacheDir): QueryReflector
$ssl = false;
$mode = getenv('DBA_MODE') ?: self::MODE_RECORDING;
$reflector = getenv('DBA_REFLECTOR') ?: 'mysqli';
$platform = getenv('DBA_PLATFORM') ?: 'mysql';
} else {
$host = getenv('DBA_HOST') ?: $_ENV['DBA_HOST'];
$user = getenv('DBA_USER') ?: $_ENV['DBA_USER'];
Expand All @@ -42,10 +43,12 @@ public static function create(string $cacheDir): QueryReflector
$ssl = (string) (getenv('DBA_SSL') ?: $_ENV['DBA_SSL'] ?? '');
$mode = getenv('DBA_MODE') ?: $_ENV['DBA_MODE'];
$reflector = getenv('DBA_REFLECTOR') ?: $_ENV['DBA_REFLECTOR'];
$platform = getenv('DBA_PLATFORM') ?: $_ENV['DBA_PLATFORM'];
}

// make env vars available to tests, in case non are defined yet
$_ENV['DBA_REFLECTOR'] = $reflector;
$_ENV['DBA_PLATFORM'] = $platform;

// we need to record the reflection information in both, phpunit and phpstan since we are replaying it in both CI jobs.
// in a regular application you will use phpstan-dba only within your phpstan CI job, therefore you only need 1 cache-file.
Expand Down
28 changes: 24 additions & 4 deletions tests/rules/SyntaxErrorInPreparedStatementMethodRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ public static function getAdditionalConfigFiles(): array
public function testSyntaxErrorInQueryRule(): void
{
if (MysqliQueryReflector::NAME === getenv('DBA_REFLECTOR')) {
$error = "Query error: Unknown column 'asdsa' in 'where clause' (1054).";
if ('mariadb' === $_ENV['DBA_PLATFORM']) {
$error = "Query error: Unknown column 'asdsa' in 'WHERE' (1054).";
}

$expectedErrors = [
[
"Query error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL/MariaDB server version for the right syntax to use near 'freigabe1u1 FROM ada LIMIT 0' at line 1 (1064).",
Expand Down Expand Up @@ -61,7 +66,7 @@ public function testSyntaxErrorInQueryRule(): void
107,
],
[
"Query error: Unknown column 'asdsa' in 'where clause' (1054).",
$error,
122,
],
[
Expand Down Expand Up @@ -165,6 +170,10 @@ public function testSyntaxErrorInQueryRule(): void
],
];
} elseif (PdoMysqlQueryReflector::NAME === getenv('DBA_REFLECTOR')) {
if ('mariadb' === $_ENV['DBA_PLATFORM']) {
self::markTestSkipped("We don't test all variants of expectations for all drivers");
}

$expectedErrors = [
[
"Query error: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL/MariaDB server version for the right syntax to use near 'freigabe1u1 FROM ada LIMIT 0' at line 1 (42000).",
Expand Down Expand Up @@ -256,17 +265,24 @@ public function testBug94()
public function testSyntaxErrorWithInferencePlaceholder()
{
if (MysqliQueryReflector::NAME === getenv('DBA_REFLECTOR')) {
$platform = $_ENV['DBA_PLATFORM'];

$error = "Query error: Unknown column 'does_not_exist' in 'field list' (1054).";
if ($platform === "mariadb") {
$error = "Query error: Unknown column 'does_not_exist' in 'SELECT' (1054).";
}

$expectedErrors = [
[
"Query error: Unknown column 'does_not_exist' in 'field list' (1054).",
$error,
12,
],
[
"Query error: Unknown column 'does_not_exist' in 'field list' (1054).",
$error,
36,
],
[
"Query error: Unknown column 'does_not_exist' in 'field list' (1054).",
$error,
60,
],
];
Expand All @@ -292,6 +308,10 @@ public function testSyntaxErrorWithInferencePlaceholder()
],
];
} elseif (PdoMysqlQueryReflector::NAME === getenv('DBA_REFLECTOR')) {
if ('mariadb' === $_ENV['DBA_PLATFORM']) {
self::markTestSkipped("We don't test all variants of expectations for all drivers");
}

$expectedErrors = [
[
"Query error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'does_not_exist' in 'field list' (42S22).",
Expand Down
9 changes: 8 additions & 1 deletion tests/rules/SyntaxErrorInQueryFunctionRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public function testSyntaxErrorInQueryRule(): void
public function getExpectedErrors(): array
{
$dbaReflector = getenv('DBA_REFLECTOR');
$platform = $_ENV['DBA_PLATFORM'];

switch ($dbaReflector) {
case MysqliQueryReflector::NAME:
Expand All @@ -52,7 +53,9 @@ public function getExpectedErrors(): array
19,
],
[
"Query error: Unknown column 'asdsa' in 'where clause' (1054).",
$platform === 'mariadb' ?
"Query error: Unknown column 'asdsa' in 'WHERE' (1054)."
: "Query error: Unknown column 'asdsa' in 'where clause' (1054).",
39,
],
];
Expand Down Expand Up @@ -87,6 +90,10 @@ public function getExpectedErrors(): array
],
];
case PdoMysqlQueryReflector::NAME:
if ('mariadb' === $_ENV['DBA_PLATFORM']) {
self::markTestSkipped("We don't test all variants of expectations for all drivers");
}

return [
[
"Query error: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL/MariaDB server version for the right syntax to use near 'freigabe1u1 FROM ada LIMIT 0' at line 1 (42000).",
Expand Down
32 changes: 26 additions & 6 deletions tests/rules/SyntaxErrorInQueryMethodRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,22 @@ public static function getAdditionalConfigFiles(): array
public function testSyntaxErrorInQueryRule(): void
{
if (MysqliQueryReflector::NAME === getenv('DBA_REFLECTOR')) {
$errSelect = "Query error: Unknown column 'doesNotExist' in 'field list' (1054).";
$errWhere = "Query error: Unknown column 'doesNotExist' in 'where clause' (1054).";
$errOrder = "Query error: Unknown column 'doesNotExist' in 'order clause' (1054).";
$errGroup = "Query error: Unknown column 'doesNotExist' in 'group statement' (1054).";
$errWhere2 = "Query error: Unknown column 'asdsa' in 'where clause' (1054).";
$errGroup2 = "Query error: Unknown column 'xy' in 'group statement' (1054).";

if ('mariadb' === $_ENV['DBA_PLATFORM']) {
$errSelect = "Query error: Unknown column 'doesNotExist' in 'SELECT' (1054).";
$errWhere = "Query error: Unknown column 'doesNotExist' in 'WHERE' (1054).";
$errOrder = "Query error: Unknown column 'doesNotExist' in 'ORDER BY' (1054).";
$errGroup = "Query error: Unknown column 'doesNotExist' in 'GROUP BY' (1054).";
$errWhere2 = "Query error: Unknown column 'asdsa' in 'WHERE' (1054).";
$errGroup2 = "Query error: Unknown column 'xy' in 'GROUP BY' (1054).";
}

$expected = [
[
"Query error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL/MariaDB server version for the right syntax to use near 'freigabe1u1 FROM ada LIMIT 0' at line 1 (1064).",
Expand All @@ -41,19 +57,19 @@ public function testSyntaxErrorInQueryRule(): void
16,
],
[
"Query error: Unknown column 'doesNotExist' in 'field list' (1054).",
$errSelect,
21,
],
[
"Query error: Unknown column 'doesNotExist' in 'where clause' (1054).",
$errWhere,
26,
],
[
"Query error: Unknown column 'doesNotExist' in 'order clause' (1054).",
$errOrder,
31,
],
[
"Query error: Unknown column 'doesNotExist' in 'group statement' (1054).",
$errGroup,
36,
],
[
Expand All @@ -73,11 +89,11 @@ public function testSyntaxErrorInQueryRule(): void
82,
],
[
"Query error: Unknown column 'asdsa' in 'where clause' (1054).",
$errWhere2,
103,
],
[
"Query error: Unknown column 'xy' in 'group statement' (1054).",
$errGroup2,
118,
],
[
Expand All @@ -98,6 +114,10 @@ public function testSyntaxErrorInQueryRule(): void
],
];
} elseif (PdoMysqlQueryReflector::NAME === getenv('DBA_REFLECTOR')) {
if ('mariadb' === $_ENV['DBA_PLATFORM']) {
self::markTestSkipped("We don't test all variants of expectations for all drivers");
}

$expected = [
[
"Query error: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL/MariaDB server version for the right syntax to use near 'freigabe1u1 FROM ada LIMIT 0' at line 1 (42000).",
Expand Down

0 comments on commit a2d990f

Please sign in to comment.