From e818d9caa462d1a9b77ad49a1e576dc13c2d03da Mon Sep 17 00:00:00 2001 From: Tigrov Date: Sun, 17 Dec 2023 11:21:23 +0700 Subject: [PATCH 1/4] Test `Command::insertWithReturningPks()` with empty values --- tests/Common/CommonCommandTest.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/Common/CommonCommandTest.php b/tests/Common/CommonCommandTest.php index 220b60786..568ed8db1 100644 --- a/tests/Common/CommonCommandTest.php +++ b/tests/Common/CommonCommandTest.php @@ -2015,4 +2015,15 @@ public function testDecimalValue(): void $this->assertSame($decimalValue, $phpTypecastValue); } + + public function testInsertWithReturningPksEmptyValues() + { + $db = $this->getConnection(true); + + $pkValues = $db->createCommand()->insertWithReturningPks('null_values', []); + + $this->assertSame(['id' => 1], $pkValues); + + $db->createCommand()->dropTable('null_values')->execute(); + } } From 4833ae27aec90ba9dc097131b2c3d8f4782335f3 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Sun, 17 Dec 2023 11:28:17 +0700 Subject: [PATCH 2/4] Update test --- tests/Common/CommonCommandTest.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/Common/CommonCommandTest.php b/tests/Common/CommonCommandTest.php index 568ed8db1..602043907 100644 --- a/tests/Common/CommonCommandTest.php +++ b/tests/Common/CommonCommandTest.php @@ -2022,7 +2022,12 @@ public function testInsertWithReturningPksEmptyValues() $pkValues = $db->createCommand()->insertWithReturningPks('null_values', []); - $this->assertSame(['id' => 1], $pkValues); + $expected = match ($db->getDriverName()) { + 'pgsql' => ['id' => 1], + default => ['id' => '1'], + }; + + $this->assertSame($expected, $pkValues); $db->createCommand()->dropTable('null_values')->execute(); } From e9810d22aaef406e6aae2c57394511f18b0a96dd Mon Sep 17 00:00:00 2001 From: Tigrov Date: Sun, 17 Dec 2023 11:37:22 +0700 Subject: [PATCH 3/4] Update test --- tests/Common/CommonCommandTest.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/Common/CommonCommandTest.php b/tests/Common/CommonCommandTest.php index 602043907..7cc5ecaa2 100644 --- a/tests/Common/CommonCommandTest.php +++ b/tests/Common/CommonCommandTest.php @@ -2028,7 +2028,5 @@ public function testInsertWithReturningPksEmptyValues() }; $this->assertSame($expected, $pkValues); - - $db->createCommand()->dropTable('null_values')->execute(); } } From 8f4cea55462e7be5229714c6c9e5b37ad24e4c37 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Sun, 17 Dec 2023 15:01:53 +0700 Subject: [PATCH 4/4] Add test with empty pk --- tests/Common/CommonCommandTest.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/Common/CommonCommandTest.php b/tests/Common/CommonCommandTest.php index 7cc5ecaa2..89710879f 100644 --- a/tests/Common/CommonCommandTest.php +++ b/tests/Common/CommonCommandTest.php @@ -2029,4 +2029,13 @@ public function testInsertWithReturningPksEmptyValues() $this->assertSame($expected, $pkValues); } + + public function testInsertWithReturningPksEmptyValuesAndNoPk() + { + $db = $this->getConnection(true); + + $pkValues = $db->createCommand()->insertWithReturningPks('negative_default_values', []); + + $this->assertSame([], $pkValues); + } }