Skip to content

Commit 7ac6005

Browse files
committed
Missing return in loadValuesForChoices method
1 parent e972224 commit 7ac6005

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

ChoiceList/Factory/Cache/ChoiceLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,6 @@ public function loadChoicesForValues(array $values, callable $value = null)
4646
*/
4747
public function loadValuesForChoices(array $choices, callable $value = null)
4848
{
49-
$this->getOption()->loadValuesForChoices($choices, $value);
49+
return $this->getOption()->loadValuesForChoices($choices, $value);
5050
}
5151
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Form\Tests\ChoiceList\Factory\Cache;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Form\ChoiceList\ArrayChoiceList;
16+
use Symfony\Component\Form\ChoiceList\Factory\Cache\ChoiceLoader;
17+
use Symfony\Component\Form\ChoiceList\Loader\CallbackChoiceLoader;
18+
use Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface;
19+
use Symfony\Component\Form\FormTypeInterface;
20+
21+
class ChoiceLoaderTest extends TestCase
22+
{
23+
public function testSameFormTypeUseCachedLoader()
24+
{
25+
$choices = ['f' => 'foo', 'b' => 'bar', 'z' => 'baz'];
26+
$choiceList = new ArrayChoiceList($choices);
27+
28+
$type = $this->createMock(FormTypeInterface::class);
29+
$decorated = new CallbackChoiceLoader(static function () use ($choices) {
30+
return $choices;
31+
});
32+
$loader1 = new ChoiceLoader($type, $decorated);
33+
$loader2 = new ChoiceLoader($type, $this->createMock(ChoiceLoaderInterface::class));
34+
35+
$this->assertEquals($choiceList, $loader1->loadChoiceList());
36+
$this->assertEquals($choiceList, $loader2->loadChoiceList());
37+
38+
$this->assertSame($choices, $loader1->loadChoicesForValues($choices));
39+
$this->assertSame($choices, $loader2->loadChoicesForValues($choices));
40+
41+
$this->assertSame($choices, $loader1->loadValuesForChoices($choices));
42+
$this->assertSame($choices, $loader2->loadValuesForChoices($choices));
43+
}
44+
}

0 commit comments

Comments
 (0)