FormFactoryBuilderTest.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  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 Symfony\Component\Form\Tests;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\Form\FormFactoryBuilder;
  13. use Symfony\Component\Form\Tests\Fixtures\LegacyFooType;
  14. class FormFactoryBuilderTest extends TestCase
  15. {
  16. private $registry;
  17. private $guesser;
  18. private $type;
  19. protected function setUp()
  20. {
  21. $factory = new \ReflectionClass('Symfony\Component\Form\FormFactory');
  22. $this->registry = $factory->getProperty('registry');
  23. $this->registry->setAccessible(true);
  24. $this->guesser = $this->getMockBuilder('Symfony\Component\Form\FormTypeGuesserInterface')->getMock();
  25. $this->type = new LegacyFooType();
  26. }
  27. public function testAddType()
  28. {
  29. $factoryBuilder = new FormFactoryBuilder();
  30. $factoryBuilder->addType($this->type);
  31. $factory = $factoryBuilder->getFormFactory();
  32. $registry = $this->registry->getValue($factory);
  33. $extensions = $registry->getExtensions();
  34. $this->assertCount(1, $extensions);
  35. $this->assertTrue($extensions[0]->hasType($this->type->getName()));
  36. $this->assertNull($extensions[0]->getTypeGuesser());
  37. }
  38. public function testAddTypeGuesser()
  39. {
  40. $factoryBuilder = new FormFactoryBuilder();
  41. $factoryBuilder->addTypeGuesser($this->guesser);
  42. $factory = $factoryBuilder->getFormFactory();
  43. $registry = $this->registry->getValue($factory);
  44. $extensions = $registry->getExtensions();
  45. $this->assertCount(1, $extensions);
  46. $this->assertNotNull($extensions[0]->getTypeGuesser());
  47. }
  48. }