8000 Fix the retrieval of the value with property path when using a loader by stof · Pull Request #15623 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Fix the retrieval of the value with property path when using a loader #15623

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
Aug 26, 2015
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
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,13 @@ public function createListFromLoader(ChoiceLoaderInterface $loader, $value = nul
if ($value instanceof PropertyPath) {
$accessor = $this->propertyAccessor;
$value = function ($choice) use ($accessor, $value) {
return $accessor->getValue($choice, $value);
// The callable may be invoked with a non-object/array value
// when such values are passed to
// ChoiceListInterface::getValuesForChoices(). Handle this case
// so that the call to getValue() doesn't break.
if (is_object($choice) || is_array($choice)) {
return $accessor->getValue($choice, $value);
}
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,36 @@ public function testCreateFromLoaderPropertyPath()
$this->assertSame('value', $this->factory->createListFromLoader($loader, 'property'));
}

// https://github.com/symfony/symfony/issues/5494
public function testCreateFromChoicesAssumeNullIfValuePropertyPathUnreadable()
{
$choices = array(null);

$this->decoratedFactory->expects($this->once())
->method('createListFromChoices')
->with($choices, $this->isInstanceOf('\Closure'))
->will($this->returnCallback(function ($choices, $callback) {
return array_map($callback, $choices);
}));

$this->assertSame(array(null), $this->factory->createListFromChoices($choices, 'property'));
}

// https://github.com/symfony/symfony/issues/5494
public function testCreateFromChoiceLoaderAssumeNullIfValuePropertyPathUnreadable()
{
$loader = $this->getMock('Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface');

$this->decoratedFactory->expects($this->once())
->method('createListFromLoader')
->with($loader, $this->isInstanceOf('\Closure'))
->will($this->returnCallback(function ($loader, $callback) {
return $callback(null);
}));

$this->assertNull($this->factory->createListFromLoader($loader, 'property'));
}

public function testCreateFromLoaderPropertyPathInstance()
{
$loader = $this->getMock('Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface');
Expand Down
< 3984 /copilot-diff-entry>
0