8000 bug #9665 [Bridge/Doctrine] ORMQueryBuilderLoader - handled the scena… · symfony/symfony@62d9cc8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 62d9cc8

Browse files
committed
bug #9665 [Bridge/Doctrine] ORMQueryBuilderLoader - handled the scenario when no entity manager is passed with closure query builder (jakzal)
This PR was merged into the 2.3 branch. Discussion ---------- [Bridge/Doctrine] ORMQueryBuilderLoader - handled the scenario when no entity manager is passed with closure query builder | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Commits ------- a534b55 Handled the scenario when no entity manager is passed with closure query builder.
2 parents 843b221 + a534b55 commit 62d9cc8

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

src/Symfony/Bridge/Doctrine/Form/ChoiceList/ORMQueryBuilderLoader.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ public function __construct($queryBuilder, $manager = null, $class = null)
4949
}
5050

5151
if ($queryBuilder instanceof \Closure) {
52+
if (!$manager instanceof EntityManager) {
53+
throw new UnexpectedTypeException($manager, 'Doctrine\ORM\EntityManager');
54+
}
55+
5256
$queryBuilder = $queryBuilder($manager->getRepository($class));
5357

5458
if (!$queryBuilder instanceof QueryBuilder) {
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bridge\Doctrine\Tests\Form\ChoiceList;
13+
14+
use Symfony\Bridge\Doctrine\Form\ChoiceList\ORMQueryBuilderLoader;
15+
16+
class ORMQueryBuilderLoaderTest extends \PHPUnit_Framework_TestCase
17+
{
18+
/**
19+
* @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException
20+
*/
21+
public function testItOnlyWorksWithQueryBuilderOrClosure()
22+
{
23+
new ORMQueryBuilderLoader(new \stdClass());
24+
}
25+
26+
/**
27+
* @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException
28+
*/
29+
public function testClosureRequiresTheEntityManager()
30+
{
31+
$closure = function () {};
32+
33+
new ORMQueryBuilderLoader($closure);
34+
}
35+
}

0 commit comments

Comments
 (0)
0