소스 검색

Merge pull request #3714 from mikemeier/master

Add FormBuilderIteratorTest and provide php-ini setting for precision
Sullivan SENECHAL 9 년 전
부모
커밋
52d016981d
3개의 변경된 파일81개의 추가작업 그리고 6개의 파일을 삭제
  1. 76 0
      Tests/Util/FormBuilderIteratorTest.php
  2. 1 6
      Util/FormBuilderIterator.php
  3. 4 0
      phpunit.xml.dist

+ 76 - 0
Tests/Util/FormBuilderIteratorTest.php

@@ -0,0 +1,76 @@
+<?php
+
+/*
+ * This file is part of the Sonata Project package.
+ *
+ * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Sonata\AdminBundle\Tests\Util;
+
+use Sonata\AdminBundle\Util\FormBuilderIterator;
+use Symfony\Component\EventDispatcher\EventDispatcherInterface;
+use Symfony\Component\Form\FormBuilder;
+use Symfony\Component\Form\FormFactoryInterface;
+
+/**
+ * @author Mike Meier <mike.meier@ibrows.ch>
+ */
+class FormBuilderIteratorTest extends \PHPUnit_Framework_TestCase
+{
+    /**
+     * @var EventDispatcherInterface
+     */
+    private $dispatcher;
+
+    /**
+     * @var FormFactoryInterface
+     */
+    private $factory;
+
+    /**
+     * @var FormBuilder
+     */
+    private $builder;
+
+    protected function setUp()
+    {
+        $this->dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
+        $this->factory = $this->getMock('Symfony\Component\Form\FormFactoryInterface');
+        $this->builder = new TestFormBuilder('name', null, $this->dispatcher, $this->factory);
+        $this->factory->expects($this->any())->method('createNamedBuilder')->willReturn($this->builder);
+    }
+
+    protected function tearDown()
+    {
+        $this->dispatcher = null;
+        $this->factory = null;
+        $this->builder = null;
+    }
+
+    public function testConstructor()
+    {
+        new FormBuilderIterator($this->builder);
+    }
+
+    public function testGetChildren()
+    {
+        $this->builder->add('name', 'text');
+        $iterator = new FormBuilderIterator($this->builder);
+        $this->assertInstanceOf(get_class($iterator), $iterator->getChildren());
+    }
+
+    public function testHasChildren()
+    {
+        $this->builder->add('name', 'text');
+        $iterator = new FormBuilderIterator($this->builder);
+        $this->assertTrue($iterator->hasChildren());
+    }
+}
+
+class TestFormBuilder extends FormBuilder
+{
+}

+ 1 - 6
Util/FormBuilderIterator.php

@@ -65,12 +65,7 @@ class FormBuilderIterator extends \RecursiveArrayIterator
      */
     private static function getKeys(FormBuilderInterface $formBuilder)
     {
-        if (!self::$reflection) {
-            self::$reflection = new \ReflectionProperty(get_class($formBuilder), 'children');
-            self::$reflection->setAccessible(true);
-        }
-
-        return array_keys(self::$reflection->getValue($formBuilder));
+        return array_keys($formBuilder->all());
     }
 
     /**

+ 4 - 0
phpunit.xml.dist

@@ -30,4 +30,8 @@
         </whitelist>
     </filter>
 
+    <php>
+        <ini name="precision" value="8"/>
+    </php>
+
 </phpunit>