merged branch bschussek/issue6190 (PR #6216)

This PR was merged into the 2.1 branch.

Commits
-------

ca5d9ac [DoctrineBridge] Fixed caching in DoctrineType when "choices" or "preferred_choices" is passed

Discussion
----------

[DoctrineBridge] Fixed caching in DoctrineType when "choices" or "preferred_choices" is passed

Bug fix: yes
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: yes
Fixes the following tickets: #6190
Todo: -
License of the code: MIT
Documentation PR: n/a

---------------------------------------------------------------------------

by craue at 2012-12-06T18:31:43Z

👍

---------------------------------------------------------------------------

by lstrojny at 2012-12-06T18:35:04Z

What about a test?

---------------------------------------------------------------------------

by bschussek at 2012-12-07T12:39:51Z

Removed CHANGELOG entries and added tests.

---------------------------------------------------------------------------

by craue at 2012-12-07T13:14:02Z

I'm not sure if @fabpot is objected to the changelog entry entirely or just the version number. What is the segfault about for PHP 5.4 in Travis?
This commit is contained in:
Fabien Potencier 2012-12-07 14:19:21 +01:00
commit 992707ea6c
2 changed files with 47 additions and 6 deletions

View File

@ -77,16 +77,16 @@ abstract class DoctrineType extends AbstractType
// A second parameter ($key) is passed, so we cannot use
// spl_object_hash() directly (which strictly requires
// one parameter)
array_walk_recursive($choiceHashes, function ($value) {
return spl_object_hash($value);
array_walk_recursive($choiceHashes, function (&$value) {
$value = spl_object_hash($value);
});
}
$preferredChoiceHashes = $options['preferred_choices'];
if (is_array($preferredChoiceHashes)) {
array_walk_recursive($preferredChoiceHashes, function ($value) {
return spl_object_hash($value);
array_walk_recursive($preferredChoiceHashes, function (&$value) {
$value = spl_object_hash($value);
});
}

View File

@ -104,7 +104,7 @@ class EntityTypePerformanceTest extends FormPerformanceTestCase
{
$this->setMaxRunningTime(1);
for ($i = 0; $i < 20; ++$i) {
for ($i = 0; $i < 40; ++$i) {
$form = $this->factory->create('entity', null, array(
'class' => self::ENTITY_CLASS,
));
@ -114,11 +114,14 @@ class EntityTypePerformanceTest extends FormPerformanceTestCase
}
}
/**
* @group benchmark
*/
public function testCollapsedEntityFieldWithQueryBuilder()
{
$this->setMaxRunningTime(1);
for ($i = 0; $i < 20; ++$i) {
for ($i = 0; $i < 40; ++$i) {
$form = $this->factory->create('entity', null, array(
'class' => self::ENTITY_CLASS,
'query_builder' => function (EntityRepository $repo) {
@ -130,4 +133,42 @@ class EntityTypePerformanceTest extends FormPerformanceTestCase
$form->createView();
}
}
/**
* @group benchmark
*/
public function testCollapsedEntityFieldWithChoices()
{
$choices = $this->em->createQuery('SELECT c FROM ' . self::ENTITY_CLASS . ' c')->getResult();
$this->setMaxRunningTime(1);
for ($i = 0; $i < 40; ++$i) {
$form = $this->factory->create('entity', null, array(
'class' => self::ENTITY_CLASS,
'choices' => $choices,
));
// force loading of the choice list
$form->createView();
}
}
/**
* @group benchmark
*/
public function testCollapsedEntityFieldWithPreferredChoices()
{
$choices = $this->em->createQuery('SELECT c FROM ' . self::ENTITY_CLASS . ' c')->getResult();
$this->setMaxRunningTime(1);
for ($i = 0; $i < 40; ++$i) {
$form = $this->factory->create('entity', null, array(
'class' => self::ENTITY_CLASS,
'preferred_choices' => $choices,
));
// force loading of the choice list
$form->createView();
}
}
}