Skip to content

Commit

Permalink
Add support for empty test result
Browse files Browse the repository at this point in the history
  • Loading branch information
morozov committed Aug 18, 2024
1 parent c7b249b commit fd1ad65
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion tests/TestUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
use InvalidArgumentException;
use PHPUnit\Framework\Assert;

use function array_fill;
use function array_map;
use function assert;
use function count;
use function extension_loaded;
use function file_exists;
use function implode;
Expand Down Expand Up @@ -269,16 +271,30 @@ public static function isDriverOneOf(string ...$names): bool
*/
public static function generateResultSetQuery(array $columnNames, array $rows, AbstractPlatform $platform): string
{
return implode(' UNION ALL ', array_map(static function (array $row) use ($columnNames, $platform): string {
$isEmpty = count($rows) === 0;

if ($isEmpty) {
$rows = [array_fill(0, count($columnNames), null)];
}

$query = implode(' UNION ALL ', array_map(static function (array $row) use ($columnNames, $platform): string {
return $platform->getDummySelectSQL(
implode(', ', array_map(static function (string $column, $value) use ($platform): string {
if (is_string($value)) {
$value = $platform->quoteStringLiteral($value);
} elseif ($value === null) {
$value = 'NULL';
}

return $value . ' ' . $platform->quoteIdentifier($column);
}, $columnNames, $row)),
);
}, $rows));

if ($isEmpty) {
$query .= ' WHERE NULL IS NOT NULL';
}

return $query;
}
}

0 comments on commit fd1ad65

Please sign in to comment.