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
This commit is contained in:
Nek (Maxime Veber) 2014-08-15 14:15:04 +02:00 committed by Bernhard Schussek
parent 3d59e3417f
commit 31d48ab91f
2 changed files with 24 additions and 1 deletions

View File

@ -64,7 +64,7 @@ class ValueToDuplicatesTransformer implements DataTransformerInterface
$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'

View File

@ -82,6 +82,29 @@ class ValueToDuplicatesTransformerTest extends \PHPUnit_Framework_TestCase
$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
*/