bug #23853 Filtering empty uuids in ORMQueryBuilderLoader. (mlazovla)

This PR was merged into the 2.7 branch.

Discussion
----------

Filtering empty uuids in ORMQueryBuilderLoader.

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #23808
| License       | MIT
| Doc PR        | no

Commits
-------

27e8cd289c Filtering empty uuids in ORMQueryBuilderLoader.
This commit is contained in:
Fabien Potencier 2017-09-11 05:33:33 -07:00
commit 47871c995f
4 changed files with 97 additions and 1 deletions

View File

@ -106,7 +106,7 @@ class ORMQueryBuilderLoader implements EntityLoaderInterface
$values = array_values(array_filter($values, function ($v) {
return (string) $v === (string) (int) $v || ctype_digit($v);
}));
} elseif ('guid' === $metadata->getTypeOfField($identifier)) {
} elseif (in_array($metadata->getTypeOfField($identifier), array('uuid', 'guid'))) {
$parameterType = Connection::PARAM_STR_ARRAY;
// Like above, but we just filter out empty strings.

View File

@ -0,0 +1,28 @@
<?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\Fixtures;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
/** @Entity */
class GuidIdEntity
{
/** @Id @Column(type="guid") */
protected $id;
public function __construct($id)
{
$this->id = $id;
}
}

View File

@ -0,0 +1,28 @@
<?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\Fixtures;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
/** @Entity */
class UuidIdEntity
{
/** @Id @Column(type="uuid") */
protected $id;
public function __construct($id)
{
$this->id = $id;
}
}

View File

@ -107,6 +107,38 @@ class ORMQueryBuilderLoaderTest extends TestCase
$loader->getEntitiesByIds('id', array(1, '', 2, 3, 'foo', '9223372036854775808'));
}
/**
* @dataProvider provideGuidEntityClasses
*/
public function testFilterEmptyUuids($entityClass)
{
$em = DoctrineTestHelper::createTestEntityManager();
$query = $this->getMockBuilder('QueryMock')
->setMethods(array('setParameter', 'getResult', 'getSql', '_doExecute'))
->getMock();
$query->expects($this->once())
->method('setParameter')
->with('ORMQueryBuilderLoader_getEntitiesByIds_id', array('71c5fd46-3f16-4abb-bad7-90ac1e654a2d', 'b98e8e11-2897-44df-ad24-d2627eb7f499'), Connection::PARAM_STR_ARRAY)
->willReturn($query);
$qb = $this->getMockBuilder('Doctrine\ORM\QueryBuilder')
->setConstructorArgs(array($em))
->setMethods(array('getQuery'))
->getMock();
$qb->expects($this->once())
->method('getQuery')
->willReturn($query);
$qb->select('e')
->from($entityClass, 'e');
$loader = new ORMQueryBuilderLoader($qb);
$loader->getEntitiesByIds('id', array('71c5fd46-3f16-4abb-bad7-90ac1e654a2d', '', 'b98e8e11-2897-44df-ad24-d2627eb7f499'));
}
public function testEmbeddedIdentifierName()
{
if (Version::compare('2.5.0') > 0) {
@ -140,4 +172,12 @@ class ORMQueryBuilderLoaderTest extends TestCase
$loader = new ORMQueryBuilderLoader($qb);
$loader->getEntitiesByIds('id.value', array(1, '', 2, 3, 'foo'));
}
public function provideGuidEntityClasses()
{
return array(
array('Symfony\Bridge\Doctrine\Tests\Fixtures\GuidIdEntity'),
array('Symfony\Bridge\Doctrine\Tests\Fixtures\UuidIdEntity'),
);
}
}