Skip to content

Commit

Permalink
Merge pull request #314 from boesing/feature/selectable-collection
Browse files Browse the repository at this point in the history
Make `Selectable#matching` return `Collection`
  • Loading branch information
greg0ire authored Aug 18, 2022
2 parents 0fdfe2b + 7f86e63 commit 07d15c8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/Doctrine/Common/Collections/Selectable.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ interface Selectable
* Selects all elements from a selectable that match the expression and
* returns a new collection containing these elements.
*
* @return Collection<mixed>
* @psalm-return Collection<TKey,T>
* @return Collection<mixed>&Selectable<mixed>
* @psalm-return Collection<TKey,T>&Selectable<TKey,T>
*/
public function matching(Criteria $criteria);
}
15 changes: 15 additions & 0 deletions tests/Doctrine/Tests/Common/Collections/BaseCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
namespace Doctrine\Tests\Common\Collections;

use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\Criteria;
use Doctrine\Common\Collections\Selectable;
use PHPUnit\Framework\TestCase;
use stdClass;

use function count;
use function is_array;
use function is_numeric;
use function is_string;
use function sprintf;

abstract class BaseCollectionTest extends TestCase
{
Expand Down Expand Up @@ -237,4 +240,16 @@ public function testCanVerifyExistingKeysWithNullValues(): void
$this->collection->set('key', null);
self::assertTrue($this->collection->containsKey('key'));
}

public function testMatchingAlwaysReturnsCollection(): void
{
if (! $this->collection instanceof Selectable) {
self::markTestSkipped(sprintf('Collection does not implement %s', Selectable::class));
}

$criteria = Criteria::create();

self::assertInstanceOf(Collection::class, $this->collection->matching($criteria));
self::assertInstanceOf(Selectable::class, $this->collection->matching($criteria));
}
}

0 comments on commit 07d15c8

Please sign in to comment.