merged branch kaywalker/master (PR #5394)

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

Commits
-------

08bd95e Fix to allow null values in labels array

Discussion
----------

Fix to allow null values in labels array

Fixed false positives on array key is null

---------------------------------------------------------------------------

by stof at 2012-08-30T19:03:02Z

@kaywalker This is still throwing a notice

---------------------------------------------------------------------------

by bschussek at 2012-08-31T09:13:33Z

Could you please add a test?

---------------------------------------------------------------------------

by fabpot at 2012-10-05T16:52:11Z

@bschussek Is it mergeable now?

---------------------------------------------------------------------------

by bschussek at 2012-10-05T16:58:34Z

The coding conventions in the test are not correct (too much indentation). Also, please reference this PR in a comment to the test. Last, the test should contain assertions to actually check something. Example:

```
    // https://github.com/symfony/symfony/pull/5394
    public function testLabelsContainingNull()
    {
        $this->list = new ChoiceList(
                array($this->obj1, $this->obj2),
                array('A', null)
        );

        $this->assertEquals(array(0 => new ChoiceView($this->obj1, '0', 'A'), 1 => new ChoiceView($this->obj2, '1', null)), $this->list->getRemainingViews());
    }
```

---------------------------------------------------------------------------

by fmeynard at 2012-11-13T17:36:59Z

I just tried the last commit and everything works correctly.
This commit is contained in:
Fabien Potencier 2012-12-11 09:06:04 +01:00
commit 20dd9d9351
2 changed files with 17 additions and 1 deletions

View File

@ -261,7 +261,7 @@ class ChoiceList implements ChoiceListInterface
{
// Add choices to the nested buckets
foreach ($choices as $group => $choice) {
if (!isset($labels[$group])) {
if (!array_key_exists($group, $labels)) {
throw new \InvalidArgumentException('The structures of the choices and labels array do not match.');
}

View File

@ -184,4 +184,20 @@ class ChoiceListTest extends \PHPUnit_Framework_TestCase
array('A')
);
}
/**
* test for pull request: https://github.com/symfony/symfony/pull/5394
*/
public function testLabelsContainingNull()
{
$this->list = new ChoiceList(
array($this->obj1, $this->obj2),
array('A', null)
);
$this->assertEquals(
array(0 => new ChoiceView($this->obj1, '0', 'A'), 1 => new ChoiceView($this->obj2, '1', null)),
$this->list->getRemainingViews()
);
}
}