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:
parent
3d59e3417f
commit
31d48ab91f
|
@ -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'
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
|
Reference in New Issue