merged branch grizlik/master (PR #3261)

Commits
-------

b65a997 [Form] Added test ChoiceList::testGetChoicesForValuesCorrectOrderingOfResult for correct ordering check
a60daff [Form] Fixed incorrect sorting in ChoiceList::getChoicesForValues

Discussion
----------

[Form] Fixed incorrect sorting in ChoiceList::getChoicesForValues

ChoiceList::getChoicesForValues return collection with sorting, that not corresponding to the sorting for input keys

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

by bschussek at 2012-02-03T21:40:49Z

Can you adapt the test cases to fail for this case please? (probably by use of assertSame instead of assertEquals in one of the existing tests)

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

by grizlik at 2012-02-04T08:41:44Z

I need to create a new test or modify an existing one?

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

by bschussek at 2012-02-04T09:58:04Z

Something like this in ChoiceListTest:

    public function testGetChoicesForValuesReverseOrderedValues()
    {
        $values = array('2', '1');
        $this->assertSame(array($this->obj3, $this->obj2), $this->list->getChoicesForValues($values));
    }
This commit is contained in:
Fabien Potencier 2012-02-06 09:56:24 +01:00
commit 9855886dc5
2 changed files with 8 additions and 2 deletions

View File

@ -200,8 +200,8 @@ class ChoiceList implements ChoiceListInterface
$choices = array();
foreach ($this->values as $i => $value) {
foreach ($values as $j => $givenValue) {
foreach ($values as $j => $givenValue) {
foreach ($this->values as $i => $value) {
if ($value === $givenValue) {
$choices[] = $this->choices[$i];
unset($values[$j]);

View File

@ -146,6 +146,12 @@ class ChoiceListTest extends \PHPUnit_Framework_TestCase
$this->assertSame(array($this->obj2, $this->obj3), $this->list->getChoicesForValues($values));
}
public function testGetChoicesForValuesCorrectOrderingOfResult()
{
$values = array('2', '1');
$this->assertSame(array($this->obj3, $this->obj2), $this->list->getChoicesForValues($values));
}
public function testGetChoicesForValuesIgnoresNonExistingValues()
{
$values = array('1', '2', '5');