diff --git a/tests/Type/PHPUnit/AssertFunctionTypeSpecifyingExtensionTest.php b/tests/Type/PHPUnit/AssertFunctionTypeSpecifyingExtensionTest.php index 4014017..5a82043 100644 --- a/tests/Type/PHPUnit/AssertFunctionTypeSpecifyingExtensionTest.php +++ b/tests/Type/PHPUnit/AssertFunctionTypeSpecifyingExtensionTest.php @@ -20,6 +20,8 @@ public static function dataFileAsserts(): iterable yield from self::gatherAssertTypes(__DIR__ . '/data/assert-function-9.6.11.php'); } + yield from self::gatherAssertTypes(__DIR__ . '/data/bug-14279.php'); + return []; } diff --git a/tests/Type/PHPUnit/data/bug-14279.php b/tests/Type/PHPUnit/data/bug-14279.php new file mode 100644 index 0000000..d304831 --- /dev/null +++ b/tests/Type/PHPUnit/data/bug-14279.php @@ -0,0 +1,99 @@ + 'value'], + ]; + + $collection = (new TestCollection())->assignRecursive($data); + + static::assertCount(5, $collection); + + assertType("array{null, 0, 'some-string', stdClass, array{some: 'value'}}", $data); + static::assertSame($data[0], $collection->get(0)); + assertType("array{null, 0, 'some-string', stdClass, array{some: 'value'}}", $data); + static::assertSame($data[1], $collection->get(1)); + assertType("array{null, 0, 'some-string', stdClass, array{some: 'value'}}", $data); + static::assertSame($data[2], $collection->get(2)); + assertType("array{null, 0, 'some-string', stdClass, array{some: 'value'}}", $data); + static::assertSame($data[3], $collection->get(3)); + assertType("array{null, 0, 'some-string', stdClass, array{some: 'value'}}", $data); + static::assertSame($data[4], $collection->get(4)); + assertType("array{null, 0, 'some-string', stdClass, array{some: 'value'}}", $data); + } +} + +/** + * @template TElement + * + * @extends Collection + */ +class TestCollection extends Collection +{ +} + +/** + * @template TElement + * + * @implements \IteratorAggregate + */ +abstract class Collection implements \IteratorAggregate, \Countable +{ + /** + * @var array + */ + protected array $elements = []; + + /** + * @param iterable $elements + */ + public function __construct(iterable $elements = []) + { + } + + /** + * @param array-key $key + * + * @return TElement|null + */ + public function get($key) + { + return $this->elements[$key] ?? null; + } + + /** + * @phpstan-impure + */ + public function count(): int + { + return \count($this->elements); + } + + /** + * @return \Traversable + */ + public function getIterator(): \Traversable + { + yield from $this->elements; + } + + public function assignRecursive(array $options): static + { + return $this; + } +}