From fd1ad653950ca44478be7f4e3394da28e5f25fb4 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Sat, 17 Aug 2024 15:22:56 -0700 Subject: [PATCH] Add support for empty test result --- tests/TestUtil.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/tests/TestUtil.php b/tests/TestUtil.php index ba54b07fd4..eb6b64657b 100644 --- a/tests/TestUtil.php +++ b/tests/TestUtil.php @@ -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; @@ -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; } }