Skip to content

Commit

Permalink
bug #11676 [Form] Fixed #11675 ValueToDuplicatesTransformer accept "0…
Browse files Browse the repository at this point in the history
…" value (Nek-)

This PR was submitted for the master branch but it was merged into the 2.3 branch instead (closes #11676).

Discussion
----------

[Form] Fixed #11675 ValueToDuplicatesTransformer accept "0" value

| Q             | A
| ------------- | ---
| Bug fix?      | [yes]
| New feature?  | [no]
| BC breaks?    | [no]
| Deprecations? | [no]
| Tests pass?   | [yes]
| Fixed tickets | #11675
| License       | MIT

Commits
-------

31d48ab Fixed #11675 ValueToDuplicatesTransformer accept "0" value
  • Loading branch information
webmozart committed Aug 19, 2014
2 parents 3d59e34 + 31d48ab commit afab3ee
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 afab3ee

Please sign in to comment.