-
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[bug] RepositoryProxy::findOneBy() with $orderBy checks inner repo
ObjectRepository::findOneBy() does not declare an $orderBy parameter but some implementations (ie `Doctrine\ORM\EntityRepository`) add this. When passed, it is ensured the wrapped repository has this parameter. If not, a `\RuntimeException` is thrown instead of silently not ordering. Fixes #65
- Loading branch information
Showing
2 changed files
with
128 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
<?php | ||
|
||
namespace Zenstruck\Foundry\Tests\Unit; | ||
|
||
use Doctrine\Persistence\ObjectRepository; | ||
use PHPUnit\Framework\TestCase; | ||
use Zenstruck\Foundry\RepositoryProxy; | ||
|
||
/** | ||
* @author Kevin Bond <kevinbond@gmail.com> | ||
*/ | ||
final class RepositoryProxyTest extends TestCase | ||
{ | ||
/** | ||
* @test | ||
* @dataProvider objectRepositoryWithoutFindOneByOrderBy | ||
*/ | ||
public function calling_find_one_by_with_order_by_when_wrapped_repo_does_not_have_throws_exception(ObjectRepository $inner): void | ||
{ | ||
$proxy = new RepositoryProxy($inner); | ||
|
||
$this->expectException(\RuntimeException::class); | ||
|
||
$proxy->findOneBy([], ['id' => 'DESC']); | ||
} | ||
|
||
public static function objectRepositoryWithoutFindOneByOrderBy(): iterable | ||
{ | ||
yield [new RepositoryProxy(new class() implements ObjectRepository { | ||
public function find($id) | ||
{ | ||
} | ||
|
||
public function findAll() | ||
{ | ||
} | ||
|
||
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null) | ||
{ | ||
} | ||
|
||
public function findOneBy(array $criteria) | ||
{ | ||
} | ||
|
||
public function getClassName() | ||
{ | ||
} | ||
})]; | ||
|
||
yield [new RepositoryProxy(new class() implements ObjectRepository { | ||
public function find($id) | ||
{ | ||
} | ||
|
||
public function findAll() | ||
{ | ||
} | ||
|
||
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null) | ||
{ | ||
} | ||
|
||
public function findOneBy(array $criteria, ?array $foo = null) | ||
{ | ||
} | ||
|
||
public function getClassName() | ||
{ | ||
} | ||
})]; | ||
|
||
yield [new RepositoryProxy(new class() implements ObjectRepository { | ||
public function find($id) | ||
{ | ||
} | ||
|
||
public function findAll() | ||
{ | ||
} | ||
|
||
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null) | ||
{ | ||
} | ||
|
||
public function findOneBy(array $criteria, $orderBy = null) | ||
{ | ||
} | ||
|
||
public function getClassName() | ||
{ | ||
} | ||
})]; | ||
|
||
yield [new RepositoryProxy(new class() implements ObjectRepository { | ||
public function find($id) | ||
{ | ||
} | ||
|
||
public function findAll() | ||
{ | ||
} | ||
|
||
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null) | ||
{ | ||
} | ||
|
||
public function findOneBy(array $criteria, ?string $orderBy = null) | ||
{ | ||
} | ||
|
||
public function getClassName() | ||
{ | ||
} | ||
})]; | ||
} | ||
} |