minor #21867 [Form] fix BC layer for form type guessers (xabbuh)

This PR was merged into the 3.3-dev branch.

Discussion
----------

[Form] fix BC layer for form type guessers

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

Commits
-------

5c38c4f [Form] fix BC layer for form type guessers
This commit is contained in:
Nicolas Grekas 2017-03-04 17:06:00 +01:00
commit 8953d0bc85
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')