Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 31d48ab

Browse files
Nek-webmozart
authored andcommitted
Fixed #11675 ValueToDuplicatesTransformer accept "0" value
Fixed wrong return null syntax Added transformation to null on empty arrays Removed useless statement in condition and switched to yoda condition
1 parent 3d59e34 commit 31d48ab

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/Symfony/Component/Form/Extension/Core/DataTransformer/ValueToDuplicatesTransformer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function reverseTransform($array)
6464
$emptyKeys = array();
6565

6666
foreach ($this->keys as $key) {
67-
if (!empty($array[$key])) {
67+
if (isset($array[$key]) && '' !== $array[$key] && false !== $array[$key] && array() !== $array[$key]) {
6868
if ($array[$key] !== $result) {
6969
throw new TransformationFailedException(
7070
'All values in the array should be the same'

src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/ValueToDuplicatesTransformerTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,29 @@ public function testReverseTransformCompletelyNull()
8282
$this->assertNull($this->transformer->reverseTransform($input));
8383
}
8484

85+
public function testReverseTransformEmptyArray()
86+
{
87+
$input = array(
88+
'a' => array(),
89+
'b' => array(),
90+
'c' => array(),
91+
);
92+
93+
$this->assertNull($this->transformer->reverseTransform($input));
94+
}
95+
96+
97+
public function testReverseTransformZeroString()
98+
{
99+
$input = array(
100+
'a' => '0',
101+
'b' => '0',
102+
'c' => '0'
103+
);
104+
105+
$this->assertSame('0', $this->transformer->reverseTransform($input));
106+
}
107+
85108
/**
86109
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
87110
*/

0 commit comments

Comments
 (0)