diff --git a/src/Client/Output/GetOutput.php b/src/Client/Output/GetOutput.php index 84f6fb3..dea2544 100644 --- a/src/Client/Output/GetOutput.php +++ b/src/Client/Output/GetOutput.php @@ -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 * diff --git a/tests/Unit/Client/GetOutputTest.php b/tests/Unit/Client/GetOutputTest.php index 8bbb88f..2b37d71 100644 --- a/tests/Unit/Client/GetOutputTest.php +++ b/tests/Unit/Client/GetOutputTest.php @@ -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');