Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/Database/Table/Selection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, mixed>|Selection<ActiveRow> $data
* @return ($data is array<string, mixed> ? T|array<string, mixed> : int)
* @param iterable<string, mixed>|list<array<string, mixed>>|Selection<ActiveRow> $data
* @return T|array<int|string, mixed>|int
*/
public function insert(iterable $data): ActiveRow|array|int
{
Expand Down
1 change: 1 addition & 0 deletions tests/types/TypesTest.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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');
30 changes: 30 additions & 0 deletions tests/types/database-types.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,33 @@ function testResultSetFetchPairs(ResultSet $resultSet): void
{
assertType('array<mixed>', $resultSet->fetchPairs());
}


/** @param Selection<ActiveRow> $selection */
function testSelectionInsertSingleRow(Selection $selection): void
{
$result = $selection->insert(['name' => 'Alice']);
assertType('array<int|string, mixed>|int|Nette\Database\Table\ActiveRow', $result);
}


/** @param Selection<ActiveRow> $selection */
function testSelectionInsertBulk(Selection $selection): void
{
$result = $selection->insert([
['name' => 'Alice'],
['name' => 'Bob'],
]);
assertType('array<int|string, mixed>|int|Nette\Database\Table\ActiveRow', $result);
}


/**
* @param Selection<ActiveRow> $selection
* @param Selection<ActiveRow> $source
*/
function testSelectionInsertFromSelection(Selection $selection, Selection $source): void
{
$result = $selection->insert($source);
assertType('array<int|string, mixed>|int|Nette\Database\Table\ActiveRow', $result);
}