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); +}