Skip to content

Commit

Permalink
Fixed #11675 ValueToDuplicatesTransformer accept "0" value
Browse files Browse the repository at this point in the history
Fixed wrong return null syntax

Added transformation to null on empty arrays

Removed useless statement in condition and switched to yoda condition
  • Loading branch information
Nek- authored and webmozart committed Aug 19, 2014
1 parent 3d59e34 commit 31d48ab
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Expand Up @@ -64,7 +64,7 @@ public function reverseTransform($array)
$emptyKeys = array();

foreach ($this->keys as $key) {
if (!empty($array[$key])) {
if (isset($array[$key]) && '' !== $array[$key] && false !== $array[$key] && array() !== $array[$key]) {
if ($array[$key] !== $result) {
throw new TransformationFailedException(
'All values in the array should be the same'
Expand Down
Expand Up @@ -82,6 +82,29 @@ public function testReverseTransformCompletelyNull()
$this->assertNull($this->transformer->reverseTransform($input));
}

public function testReverseTransformEmptyArray()
{
$input = array(
'a' => array(),
'b' => array(),
'c' => array(),
);

$this->assertNull($this->transformer->reverseTransform($input));
}


public function testReverseTransformZeroString()
{
$input = array(
'a' => '0',
'b' => '0',
'c' => '0'
);

$this->assertSame('0', $this->transformer->reverseTransform($input));
}

/**
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
*/
Expand Down

0 comments on commit 31d48ab

Please sign in to comment.