Skip to content

Commit

Permalink
Add FormBuilderIteratorTest and provide php-ini setting for precision
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Meier committed Apr 11, 2016
1 parent 2d74c3c commit 79b453f
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 7 deletions.
76 changes: 76 additions & 0 deletions Tests/Util/FormBuilderIteratorTest.php
Original file line number Diff line number Diff line change
@@ -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
{
}
7 changes: 1 addition & 6 deletions Util/FormBuilderIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,7 @@ public function __construct(FormBuilderInterface $formBuilder, $prefix = false)
*/
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());
}

/**
Expand Down
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
"jms/di-extra-bundle": "~1.7",
"sensio/generator-bundle": "~2.3|~3.0",
"symfony/yaml": "~2.3|~3.0",
"symfony/security-acl": "~2.4|~3.0",
"phpunit/phpunit": "~4.3",
"sonata-project/intl-bundle": "^2.2.4",
"symfony/phpunit-bridge": "~2.7|~3.0"
},
Expand Down
6 changes: 5 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
stopOnFailure="false"
syntaxCheck="false"
bootstrap="Tests/tests/bootstrap.php"
>
>
<testsuites>
<testsuite name="AdminBundle Test Suite">
<directory>./Tests</directory>
Expand All @@ -30,4 +30,8 @@
</whitelist>
</filter>

<php>
<ini name="precision" value="8"/>
</php>

</phpunit>

0 comments on commit 79b453f

Please sign in to comment.