From ea480bda3b040727937a538f5df59d10e87d6e68 Mon Sep 17 00:00:00 2001 From: Bernhard Schussek Date: Sat, 24 Aug 2013 17:43:39 +0200 Subject: [PATCH] [Form] Fixed Form::all() signature for PHP 5.3.3 --- src/Symfony/Component/Form/Form.php | 2 +- .../Util/VirtualFormAwareIteratorTest.php | 122 ------------------ .../Form/Util/ReferencingArrayIterator.php | 78 ----------- .../Form/Util/VirtualFormAwareIterator.php | 5 +- 4 files changed, 2 insertions(+), 205 deletions(-) delete mode 100644 src/Symfony/Component/Form/Tests/Util/VirtualFormAwareIteratorTest.php delete mode 100644 src/Symfony/Component/Form/Util/ReferencingArrayIterator.php diff --git a/src/Symfony/Component/Form/Form.php b/src/Symfony/Component/Form/Form.php index c4f744f1de..92014de3ed 100644 --- a/src/Symfony/Component/Form/Form.php +++ b/src/Symfony/Component/Form/Form.php @@ -832,7 +832,7 @@ class Form implements \IteratorAggregate, FormInterface /** * {@inheritdoc} */ - public function &all() + public function all() { return $this->children; } diff --git a/src/Symfony/Component/Form/Tests/Util/VirtualFormAwareIteratorTest.php b/src/Symfony/Component/Form/Tests/Util/VirtualFormAwareIteratorTest.php deleted file mode 100644 index 805acad903..0000000000 --- a/src/Symfony/Component/Form/Tests/Util/VirtualFormAwareIteratorTest.php +++ /dev/null @@ -1,122 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\Form\Tests\Util; - -use Symfony\Component\Form\Util\VirtualFormAwareIterator; - -/** - * @author Bernhard Schussek - */ -class VirtualFormAwareIteratorTest extends \PHPUnit_Framework_TestCase -{ - public function testSupportDynamicModification() - { - $form = $this->getMockForm('form'); - $formToBeAdded = $this->getMockForm('added'); - $formToBeRemoved = $this->getMockForm('removed'); - - $forms = array('form' => $form, 'removed' => $formToBeRemoved); - $iterator = new VirtualFormAwareIterator($forms); - - $iterator->rewind(); - $this->assertTrue($iterator->valid()); - $this->assertSame('form', $iterator->key()); - $this->assertSame($form, $iterator->current()); - - // dynamic modification - unset($forms['removed']); - $forms['added'] = $formToBeAdded; - - // continue iteration - $iterator->next(); - $this->assertTrue($iterator->valid()); - $this->assertSame('added', $iterator->key()); - $this->assertSame($formToBeAdded, $iterator->current()); - - // end of array - $iterator->next(); - $this->assertFalse($iterator->valid()); - } - - public function testSupportDynamicModificationInRecursiveCall() - { - $virtualForm = $this->getMockForm('virtual'); - $form = $this->getMockForm('form'); - $formToBeAdded = $this->getMockForm('added'); - $formToBeRemoved = $this->getMockForm('removed'); - - $virtualForm->getConfig()->expects($this->any()) - ->method('getVirtual') - ->will($this->returnValue(true)); - - $virtualForm->add($form); - $virtualForm->add($formToBeRemoved); - - $forms = array('virtual' => $virtualForm); - $iterator = new VirtualFormAwareIterator($forms); - - $iterator->rewind(); - $this->assertTrue($iterator->valid()); - $this->assertSame('virtual', $iterator->key()); - $this->assertSame($virtualForm, $iterator->current()); - $this->assertTrue($iterator->hasChildren()); - - // enter nested iterator - $nestedIterator = $iterator->getChildren(); - $this->assertSame('form', $nestedIterator->key()); - $this->assertSame($form, $nestedIterator->current()); - $this->assertFalse($nestedIterator->hasChildren()); - - // dynamic modification - $virtualForm->remove('removed'); - $virtualForm->add($formToBeAdded); - - // continue iteration - nested iterator discovers change in the form - $nestedIterator->next(); - $this->assertTrue($nestedIterator->valid()); - $this->assertSame('added', $nestedIterator->key()); - $this->assertSame($formToBeAdded, $nestedIterator->current()); - - // end of array - $nestedIterator->next(); - $this->assertFalse($nestedIterator->valid()); - } - - /** - * @param string $name - * - * @return \PHPUnit_Framework_MockObject_MockObject - */ - protected function getMockForm($name = 'name') - { - $config = $this->getMock('Symfony\Component\Form\FormConfigInterface'); - - $config->expects($this->any()) - ->method('getName') - ->will($this->returnValue($name)); - $config->expects($this->any()) - ->method('getCompound') - ->will($this->returnValue(true)); - $config->expects($this->any()) - ->method('getDataMapper') - ->will($this->returnValue($this->getMock('Symfony\Component\Form\DataMapperInterface'))); - $config->expects($this->any()) - ->method('getEventDispatcher') - ->will($this->returnValue($this->getMock('Symfony\Component\EventDispatcher\EventDispatcher'))); - - return $this->getMockBuilder('Symfony\Component\Form\Form') - ->setConstructorArgs(array($config)) - ->disableArgumentCloning() - ->setMethods(array('getViewData')) - ->getMock(); - } -} diff --git a/src/Symfony/Component/Form/Util/ReferencingArrayIterator.php b/src/Symfony/Component/Form/Util/ReferencingArrayIterator.php deleted file mode 100644 index 9bb64d79d2..0000000000 --- a/src/Symfony/Component/Form/Util/ReferencingArrayIterator.php +++ /dev/null @@ -1,78 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\Form\Util; - -/** - * Iterator that traverses an array. - * - * Contrary to {@link \ArrayIterator}, this iterator recognizes changes in the - * original array during iteration. - * - * @author Bernhard Schussek - */ -class ReferencingArrayIterator implements \Iterator -{ - /** - * @var array - */ - private $array; - - /** - * Creates a new iterator. - * - * @param array $array An array - */ - public function __construct(array &$array) - { - $this->array = &$array; - } - - /** - *{@inheritdoc} - */ - public function current() - { - return current($this->array); - } - - /** - *{@inheritdoc} - */ - public function next() - { - next($this->array); - } - - /** - *{@inheritdoc} - */ - public function key() - { - return key($this->array); - } - - /** - *{@inheritdoc} - */ - public function valid() - { - return null !== key($this->array); - } - - /** - *{@inheritdoc} - */ - public function rewind() - { - reset($this->array); - } -} diff --git a/src/Symfony/Component/Form/Util/VirtualFormAwareIterator.php b/src/Symfony/Component/Form/Util/VirtualFormAwareIterator.php index 2648c3a501..3060bedc0c 100644 --- a/src/Symfony/Component/Form/Util/VirtualFormAwareIterator.php +++ b/src/Symfony/Component/Form/Util/VirtualFormAwareIterator.php @@ -14,15 +14,12 @@ namespace Symfony\Component\Form\Util; /** * Iterator that traverses an array of forms. * - * Contrary to {@link \ArrayIterator}, this iterator recognizes changes in the - * original array during iteration. - * * You can wrap the iterator into a {@link \RecursiveIterator} in order to * enter any virtual child form and iterate the children of that virtual form. * * @author Bernhard Schussek */ -class VirtualFormAwareIterator extends ReferencingArrayIterator implements \RecursiveIterator +class VirtualFormAwareIterator extends \ArrayIterator implements \RecursiveIterator { /** *{@inheritdoc}