|
14 | 14 | use PHPUnit\Framework\TestCase; |
15 | 15 | use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException; |
16 | 16 | use Symfony\Component\Form\Extension\DependencyInjection\DependencyInjectionExtension; |
| 17 | +use Symfony\Component\Form\FormTypeGuesserChain; |
| 18 | +use Symfony\Component\Form\FormTypeGuesserInterface; |
17 | 19 |
|
18 | 20 | class DependencyInjectionExtensionTest extends TestCase |
19 | 21 | { |
@@ -107,6 +109,49 @@ public function testLegacyThrowExceptionForInvalidExtendedType() |
107 | 109 | $extension->getTypeExtensions('test'); |
108 | 110 | } |
109 | 111 |
|
| 112 | + public function testGetTypeGuesser() |
| 113 | + { |
| 114 | + $container = $this->createContainerMock(); |
| 115 | + $extension = new DependencyInjectionExtension($container, array(), array($this->getMockBuilder(FormTypeGuesserInterface::class)->getMock())); |
| 116 | + |
| 117 | + $this->assertInstanceOf(FormTypeGuesserChain::class, $extension->getTypeGuesser()); |
| 118 | + } |
| 119 | + |
| 120 | + public function testGetTypeGuesserReturnsNullWhenNoTypeGuessersHaveBeenConfigured() |
| 121 | + { |
| 122 | + $container = $this->createContainerMock(); |
| 123 | + $extension = new DependencyInjectionExtension($container, array(), array()); |
| 124 | + |
| 125 | + $this->assertNull($extension->getTypeGuesser()); |
| 126 | + } |
| 127 | + |
| 128 | + /** |
| 129 | + * @group legacy |
| 130 | + */ |
| 131 | + public function testLegacyGetTypeGuesser() |
| 132 | + { |
| 133 | + $container = $this->createContainerMock(); |
| 134 | + $container |
| 135 | + ->expects($this->once()) |
| 136 | + ->method('get') |
| 137 | + ->with('foo') |
| 138 | + ->willReturn($this->getMockBuilder(FormTypeGuesserInterface::class)->getMock()); |
| 139 | + $extension = new DependencyInjectionExtension($container, array(), array(), array('foo')); |
| 140 | + |
| 141 | + $this->assertInstanceOf(FormTypeGuesserChain::class, $extension->getTypeGuesser()); |
| 142 | + } |
| 143 | + |
| 144 | + /** |
| 145 | + * @group legacy |
| 146 | + */ |
| 147 | + public function testLegacyGetTypeGuesserReturnsNullWhenNoTypeGuessersHaveBeenConfigured() |
| 148 | + { |
| 149 | + $container = $this->createContainerMock(); |
| 150 | + $extension = new DependencyInjectionExtension($container, array(), array(), array()); |
| 151 | + |
| 152 | + $this->assertNull($extension->getTypeGuesser()); |
| 153 | + } |
| 154 | + |
110 | 155 | private function createContainerMock() |
111 | 156 | { |
112 | 157 | return $this->getMockBuilder('Psr\Container\ContainerInterface') |
|
0 commit comments