Skip to content

Commit

Permalink
Merge branch '4.2'
Browse files Browse the repository at this point in the history
* 4.2:
  replace mocks with real objects in tests
  • Loading branch information
nicolas-grekas committed Feb 8, 2019
2 parents 41cc6d2 + 37f6be1 commit 5ed68ee
Showing 1 changed file with 5 additions and 19 deletions.
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Component\Form\Tests\Extension\DependencyInjection;

use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Form\AbstractTypeExtension;
use Symfony\Component\Form\Extension\DependencyInjection\DependencyInjectionExtension;
use Symfony\Component\Form\FormTypeGuesserChain;
Expand All @@ -21,9 +22,6 @@ class DependencyInjectionExtensionTest extends TestCase
{
public function testGetTypeExtensions()
{
$container = $this->createContainerMock();
$container->expects($this->never())->method('get');

$typeExtension1 = new TestTypeExtension();
$typeExtension2 = new TestTypeExtension();
$typeExtension3 = new OtherTypeExtension();
Expand All @@ -34,7 +32,7 @@ public function testGetTypeExtensions()
'other' => new \ArrayIterator([$typeExtension3, $typeExtension4]),
];

$extension = new DependencyInjectionExtension($container, $extensions, []);
$extension = new DependencyInjectionExtension(new ContainerBuilder(), $extensions, []);

$this->assertTrue($extension->hasTypeExtensions('test'));
$this->assertTrue($extension->hasTypeExtensions('other'));
Expand All @@ -48,40 +46,28 @@ public function testGetTypeExtensions()
*/
public function testThrowExceptionForInvalidExtendedType()
{
$container = $this->getMockBuilder('Psr\Container\ContainerInterface')->getMock();
$container->expects($this->never())->method('get');

$extensions = [
'unmatched' => new \ArrayIterator([new TestTypeExtension()]),
];

$extension = new DependencyInjectionExtension($container, $extensions, []);
$extension = new DependencyInjectionExtension(new ContainerBuilder(), $extensions, []);

$extension->getTypeExtensions('unmatched');
}

public function testGetTypeGuesser()
{
$container = $this->createContainerMock();
$extension = new DependencyInjectionExtension($container, [], [$this->getMockBuilder(FormTypeGuesserInterface::class)->getMock()]);
$extension = new DependencyInjectionExtension(new ContainerBuilder(), [], [$this->getMockBuilder(FormTypeGuesserInterface::class)->getMock()]);

$this->assertInstanceOf(FormTypeGuesserChain::class, $extension->getTypeGuesser());
}

public function testGetTypeGuesserReturnsNullWhenNoTypeGuessersHaveBeenConfigured()
{
$container = $this->createContainerMock();
$extension = new DependencyInjectionExtension($container, [], []);
$extension = new DependencyInjectionExtension(new ContainerBuilder(), [], []);

$this->assertNull($extension->getTypeGuesser());
}

private function createContainerMock()
{
return $this->getMockBuilder('Psr\Container\ContainerInterface')
->setMethods(['get', 'has'])
->getMock();
}
}

class TestTypeExtension extends AbstractTypeExtension
Expand Down

0 comments on commit 5ed68ee

Please sign in to comment.