8000 [DoctrineBridge] Fixed caching in DoctrineType when "choices" or "pre… · symfony/symfony@ca5d9ac · GitHub
[go: up one dir, main page]

Skip to content

Commit ca5d9ac

Browse files
committed
[DoctrineBridge] Fixed caching in DoctrineType when "choices" or "preferred_choices" is passed
1 parent 864cc85 commit ca5d9ac

File tree

2 files changed

+47
-6
lines changed

2 files changed

+47
-6
lines changed

src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,16 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
7777
// A second parameter ($key) is passed, so we cannot use
7878
// spl_object_hash() directly (which strictly requires
7979
// one parameter)
80-
array_walk_recursive($choiceHashes, function ($value) {
81-
return spl_object_hash($value);
80+
array_walk_recursive($choiceHashes, function (&$value) {
81+
$value = spl_object_hash($value);
8282
});
8383
}
8484

8585
$preferredChoiceHashes = $options['preferred_choices'];
8686

8787
if (is_array($preferredChoiceHashes)) {
88-
array_walk_recursive($preferredChoiceHashes, function ($value) {
89-
return spl_object_hash($value);
88+
array_walk_recursive($preferredChoiceHashes, function (&$value) {
89+
$value = spl_object_hash($value);
9090
});
9191
}
9292

src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypePerformanceTest.php

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public function testCollapsedEntityField()
104104
{
105105
$this->setMaxRunningTime(1);
106106

107-
for ($i = 0; $i < 20; ++$i) {
107+
for ($i = 0; $i < 40; ++$i) {
108108
$form = $this->factory->create('entity', null, array(
109109
'class' => self::ENTITY_CLASS,
110110
));
@@ -114,11 +114,14 @@ public function testCollapsedEntityField()
114114
}
115115
}
116116

117+
/**
118+
* @group benchmark
119+
*/
117120
public function testCollapsedEntityFieldWithQueryBuilder()
118121
{
119122
$this->setMaxRunningTime(1);
120123

121-
for ($i = 0; $i < 20; ++$i) {
124+
for ($i = 0; $i < 40; ++$i) {
122125
$form = $this->factory->create('entity', null, array(
123126
'class' => self::ENTITY_CLASS,
124127
'query_builder' => function (EntityRepository $repo) {
@@ -130,4 +133,42 @@ public function testCollapsedEntityFieldWithQueryBuilder()
130133
$form->createView();
131134
}
132135
}
136+
137+
/**
138+
* @group benchmark
139+
*/
140+
public function testCollapsedEntityFieldWithChoices()
141+
{
142+
$choices = $this->em->createQuery('SELECT c FROM ' . self::ENTITY_CLASS . ' c')->getResult();
143+
$this->setMaxRunningTime(1);
144+
145+
for ($i = 0; $i < 40; ++$i) {
146+
$form = $this->factory->create('entity', null, array(
147+
'class' => self::ENTITY_CLASS,
148+
'choices' => $choices,
149+
));
150+
151+
// force loading of the choice list
152+
$form->createView();
153+
}
154+
}
155+
156+
/**
157+
* @group benchmark
158+
*/
159+
public function testCollapsedEntityFieldWithPreferredChoices()
160+
{
161+
$choices = $this->em->createQuery('SELECT c FROM ' . self::ENTITY_CLASS . ' c')->getResult();
162+
$this->setMaxRunningTime(1);
163+
164+
for ($i = 0; $i < 40; ++$i) {
165+
$form = $this->factory->create('entity', null, array(
166+
'class' => self::ENTITY_CLASS,
167+
'preferred_choices' => $choices,
168+
));
169+
170+
// force loading of the choice list
171+
$form->createView();
172+
}
173+
}
133174
}

0 commit comments

Comments
 (0)
0