8000 Merge branch '2.3' · symfony/symfony@95483e5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 95483e5

Browse files
committed
Merge branch '2.3'
* 2.3: Fixed docblock in UserInterface::getSalt() [Process] Fix #8970 : read output once the process is finished, enable pipe tests on Windows [DoctrineBridge] Improved test coverage of EntityChoiceList [DoctrineBridge] Improved test coverage of EntityChoiceList [Form] Improved test coverage of ChoiceList classes [Form] Fixed expanded choice field to be marked invalid when unknown choices are submitted [Form] Fixed ChoiceList::get*By*() methods to preserve order and array keys [Form] Removed usage of the ChoiceList::getIndicesFor*() methods where they don't offer any performance benefit [Form] Improved test coverage of ChoiceList classes [Form] Fixed expanded choice field to be marked invalid when unknown choices are submitted [Form] Fixed ChoiceList::get*By*() methods to preserve order and array keys [Form] Removed usage of the ChoiceList::getIndicesFor*() methods where they don't offer any performance benefit Removed duplicate annotation [HttpKernel] made code more reliable [HttpFoundation] fixed regression in the way the request format is handled for duplicated requests (closes #8917) [HttpKernel] fixer HInclude src (closes #8951) Fixed escaping of service identifiers in configuration Conflicts: src/Symfony/Bridge/Doctrine/Tests/Form/ChoiceList/GenericEntityChoiceListTest.php src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php src/Symfony/Component/HttpKernel/Tests/Fragment/HIncludeFragmentRendererTest.php
2 parents ea8359a + 51413e1 commit 95483e5

File tree

63 files changed

+2194
-901
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+2194
-901
lines changed

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

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,26 @@ public function getChoicesForValues(array $values)
208208
// Optimize performance in case we have an entity loader and
209209
// a single-field identifier
210210
if ($this->idAsValue && $this->entityLoader) {
211-
if (empty($values)) {
212-
return array();
211+
$unorderedEntities = $this->entityLoader->getEntitiesByIds($this->idField, $values);
212+
$entitiesByValue = array();
213+
$entities = array();
214+
215+
// Maintain order and indices from the given $values
216+
// An alternative approach to the following loop is to add the
217+
// "INDEX BY" clause to the Doctrine query in the loader,
218+
// but I'm not sure whether that's doable in a generic fashion.
219+
foreach ($unorderedEntities as $entity) {
220+
$value = $this->fixValue(current($this->getIdentifierValues($entity)));
221+
$entitiesByValue[$value] = $entity;
213222
}
214223

215-
return $this->entityLoader->getEntitiesByIds($this->idField, $values);
224+
foreach ($values as $i => $value) {
225+
if (isset($entitiesByValue[$value])) {
226+
$entities[$i] = $entitiesByValue[$value];
227+
}
228+
}
229+
230+
return $entities;
216231
}
217232

218233
$this->load();
@@ -240,10 +255,10 @@ public function getValuesForChoices(array $entities)
240255
if ($this->idAsValue) {
241256
$values = array();
242257

243-
foreach ($entities as $entity) {
258+
foreach ($entities as $i => $entity) {
244259
if ($entity instanceof $this->class) {
245260
// Make sure to convert to the right format
246-
$values[] = $this->fixValue(current($this->getIdentifierValues($entity)));
261+
$values[$i] = $this->fixValue(current($this->getIdentifierValues($entity)));
247262
}
248263
}
249264

@@ -275,10 +290,10 @@ public function getIndicesForChoices(array $entities)
275290
if ($this->idAsIndex) {
276291
$indices = array();
277292

278-
foreach ($entities as $entity) {
293+
foreach ($entities as $i => $entity) {
279294
if ($entity instanceof $this->class) {
280295
// Make sure to convert to the right format
281-
$indices[] = $this->fixIndex(current($this->getIdentifierValues($entity)));
296+
$indices[$i] = $this->fixIndex(current($this->getIdentifierValues($entity)));
282297
}
283298
}
284299

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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\Test;
13+
14+
use Doctrine\Common\Annotations\AnnotationReader;
15+
use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
16+
use Doctrine\ORM\EntityManager;
17+
18+
/**
19+
* Provides utility functions needed in tests.
20+
*
21+
* @author Bernhard Schussek <bschussek@gmail.com>
22+
*/
23+
class DoctrineTestHelper
24+
{
25+
/**
26+
* Returns an entity manager for testing.
27+
*
28+
* @return EntityManager
29+
*/
30+
public static function createTestEntityManager()
31+
{
32+
if (!class_exists('PDO') || !in_array('sqlite', \PDO::getAvailableDrivers())) {
33+
\PHPUnit_Framework_TestCase::markTestSkipped('This test requires SQLite support in your environment');
34+
}
35+
36+
$config = new \Doctrine\ORM\Configuration();
37+
$config->setEntityNamespaces(array('SymfonyTestsDoctrine' => 'Symfony\Bridge\Doctrine\Tests\Fixtures'));
38+
$config->setAutoGenerateProxyClasses(true);
39+
$config->setProxyDir(\sys_get_temp_dir());
40+
$config->setProxyNamespace('SymfonyTests\Doctrine');
41+
$config->setMetadataDriverImpl(new AnnotationDriver(new AnnotationReader()));
42+
$config->setQueryCacheImpl(new \Doctrine\Common\Cache\ArrayCache());
43+
$config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache());
44+
45+
$params = array(
46+
'driver' => 'pdo_sqlite',
47+
'memory' => true,
48+
);
49+
50+
return EntityManager::create($params, $config);
51+
}
52+
53+
/**
54+
* This class cannot be instantiated.
55+
*/
56+
private function __construct()
57+
{
58+
}
59+
}

src/Symfony/Bridge/Doctrine/Tests/DoctrineOrmTestCase.php

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,21 @@
1111

1212
namespace Symfony\Bridge\Doctrine\Tests;
1313

14-
use Doctrine\Common\Annotations\AnnotationReader;
15-
use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
16-
use Doctrine\ORM\EntityManager;
14+
use Symfony\Bridge\Doctrine\Test\DoctrineTestHelper;
1715

16+
/**
17+
* Class DoctrineOrmTestCase
18+
*
19+
* @deprecated Deprecated as of Symfony 2.4, to be removed in Symfony 3.0.
20+
* Use {@link DoctrineTestHelper} instead.
21+
*/
1822
abstract class DoctrineOrmTestCase extends \PHPUnit_Framework_TestCase
1923
{
2024
/**
21-
* @return EntityManager
25+
* @return \Doctrine\ORM\EntityManager
2226
*/
23-
public static function createTestEntityManager($paths = array())
27+
public static function createTestEntityManager()
2428
{
25-
if (!class_exists('PDO') || !in_array('sqlite', \PDO::getAvailableDrivers())) {
26-
self::markTestSkipped('This test requires SQLite support in your environment');
27-
}
28-
$config = new \Doctrine\ORM\Configuration();
29-
$config->setEntityNamespaces(array('SymfonyTestsDoctrine' => 'Symfony\Bridge\Doctrine\Tests\Fixtures'));
30-
$config->setAutoGenerateProxyClasses(true);
31-
$config->setProxyDir(\sys_get_temp_dir());
32-
$config->setProxyNamespace('SymfonyTests\Doctrine');
33-
$config->setMetadataDriverImpl(new AnnotationDriver(new AnnotationReader()));
34-
$config->setQueryCacheImpl(new \Doctrine\Common\Cache\ArrayCache());
35-
$config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache());
36-
37-
$params = array(
38-
'driver' => 'pdo_sqlite',
39-
'memory' => true,
40-
);
41-
42-
return EntityManager::create($params, $config);
29+
return DoctrineTestHelper::createTestEntityManager();
4330
}
4431
}

src/Symfony/Bridge/Doctrine/Tests/Fixtures/AssociationEntity.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,18 @@ class AssociationEntity
2626
private $id;
2727

2828
/**
29-
* @ORM\ManyToOne(targetEntity="SingleIdentEntity")
30-
* @var \Symfony\Bridge\Doctrine\Tests\Form\Fixtures\SingleIdentEntity
29+
* @ORM\ManyToOne(targetEntity="SingleIntIdEntity")
30+
* @var \Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdEntity
3131
*/
3232
public $single;
3333

3434
/**
35-
* @ORM\ManyToOne(targetEntity="CompositeIdentEntity")
35+
* @ORM\ManyToOne(targetEntity="CompositeIntIdEntity")
3636
* @ORM\JoinColumns({
3737
* @ORM\JoinColumn(name="composite_id1", referencedColumnName="id1"),
3838
* @ORM\JoinColumn(name="composite_id2", referencedColumnName="id2")
3939
* })
40-
* @var \Symfony\Bridge\Doctrine\Tests\Form\Fixtures\CompositeIdentEntity
40+
* @var \Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeIntIdEntity
4141
*/
4242
public $composite;
4343
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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\Fixtures;
13+
14+
use Doctrine\ORM\Mapping\Id;
15+
use Doctrine\ORM\Mapping\Column;
16+
use Doctrine\ORM\Mapping\Entity;
17+
18+
/** @Entity */
19+
class CompositeIntIdEntity
20+
{
21+
/** @Id @Column(type="integer") */
22+
protected $id1;
23+
24+
/** @Id @Column(type="integer") */
25+
protected $id2;
26+
27+
/** @Column(type="string") */
28+
public $name;
29+
30+
public function __construct($id1, $id2, $name)
31+
{
32+
$this->id1 = $id1;
33+
$this->id2 = $id2;
34+
$this->name = $name;
35+
}
36+
37+
public function __toString()
38+
{
39+
return $this->name;
40+
}
41+
}

src/Symfony/Bridge/Doctrine/Tests/Fixtures/CompositeStringIdentEntity.php renamed to src/Symfony/Bridge/Doctrine/Tests/Fixtures/CompositeStringIdEntity.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use Doctrine\ORM\Mapping\Entity;
1717

1818
/** @Entity */
19-
class CompositeStringIdentEntity
19+
class CompositeStringIdEntity
2020
{
2121
/** @Id @Column(type="string") */
2222
protected $id1;
@@ -33,4 +33,9 @@ public function __construct($id1, $id2, $name)
3333
$this->id2 = $id2;
3434
$this->name = $name;
3535
}
36+
37+
public function __toString()
38+
{
39+
return $this->name;
40+
}
3641
}

src/Symfony/Bridge/Doctrine/Tests/Fixtures/DoubleIdentEntity.php renamed to src/Symfony/Bridge/Doctrine/Tests/Fixtures/DoubleNameEntity.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use Doctrine\ORM\Mapping\Entity;
1717

1818
/** @Entity */
19-
class DoubleIdentEntity
19+
class DoubleNameEntity
2020
{
2121
/** @Id @Column(type="integer") */
2222
protected $id;

src/Symfony/Bridge/Doctrine/Tests/Fixtures/ItemGroupEntity.php renamed to src/Symfony/Bridge/Doctrine/Tests/Fixtures/GroupableEntity.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use Doctrine\ORM\Mapping\Entity;
1717

1818
/** @Entity */
19-
class ItemGroupEntity
19+
class GroupableEntity
2020
{
2121
/** @Id @Column(type="integer") */
2222
protected $id;

src/Symfony/Bridge/Doctrine/Tests/Fixtures/SingleIdentEntity.php renamed to src/Symfony/Bridge/Doctrine/Tests/Fixtures/SingleIntIdEntity.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use Doctrine\ORM\Mapping\Entity;
1717

1818
/** @Entity */
19-
class SingleIdentEntity
19+
class SingleIntIdEntity
2020
{
2121
/** @Id @Column(type="integer") */
2222
protected $id;

src/Symfony/Bridge/Doctrine/Tests/Fixtures/NoToStringSingleIdentEntity.php renamed to src/Symfony/Bridge/Doctrine/Tests/Fixtures/SingleIntIdNoToStringEntity.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use Doctrine\ORM\Mapping\Entity;
1717

1818
/** @Entity */
19-
class NoToStringSingleIdentEntity
19+
class SingleIntIdNoToStringEntity
2020
{
2121
/** @Id @Column(type="integer") */
2222
protected $id;

0 commit comments

Comments
 (0)
0