do not mock the container builder or definitions
This commit is contained in:
parent
39e88ed312
commit
8bba882512
@ -12,78 +12,34 @@
|
|||||||
namespace Symfony\Bundle\TwigBundle\Tests\DependencyInjection\Compiler;
|
namespace Symfony\Bundle\TwigBundle\Tests\DependencyInjection\Compiler;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Symfony\Bridge\Twig\Extension\FormExtension;
|
||||||
use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\TwigEnvironmentPass;
|
use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\TwigEnvironmentPass;
|
||||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
use Symfony\Component\DependencyInjection\Definition;
|
|
||||||
use Symfony\Component\DependencyInjection\Reference;
|
use Symfony\Component\DependencyInjection\Reference;
|
||||||
|
|
||||||
class TwigEnvironmentPassTest extends TestCase
|
class TwigEnvironmentPassTest extends TestCase
|
||||||
{
|
{
|
||||||
public function testTwigBridgeExtensionsAreRegisteredFirst()
|
public function testTwigBridgeExtensionsAreRegisteredFirst()
|
||||||
{
|
{
|
||||||
$twigDefinition = new Definition('twig');
|
$container = new ContainerBuilder();
|
||||||
|
$twigDefinition = $container->register('twig');
|
||||||
$containerBuilderMock = $this->getMockBuilder(ContainerBuilder::class)
|
$container->register('other_extension', 'Foo\Bar')
|
||||||
->setMethods(array('hasDefinition', 'get', 'findTaggedServiceIds', 'getDefinition'))
|
->addTag('twig.extension');
|
||||||
->getMock();
|
$container->register('twig_bridge_extension', FormExtension::class)
|
||||||
$containerBuilderMock
|
->addTag('twig.extension');
|
||||||
->expects($this->once())
|
|
||||||
->method('hasDefinition')
|
|
||||||
->with('twig')
|
|
||||||
->will($this->returnValue(true));
|
|
||||||
$containerBuilderMock
|
|
||||||
->expects($this->once())
|
|
||||||
->method('findTaggedServiceIds')
|
|
||||||
->with('twig.extension')
|
|
||||||
->will($this->returnValue(array(
|
|
||||||
'other_extension' => array(
|
|
||||||
array(),
|
|
||||||
),
|
|
||||||
'twig_bridge_extension' => array(
|
|
||||||
array(),
|
|
||||||
),
|
|
||||||
)));
|
|
||||||
|
|
||||||
$otherExtensionDefinitionMock = $this->getMockBuilder(Definition::class)
|
|
||||||
->setMethods(array('getClass'))
|
|
||||||
->getMock();
|
|
||||||
$otherExtensionDefinitionMock
|
|
||||||
->expects($this->once())
|
|
||||||
->method('getClass')
|
|
||||||
->will($this->returnValue('Foo\\Bar'));
|
|
||||||
|
|
||||||
$twigExtensionDefinitionMock = $this->getMockBuilder(Definition::class)
|
|
||||||
->setMethods(array('getClass'))
|
|
||||||
->getMock();
|
|
||||||
$twigExtensionDefinitionMock
|
|
||||||
->expects($this->once())
|
|
||||||
->method('getClass')
|
|
||||||
->will($this->returnValue('Symfony\\Bridge\\Twig\\Extension\\Foo'));
|
|
||||||
|
|
||||||
$containerBuilderMock
|
|
||||||
->expects($this->exactly(3))
|
|
||||||
->method('getDefinition')
|
|
||||||
->withConsecutive(array('twig'), array('other_extension'), array('twig_bridge_extension'))
|
|
||||||
->willReturnOnConsecutiveCalls(
|
|
||||||
$this->returnValue($twigDefinition),
|
|
||||||
$this->returnValue($otherExtensionDefinitionMock),
|
|
||||||
$this->returnValue($twigExtensionDefinitionMock)
|
|
||||||
);
|
|
||||||
|
|
||||||
$twigEnvironmentPass = new TwigEnvironmentPass();
|
$twigEnvironmentPass = new TwigEnvironmentPass();
|
||||||
$twigEnvironmentPass->process($containerBuilderMock);
|
$twigEnvironmentPass->process($container);
|
||||||
|
|
||||||
$methodCalls = $twigDefinition->getMethodCalls();
|
$methodCalls = $twigDefinition->getMethodCalls();
|
||||||
$this->assertCount(2, $methodCalls);
|
$this->assertCount(2, $methodCalls);
|
||||||
|
|
||||||
$twigBridgeExtensionReference = $methodCalls[0][1][0];
|
$twigBridgeExtensionReference = $methodCalls[0][1][0];
|
||||||
$this->assertInstanceOf(Reference::class, $twigBridgeExtensionReference);
|
$this->assertInstanceOf(Reference::class, $twigBridgeExtensionReference);
|
||||||
/* @var Reference $twigBridgeExtensionReference */
|
$this->assertSame('twig_bridge_extension', (string) $twigBridgeExtensionReference);
|
||||||
$this->assertEquals('twig_bridge_extension', $twigBridgeExtensionReference->__toString());
|
|
||||||
|
|
||||||
$otherExtensionReference = $methodCalls[1][1][0];
|
$otherExtensionReference = $methodCalls[1][1][0];
|
||||||
$this->assertInstanceOf(Reference::class, $otherExtensionReference);
|
$this->assertInstanceOf(Reference::class, $otherExtensionReference);
|
||||||
/* @var Reference $otherExtensionReference */
|
$this->assertSame('other_extension', (string) $otherExtensionReference);
|
||||||
$this->assertEquals('other_extension', $otherExtensionReference->__toString());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user