[Form] Created failing test for PropertyPath modifying collections while iterating them
This commit is contained in:
parent
46ffbd5282
commit
076a104e86
@ -15,12 +15,34 @@ use Symfony\Component\Form\Util\PropertyPath;
|
||||
|
||||
class PropertyPathCollectionTest_Car
|
||||
{
|
||||
private $axes;
|
||||
|
||||
public function __construct($axes = null)
|
||||
{
|
||||
$this->axes = $axes;
|
||||
}
|
||||
|
||||
// In the test, use a name that FormUtil can't uniquely singularify
|
||||
public function addAxis($axis) {}
|
||||
public function addAxis($axis)
|
||||
{
|
||||
$this->axes[] = $axis;
|
||||
}
|
||||
|
||||
public function removeAxis($axis) {}
|
||||
public function removeAxis($axis)
|
||||
{
|
||||
foreach ($this->axes as $key => $value) {
|
||||
if ($value === $axis) {
|
||||
unset($this->axes[$key]);
|
||||
|
||||
public function getAxes() {}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getAxes()
|
||||
{
|
||||
return $this->axes;
|
||||
}
|
||||
}
|
||||
|
||||
class PropertyPathCollectionTest_CarCustomSingular
|
||||
@ -70,26 +92,19 @@ abstract class PropertyPathCollectionTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testSetValueCallsAdderAndRemoverForCollections()
|
||||
{
|
||||
$car = $this->getMock(__CLASS__ . '_Car');
|
||||
$axesBefore = $this->getCollection(array(1 => 'second', 3 => 'fourth'));
|
||||
$axesAfter = $this->getCollection(array(0 => 'first', 1 => 'second', 2 => 'third'));
|
||||
$axesBefore = $this->getCollection(array(1 => 'second', 3 => 'fourth', 4 => 'fifth'));
|
||||
$axesMerged = $this->getCollection(array(1 => 'first', 2 => 'second', 3 => 'third'));
|
||||
$axesAfter = $this->getCollection(array(1 => 'second', 5 => 'first', 6 => 'third'));
|
||||
|
||||
// Don't use a mock in order to test whether the collections are
|
||||
// modified while iterating them
|
||||
$car = new PropertyPathCollectionTest_Car($axesBefore);
|
||||
|
||||
$path = new PropertyPath('axes');
|
||||
|
||||
$car->expects($this->at(0))
|
||||
->method('getAxes')
|
||||
->will($this->returnValue($axesBefore));
|
||||
$car->expects($this->at(1))
|
||||
->method('removeAxis')
|
||||
->with('fourth');
|
||||
$car->expects($this->at(2))
|
||||
->method('addAxis')
|
||||
->with('first');
|
||||
$car->expects($this->at(3))
|
||||
->method('addAxis')
|
||||
->with('third');
|
||||
$path->setValue($car, $axesMerged);
|
||||
|
||||
$path->setValue($car, $axesAfter);
|
||||
$this->assertEquals($axesAfter, $car->getAxes());
|
||||
}
|
||||
|
||||
public function testSetValueCallsAdderAndRemoverForNestedCollections()
|
||||
|
Reference in New Issue
Block a user