Handled the scenario when no entity manager is passed with closure query builder.
This commit is contained in:
parent
843b221f44
commit
a534b55fcb
@ -49,6 +49,10 @@ class ORMQueryBuilderLoader implements EntityLoaderInterface
|
||||
}
|
||||
|
||||
if ($queryBuilder instanceof \Closure) {
|
||||
if (!$manager instanceof EntityManager) {
|
||||
throw new UnexpectedTypeException($manager, 'Doctrine\ORM\EntityManager');
|
||||
}
|
||||
|
||||
$queryBuilder = $queryBuilder($manager->getRepository($class));
|
||||
|
||||
if (!$queryBuilder instanceof QueryBuilder) {
|
||||
|
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Bridge\Doctrine\Tests\Form\ChoiceList;
|
||||
|
||||
use Symfony\Bridge\Doctrine\Form\ChoiceList\ORMQueryBuilderLoader;
|
||||
|
||||
class ORMQueryBuilderLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException
|
||||
*/
|
||||
public function testItOnlyWorksWithQueryBuilderOrClosure()
|
||||
{
|
||||
new ORMQueryBuilderLoader(new \stdClass());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException
|
||||
*/
|
||||
public function testClosureRequiresTheEntityManager()
|
||||
{
|
||||
$closure = function () {};
|
||||
|
||||
new ORMQueryBuilderLoader($closure);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user