bug #37499 [Form] Missing return in loadValuesForChoices method (yceruto)

This PR was merged into the 5.1 branch.

Discussion
----------

[Form] Missing return in loadValuesForChoices method

| Q             | A
| ------------- | ---
| Branch?       | 5.1
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

Commits
-------

6075debead Missing return in loadValuesForChoices method
This commit is contained in:
Fabien Potencier 2020-07-06 08:32:18 +02:00
commit 309b06201a
2 changed files with 45 additions and 1 deletions

View File

@ -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);
}
}

View File

@ -0,0 +1,44 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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));
}
}