From 44551e48f94380e44de41fef888218f7bfd6dbe0 Mon Sep 17 00:00:00 2001 From: Michal Haltuf Date: Wed, 22 Apr 2026 19:08:15 +0200 Subject: [PATCH] Selection: insert() phpDoc covers documented bulk form Reported in https://forum.nette.org/cs/36954 --- src/Database/Table/Selection.php | 5 ++--- tests/types/TypesTest.phpt | 1 + tests/types/database-types.php | 30 ++++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/Database/Table/Selection.php b/src/Database/Table/Selection.php index 76603ccd9..c79fe19ec 100644 --- a/src/Database/Table/Selection.php +++ b/src/Database/Table/Selection.php @@ -810,9 +810,8 @@ public function getDataRefreshed(): bool /** * Inserts one or more rows into the table. - * Returns the inserted ActiveRow for single-row inserts, or the number of affected rows otherwise. - * @param iterable|Selection $data - * @return ($data is array ? T|array : int) + * @param iterable|list>|Selection $data + * @return T|array|int */ public function insert(iterable $data): ActiveRow|array|int { diff --git a/tests/types/TypesTest.phpt b/tests/types/TypesTest.phpt index 1bd53e017..6bbbf6406 100644 --- a/tests/types/TypesTest.phpt +++ b/tests/types/TypesTest.phpt @@ -5,3 +5,4 @@ require __DIR__ . '/../bootstrap.php'; use Nette\PHPStan\Tester\TypeAssert; TypeAssert::assertTypes(__DIR__ . '/database-types.php'); +TypeAssert::assertNoErrors(__DIR__ . '/database-types.php'); diff --git a/tests/types/database-types.php b/tests/types/database-types.php index d553a9282..556a5758f 100644 --- a/tests/types/database-types.php +++ b/tests/types/database-types.php @@ -116,3 +116,33 @@ function testResultSetFetchPairs(ResultSet $resultSet): void { assertType('array', $resultSet->fetchPairs()); } + + +/** @param Selection $selection */ +function testSelectionInsertSingleRow(Selection $selection): void +{ + $result = $selection->insert(['name' => 'Alice']); + assertType('array|int|Nette\Database\Table\ActiveRow', $result); +} + + +/** @param Selection $selection */ +function testSelectionInsertBulk(Selection $selection): void +{ + $result = $selection->insert([ + ['name' => 'Alice'], + ['name' => 'Bob'], + ]); + assertType('array|int|Nette\Database\Table\ActiveRow', $result); +} + + +/** + * @param Selection $selection + * @param Selection $source + */ +function testSelectionInsertFromSelection(Selection $selection, Selection $source): void +{ + $result = $selection->insert($source); + assertType('array|int|Nette\Database\Table\ActiveRow', $result); +}