8000 [DoctrineBridge] Fixed caching in DoctrineType when "choices" or "preferred_choices" is passed by webmozart · Pull Request #6216 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 7, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[DoctrineBridge] Fixed caching in DoctrineType when "choices" or "pre…
…ferred_choices" is passed
  • Loading branch information
webmozart committed Dec 7, 2012
commit ca5d9acb19459c605c66c60e6b79e8ef5e57bbd9
8 changes: 4 additions & 4 deletions src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php
10000
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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