FormBuilderIteratorTest.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /*
  3. * This file is part of the Sonata Project package.
  4. *
  5. * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Sonata\AdminBundle\Tests\Util;
  11. use Sonata\AdminBundle\Util\FormBuilderIterator;
  12. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  13. use Symfony\Component\Form\FormBuilder;
  14. use Symfony\Component\Form\FormFactoryInterface;
  15. /**
  16. * @author Mike Meier <mike.meier@ibrows.ch>
  17. */
  18. class FormBuilderIteratorTest extends \PHPUnit_Framework_TestCase
  19. {
  20. /**
  21. * @var EventDispatcherInterface
  22. */
  23. private $dispatcher;
  24. /**
  25. * @var FormFactoryInterface
  26. */
  27. private $factory;
  28. /**
  29. * @var FormBuilder
  30. */
  31. private $builder;
  32. protected function setUp()
  33. {
  34. $this->dispatcher = $this->getMockForAbstractClass('Symfony\Component\EventDispatcher\EventDispatcherInterface');
  35. $this->factory = $this->getMockForAbstractClass('Symfony\Component\Form\FormFactoryInterface');
  36. $this->builder = new TestFormBuilder('name', null, $this->dispatcher, $this->factory);
  37. $this->factory->expects($this->any())->method('createNamedBuilder')->willReturn($this->builder);
  38. }
  39. protected function tearDown()
  40. {
  41. $this->dispatcher = null;
  42. $this->factory = null;
  43. $this->builder = null;
  44. }
  45. public function testConstructor()
  46. {
  47. new FormBuilderIterator($this->builder);
  48. }
  49. public function testGetChildren()
  50. {
  51. $this->builder->add('name', 'text');
  52. $iterator = new FormBuilderIterator($this->builder);
  53. $this->assertInstanceOf(get_class($iterator), $iterator->getChildren());
  54. }
  55. public function testHasChildren()
  56. {
  57. $this->builder->add('name', 'text');
  58. $iterator = new FormBuilderIterator($this->builder);
  59. $this->assertTrue($iterator->hasChildren());
  60. }
  61. }
  62. class TestFormBuilder extends FormBuilder
  63. {
  64. }