From b197e565f0dfaf3cad8f77fc39a4965d8e79885a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Jodas?= Date: Mon, 25 Aug 2025 15:20:42 +0200 Subject: [PATCH 1/3] Add ResultHelper --- src/ResultHelper.php | 44 ++++++++++++++++++++++++++++ tests/Phpunit/ResultHelperTest.php | 47 ++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 src/ResultHelper.php create mode 100644 tests/Phpunit/ResultHelperTest.php diff --git a/src/ResultHelper.php b/src/ResultHelper.php new file mode 100644 index 0000000..9014dfb --- /dev/null +++ b/src/ResultHelper.php @@ -0,0 +1,44 @@ +, + * "data": array>, + * } $responseData + * @return array{ + * "columns": array, + * "data": array>, + * } + */ + public static function mapColumnNamesIntoData(array $responseData): array + { + $data = $responseData['data']; + $columnNames = array_column($responseData['columns'], 'name'); + + $transformedData = []; + foreach ($data as $row) { + assert(is_array($row)); + $transformedRow = []; + foreach ($row as $index => $value) { + if (isset($columnNames[$index])) { + $transformedRow[$columnNames[$index]] = $value; + } + } + $transformedData[] = $transformedRow; + } + $responseData['data'] = $transformedData; + return $responseData; + } +} diff --git a/tests/Phpunit/ResultHelperTest.php b/tests/Phpunit/ResultHelperTest.php new file mode 100644 index 0000000..5c800ff --- /dev/null +++ b/tests/Phpunit/ResultHelperTest.php @@ -0,0 +1,47 @@ + [ + ['name' => 'id', 'type' => 'text'], + ['name' => 'name', 'type' => 'text'], + ['name' => 'city', 'type' => 'text'], + ], + 'data' => [ + ['1', 'Alice', 'Prague'], + ['2', 'Bob', 'Liberec'], + ['3', 'Charlie', 'Brno', 'EXTRA'], + ], + ]; + + $expected = [ + 'columns' => [ + ['name' => 'id', 'type' => 'text'], + ['name' => 'name', 'type' => 'text'], + ['name' => 'city', 'type' => 'text'], + ], + 'data' => [ + ['id' => '1', 'name' => 'Alice', 'city' => 'Prague'], + ['id' => '2', 'name' => 'Bob', 'city' => 'Liberec'], + ['id' => '3', 'name' => 'Charlie', 'city' => 'Brno'], + ], + ]; + + $actual = ResultHelper::mapColumnNamesIntoData($input); + + // Columns should be preserved unchanged + $this->assertSame($expected['columns'], $actual['columns']); + // Data rows should be mapped by column names + $this->assertSame($expected['data'], $actual['data']); + } +} From cebb60133bfe983210e6b852598a2b2e8bb0bfa6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Jodas?= Date: Tue, 26 Aug 2025 21:31:38 +0200 Subject: [PATCH 2/3] fix statement status --- tests/Functional/QueryServiceFunctionalTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Functional/QueryServiceFunctionalTest.php b/tests/Functional/QueryServiceFunctionalTest.php index 365e461..adaf286 100644 --- a/tests/Functional/QueryServiceFunctionalTest.php +++ b/tests/Functional/QueryServiceFunctionalTest.php @@ -205,7 +205,7 @@ public function testQueryJobWithInvalidSQL(): void // The statement remains in 'waiting' status because the job failed before execution $statement = $statements[0]; assert(is_array($statement)); - $this->assertEquals('completed', $statement['status']); + $this->assertEquals('failed', $statement['status']); assert(is_string($statement['query'])); $this->assertEquals('SELECT * FROM non_existent_table_12345', $statement['query']); } From f2808ba80167b156bc9c9e6e0ad771e82e140f3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Kri=C5=A1ka?= Date: Wed, 27 Aug 2025 09:00:39 +0200 Subject: [PATCH 3/3] Update tests/Functional/QueryServiceFunctionalTest.php --- tests/Functional/QueryServiceFunctionalTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Functional/QueryServiceFunctionalTest.php b/tests/Functional/QueryServiceFunctionalTest.php index adaf286..9405f53 100644 --- a/tests/Functional/QueryServiceFunctionalTest.php +++ b/tests/Functional/QueryServiceFunctionalTest.php @@ -202,7 +202,6 @@ public function testQueryJobWithInvalidSQL(): void assert(is_array($statements)); $this->assertCount(1, $statements); - // The statement remains in 'waiting' status because the job failed before execution $statement = $statements[0]; assert(is_array($statement)); $this->assertEquals('failed', $statement['status']);