[DoctrineBridge] Fixed caching in DoctrineType when "choices" or "preferred_choices" is passed
This commit is contained in:
parent
864cc8598f
commit
ca5d9acb19
@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user