Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/Client/Output/GetOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* matches of a search: each `BatchGetItem` of 100 keys is read as the stream reaches it.
* {@see forEntity()} and {@see grouped()} read it as the other terminals do, so use one of them, and only once.
*
* @template Entity of AbstractEntity = never
* @template Entity of AbstractEntity
*
* @extends ReadOutput<Entity, int>
*
Expand Down
23 changes: 23 additions & 0 deletions tests/Unit/Client/GetOutputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,29 @@ public function testStreamsEveryEntityFlatAcrossTables(): void
static::assertSame([$a, $o], self::getOutput($a, $o)->toArray());
}

/**
* Iterated directly rather than through `toArray()`: PHPStan checks each `instanceof` against the type the loop
* gives the entities, which a template default of `never` on `GetOutput` made `never`.
*/
public function testIteratingHandsOutEntitiesOfEveryClass(): void
{
$a = new NormalEntity()->setAutofilledId('a')->setRequired('req');
$o = new OtherEntity()->setOtherId('o');

$normal = [];
$other = [];
foreach (self::getOutput($a, $o) as $entity) {
if ($entity instanceof NormalEntity) {
$normal[] = $entity;
} else {
$other[] = $entity;
}
}

static::assertSame([$a], $normal);
static::assertSame([$o], $other);
}

public function testBucketsEntitiesByTheirClass(): void
{
$a = new NormalEntity()->setAutofilledId('a')->setRequired('req');
Expand Down
Loading