From 6075debeadef7778e9fb41ecfcff1543cf812759 Mon Sep 17 00:00:00 2001 From: Yonel Ceruto Date: Sun, 5 Jul 2020 20:44:22 -0400 Subject: [PATCH] Missing return in loadValuesForChoices method --- .../ChoiceList/Factory/Cache/ChoiceLoader.php | 2 +- .../Factory/Cache/ChoiceLoaderTest.php | 44 +++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 src/Symfony/Component/Form/Tests/ChoiceList/Factory/Cache/ChoiceLoaderTest.php diff --git a/src/Symfony/Component/Form/ChoiceList/Factory/Cache/ChoiceLoader.php b/src/Symfony/Component/Form/ChoiceList/Factory/Cache/ChoiceLoader.php index d8630dd854..f0e1067b90 100644 --- a/src/Symfony/Component/Form/ChoiceList/Factory/Cache/ChoiceLoader.php +++ b/src/Symfony/Component/Form/ChoiceList/Factory/Cache/ChoiceLoader.php @@ -46,6 +46,6 @@ final class ChoiceLoader extends AbstractStaticOption implements ChoiceLoaderInt */ public function loadValuesForChoices(array $choices, callable $value = null) { - $this->getOption()->loadValuesForChoices($choices, $value); + return $this->getOption()->loadValuesForChoices($choices, $value); } } diff --git a/src/Symfony/Component/Form/Tests/ChoiceList/Factory/Cache/ChoiceLoaderTest.php b/src/Symfony/Component/Form/Tests/ChoiceList/Factory/Cache/ChoiceLoaderTest.php new file mode 100644 index 0000000000..a96c838663 --- /dev/null +++ b/src/Symfony/Component/Form/Tests/ChoiceList/Factory/Cache/ChoiceLoaderTest.php @@ -0,0 +1,44 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Form\Tests\ChoiceList\Factory\Cache; + +use PHPUnit\Framework\TestCase; +use Symfony\Component\Form\ChoiceList\ArrayChoiceList; +use Symfony\Component\Form\ChoiceList\Factory\Cache\ChoiceLoader; +use Symfony\Component\Form\ChoiceList\Loader\CallbackChoiceLoader; +use Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface; +use Symfony\Component\Form\FormTypeInterface; + +class ChoiceLoaderTest extends TestCase +{ + public function testSameFormTypeUseCachedLoader() + { + $choices = ['f' => 'foo', 'b' => 'bar', 'z' => 'baz']; + $choiceList = new ArrayChoiceList($choices); + + $type = $this->createMock(FormTypeInterface::class); + $decorated = new CallbackChoiceLoader(static function () use ($choices) { + return $choices; + }); + $loader1 = new ChoiceLoader($type, $decorated); + $loader2 = new ChoiceLoader($type, $this->createMock(ChoiceLoaderInterface::class)); + + $this->assertEquals($choiceList, $loader1->loadChoiceList()); + $this->assertEquals($choiceList, $loader2->loadChoiceList()); + + $this->assertSame($choices, $loader1->loadChoicesForValues($choices)); + $this->assertSame($choices, $loader2->loadChoicesForValues($choices)); + + $this->assertSame($choices, $loader1->loadValuesForChoices($choices)); + $this->assertSame($choices, $loader2->loadValuesForChoices($choices)); + } +}