Skip to content

Commit 514005b

Browse files
committed
[Form] fix BC layer for form type guessers
1 parent ae07c30 commit 514005b

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

Extension/DependencyInjection/DependencyInjectionExtension.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public function __construct(ContainerInterface $typeContainer, array $typeExtens
4242
$this->guesserServiceIds = $guesserServiceIds;
4343
$this->typeServiceIds = $typeExtensionServices;
4444
$typeExtensionServices = $guesserServices;
45+
$guesserServices = $guesserServiceIds;
4546
}
4647

4748
$this->typeContainer = $typeContainer;

Tests/Extension/DependencyInjection/DependencyInjectionExtensionTest.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
1616
use Symfony\Component\Form\Extension\DependencyInjection\DependencyInjectionExtension;
17+
use Symfony\Component\Form\FormTypeGuesserChain;
18+
use Symfony\Component\Form\FormTypeGuesserInterface;
1719

1820
class DependencyInjectionExtensionTest extends TestCase
1921
{
@@ -107,6 +109,49 @@ public function testLegacyThrowExceptionForInvalidExtendedType()
107109
$extension->getTypeExtensions('test');
108110
}
109111

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+
110155
private function createContainerMock()
111156
{
112157
return $this->getMockBuilder('Psr\Container\ContainerInterface')

0 commit comments

Comments
 (0)