8000 adding tests · symfony/symfony@35c2c52 · GitHub
[go: up one dir, main page]

Skip to content

Commit 35c2c52

Browse files
author
hamza
committed
adding tests
1 parent 39e9859 commit 35c2c52

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

src/Symfony/Component/Form/ChoiceList/Factory/PropertyAccessDecorator.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,12 @@ public function createListFromChoices($choices, $value = null)
8787
if (is_string($value) && !is_callable($value)) {
8888
$value = new PropertyPath($value);
8989
} elseif (is_string($value) && is_callable($value)) {
90-
@trigger_error('createListFromChoices() treats callable strings as callable and is deprecated since version 3.1.', E_USER_DEPRECATED);
91-
$value = function ($choice) use ($value) {
92-
return $value($choice);
90+
@trigger_error('createListFromChoices() - Treating strings as callable is deprecated since version 3.1 and will throw an error in 4.0. You should use a "\Closure" instead', E_USER_DEPRECATED);
91+
$value = function (array $choices) use ($value) {
92+
return $value($choices);
9393
};
94+
95+
return $value($choices);
9496
}
9597

9698
if ($value instanceof PropertyPath) {
@@ -123,9 +125,9 @@ public function createListFromLoader(ChoiceLoaderInterface $loader, $value = nul
123125
if (is_string($value) && !is_callable($value)) {
124126
$value = new PropertyPath($value);
125127
} elseif (is_string($value) && is_callable($value)) {
126-
@trigger_error('createListFromLoader() treats callable strings as callable and is deprecated since version 3.1.', E_USER_DEPRECATED);
127-
$value = function ($choice) use ($value) {
128-
return $value($choice);
128+
@trigger_error('createListFromLoader() - Treating strings as callable is deprecated since version 3.1 and will throw an error in 4.0. You should use a "\Closure" instead', E_USER_DEPRECATED);
129+
$value = function ($choices) use ($value) {
130+
return $value($choices);
129131
};
130132
}
131133

@@ -169,6 +171,7 @@ public function createView(ChoiceListInterface $list, $preferredChoices = null,
169171
$label = function ($choice) use ($label) {
170172
return $label($choice);
171173
};
174+
172175
}
173176

174177
if ($label instanceof PropertyPath) {

src/Symfony/Component/Form/Tests/ChoiceList/Factory/PropertyAccessDecoratorTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,18 @@ public function testCreateFromChoicesPropertyPathInstance()
6363
$this->assertSame(array('value'), $this->factory->createListFromChoices($choices, new PropertyPath('property')));
6464
}
6565

66+
public function testCreateFromChoicesPropertyPathWithCallableString()
67+
{
68+
$choices = array(array('property' => 'value'));
69+
70+
$this->decoratedFactory->expects($this->once())
71+
->method('createListFromChoices')
72+
->with($choices,'count')
73+
->will($this->returnValue(0));
74+
75+
$this->assertEquals(count($choices), $this->factory->createListFromChoices($choices,'count'));
76+
}
77+
6678
public function testCreateFromLoaderPropertyPath()
6779
{
6880
$loader = $this->getMock('Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface');

0 commit comments

Comments
 (0)
0