Skip to content

Commit

Permalink
[DoctrineBridge] Fixed caching in DoctrineType when "choices" or "pre…
Browse files Browse the repository at this point in the history
…ferred_choices" is passed
  • Loading branch information
webmozart committed Dec 7, 2012
1 parent 864cc85 commit ca5d9ac
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php
Expand Up @@ -77,16 +77,16 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
// 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);
});
}

Expand Down
Expand Up @@ -104,7 +104,7 @@ public function testCollapsedEntityField()
{
$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,
));
Expand All @@ -114,11 +114,14 @@ public function testCollapsedEntityField()
}
}

/**
* @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) {
Expand All @@ -130,4 +133,42 @@ public function testCollapsedEntityFieldWithQueryBuilder()
$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();
}
}
}

0 comments on commit ca5d9ac

Please sign in to comment.