Skip to content
This repository was archived by the owner on Aug 14, 2024. It is now read-only.
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 @@ -25,7 +25,7 @@ public function find($id) : ?array;
*
* @return mixed[][] The objects data.
*/
public function findAll() : array;
public function findAll() : iterable;

/**
* Finds objects data by a set of criteria.
Expand All @@ -46,7 +46,7 @@ public function findBy(
?array $orderBy = null,
?int $limit = null,
?int $offset = null
) : array;
) : iterable;

/**
* Finds a single objects data by a set of criteria.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function find($id)
*
* @return object[] The objects.
*/
public function findAll() : array
public function findAll() : iterable
{
$objectsData = $this->objectDataRepository->findAll();

Expand All @@ -108,7 +108,7 @@ public function findAll() : array
/**
* {@inheritDoc}
*/
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null) : array
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null) : iterable
{
$objectsData = $this->objectDataRepository->findBy(
$criteria,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Doctrine\SkeletonMapper\Tests\ObjectRepository;

use ArrayIterator;
use Doctrine\Common\EventManager;
use Doctrine\SkeletonMapper\DataRepository\ObjectDataRepositoryInterface;
use Doctrine\SkeletonMapper\Hydrator\ObjectHydratorInterface;
Expand Down Expand Up @@ -65,7 +66,21 @@ public function testFind() : void
self::assertEquals(new stdClass(), $object);
}

public function testFindAll() : void
/**
* @return bool[][]
*/
public function providerTestFind() : array
{
return [
[false],
[true],
];
}

/**
* @dataProvider providerTestFind
*/
public function testFindAll(bool $arrayIteratorReturns) : void
{
$data = [
['username' => 'jwage'],
Expand All @@ -89,11 +104,16 @@ public function testFindAll() : void
->with('TestClassName', $data[1])
->will(self::returnValue($object2));

$this->repository->setArrayIteratorReturn($arrayIteratorReturns);
$objects = $this->repository->findAll();
self::assertSame([$object1, $object2], $objects);

self::assertSame([$object1, $object2], $objects instanceof ArrayIterator ? $objects->getArrayCopy() : $objects);
}

public function testFindBy() : void
/**
* @dataProvider providerTestFind
*/
public function testFindBy(bool $arrayIteratorReturns) : void
{
$data = [
['username' => 'jwage'],
Expand All @@ -118,8 +138,10 @@ public function testFindBy() : void
->with('TestClassName', $data[1])
->will(self::returnValue($object2));

$this->repository->setArrayIteratorReturn($arrayIteratorReturns);
$objects = $this->repository->findBy([]);
self::assertSame([$object1, $object2], $objects);

self::assertSame([$object1, $object2], $objects instanceof ArrayIterator ? $objects->getArrayCopy() : $objects);
}

public function testFindOneBy() : void
Expand Down Expand Up @@ -203,6 +225,14 @@ protected function setUp() : void

class TestObjectRepository extends ObjectRepository
{
/** @var bool */
private $arrayIteratorReturn = false;

public function setArrayIteratorReturn(bool $returnArrayIterator) : void
{
$this->arrayIteratorReturn = $returnArrayIterator;
}

public function getClassMetadata() : ClassMetadataInterface
{
return $this->class;
Expand Down Expand Up @@ -234,4 +264,27 @@ public function getObjectIdentifierFromData(array $data) : array
public function merge($object) : void
{
}

/**
* @return mixed[]
*/
public function findAll() : iterable
{
$result = parent::findAll();
return $this->arrayIteratorReturn ? new ArrayIterator($result) : $result;
}

/**
* @param mixed[] $criteria
* @param string[]|null $orderBy
* @param mixed|null $limit
* @param mixed|null $offset
*
* @return mixed[]
*/
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null) : iterable
{
$result = parent::findBy($criteria, $orderBy, $limit, $offset);
return $this->arrayIteratorReturn ? new ArrayIterator($result) : $result;
}
}