[Form] fix BC layer for form type guessers

This commit is contained in:
Christian Flothmann 2017-03-04 16:52:39 +01:00
parent b118c650a3
commit 5c38c4f2e5
2 changed files with 46 additions and 0 deletions

View File

@ -42,6 +42,7 @@ class DependencyInjectionExtension implements FormExtensionInterface
$this->guesserServiceIds = $guesserServiceIds;
$this->typeServiceIds = $typeExtensionServices;
$typeExtensionServices = $guesserServices;
$guesserServices = $guesserServiceIds;
}
$this->typeContainer = $typeContainer;

View File

@ -14,6 +14,8 @@ namespace Symfony\Component\Form\Tests\Extension\DependencyInjection;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
use Symfony\Component\Form\Extension\DependencyInjection\DependencyInjectionExtension;
use Symfony\Component\Form\FormTypeGuesserChain;
use Symfony\Component\Form\FormTypeGuesserInterface;
class DependencyInjectionExtensionTest extends TestCase
{
@ -107,6 +109,49 @@ class DependencyInjectionExtensionTest extends TestCase
$extension->getTypeExtensions('test');
}
public function testGetTypeGuesser()
{
$container = $this->createContainerMock();
$extension = new DependencyInjectionExtension($container, array(), array($this->getMockBuilder(FormTypeGuesserInterface::class)->getMock()));
$this->assertInstanceOf(FormTypeGuesserChain::class, $extension->getTypeGuesser());
}
public function testGetTypeGuesserReturnsNullWhenNoTypeGuessersHaveBeenConfigured()
{
$container = $this->createContainerMock();
$extension = new DependencyInjectionExtension($container, array(), array());
$this->assertNull($extension->getTypeGuesser());
}
/**
* @group legacy
*/
public function testLegacyGetTypeGuesser()
{
$container = $this->createContainerMock();
$container
->expects($this->once())
->method('get')
->with('foo')
->willReturn($this->getMockBuilder(FormTypeGuesserInterface::class)->getMock());
$extension = new DependencyInjectionExtension($container, array(), array(), array('foo'));
$this->assertInstanceOf(FormTypeGuesserChain::class, $extension->getTypeGuesser());
}
/**
* @group legacy
*/
public function testLegacyGetTypeGuesserReturnsNullWhenNoTypeGuessersHaveBeenConfigured()
{
$container = $this->createContainerMock();
$extension = new DependencyInjectionExtension($container, array(), array(), array());
$this->assertNull($extension->getTypeGuesser());
}
private function createContainerMock()
{
return $this->getMockBuilder('Psr\Container\ContainerInterface')