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
Original file line number Diff line number Diff line change
Expand Up @@ -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 [];
}

Expand Down
99 changes: 99 additions & 0 deletions tests/Type/PHPUnit/data/bug-14279.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php declare(strict_types=1);

namespace Shopware\Tests\Unit\Core\Framework\Struct;

use PHPUnit\Framework\TestCase;
use function PHPStan\Testing\assertType;

/**
* @internal
*/
class CollectionTest extends TestCase
{
public function testFromAssociative(): void
{
$data = [
null,
0,
'some-string',
new \stdClass(),
['some' => '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<TElement>
*/
class TestCollection extends Collection
{
}

/**
* @template TElement
*
* @implements \IteratorAggregate<array-key, TElement>
*/
abstract class Collection implements \IteratorAggregate, \Countable
{
/**
* @var array<array-key, TElement>
*/
protected array $elements = [];

/**
* @param iterable<TElement> $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<TElement>
*/
public function getIterator(): \Traversable
{
yield from $this->elements;
}

public function assignRecursive(array $options): static
{
return $this;
}
}
Loading