|
12 | 12 | namespace Symfony\Bundle\TwigBundle\Tests\DependencyInjection\Compiler; |
13 | 13 |
|
14 | 14 | use PHPUnit\Framework\TestCase; |
| 15 | +use Symfony\Bridge\Twig\Extension\FormExtension; |
15 | 16 | use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\TwigEnvironmentPass; |
16 | 17 | use Symfony\Component\DependencyInjection\ContainerBuilder; |
17 | | -use Symfony\Component\DependencyInjection\Definition; |
18 | 18 | use Symfony\Component\DependencyInjection\Reference; |
19 | 19 |
|
20 | 20 | class TwigEnvironmentPassTest extends TestCase |
21 | 21 | { |
22 | 22 | public function testTwigBridgeExtensionsAreRegisteredFirst() |
23 | 23 | { |
24 | | - $twigDefinition = new Definition('twig'); |
25 | | - |
26 | | - $containerBuilderMock = $this->getMockBuilder(ContainerBuilder::class) |
27 | | - ->setMethods(array('hasDefinition', 'get', 'findTaggedServiceIds', 'getDefinition')) |
28 | | - ->getMock(); |
29 | | - $containerBuilderMock |
30 | | - ->expects($this->once()) |
31 | | - ->method('hasDefinition') |
32 | | - ->with('twig') |
33 | | - ->will($this->returnValue(true)); |
34 | | - $containerBuilderMock |
35 | | - ->expects($this->once()) |
36 | | - ->method('findTaggedServiceIds') |
37 | | - ->with('twig.extension') |
38 | | - ->will($this->returnValue(array( |
39 | | - 'other_extension' => array( |
40 | | - array(), |
41 | | - ), |
42 | | - 'twig_bridge_extension' => array( |
43 | | - array(), |
44 | | - ), |
45 | | - ))); |
46 | | - |
47 | | - $otherExtensionDefinitionMock = $this->getMockBuilder(Definition::class) |
48 | | - ->setMethods(array('getClass')) |
49 | | - ->getMock(); |
50 | | - $otherExtensionDefinitionMock |
51 | | - ->expects($this->once()) |
52 | | - ->method('getClass') |
53 | | - ->will($this->returnValue('Foo\\Bar')); |
54 | | - |
55 | | - $twigExtensionDefinitionMock = $this->getMockBuilder(Definition::class) |
56 | | - ->setMethods(array('getClass')) |
57 | | - ->getMock(); |
58 | | - $twigExtensionDefinitionMock |
59 | | - ->expects($this->once()) |
60 | | - ->method('getClass') |
61 | | - ->will($this->returnValue('Symfony\\Bridge\\Twig\\Extension\\Foo')); |
62 | | - |
63 | | - $containerBuilderMock |
64 | | - ->expects($this->exactly(3)) |
65 | | - ->method('getDefinition') |
66 | | - ->withConsecutive(array('twig'), array('other_extension'), array('twig_bridge_extension')) |
67 | | - ->willReturnOnConsecutiveCalls( |
68 | | - $this->returnValue($twigDefinition), |
69 | | - $this->returnValue($otherExtensionDefinitionMock), |
70 | | - $this->returnValue($twigExtensionDefinitionMock) |
71 | | - ); |
| 24 | + $container = new ContainerBuilder(); |
| 25 | + $twigDefinition = $container->register('twig'); |
| 26 | + $container->register('other_extension', 'Foo\Bar') |
| 27 | + ->addTag('twig.extension'); |
| 28 | + $container->register('twig_bridge_extension', FormExtension::class) |
| 29 | + ->addTag('twig.extension'); |
72 | 30 |
|
73 | 31 | $twigEnvironmentPass = new TwigEnvironmentPass(); |
74 | | - $twigEnvironmentPass->process($containerBuilderMock); |
| 32 | + $twigEnvironmentPass->process($container); |
75 | 33 |
|
76 | 34 | $methodCalls = $twigDefinition->getMethodCalls(); |
77 | 35 | $this->assertCount(2, $methodCalls); |
78 | 36 |
|
79 | 37 | $twigBridgeExtensionReference = $methodCalls[0][1][0]; |
80 | 38 | $this->assertInstanceOf(Reference::class, $twigBridgeExtensionReference); |
81 | | - /* @var Reference $twigBridgeExtensionReference */ |
82 | | - $this->assertEquals('twig_bridge_extension', $twigBridgeExtensionReference->__toString()); |
| 39 | + $this->assertSame('twig_bridge_extension', (string) $twigBridgeExtensionReference); |
83 | 40 |
|
84 | 41 | $otherExtensionReference = $methodCalls[1][1][0]; |
85 | 42 | $this->assertInstanceOf(Reference::class, $otherExtensionReference); |
86 | | - /* @var Reference $otherExtensionReference */ |
87 | | - $this->assertEquals('other_extension', $otherExtensionReference->__toString()); |
| 43 | + $this->assertSame('other_extension', (string) $otherExtensionReference); |
88 | 44 | } |
89 | 45 | } |
0 commit comments