8000 minor #26078 [TwigBundle] do not mock the container builder or defini… · fervo/symfony@a41874f · GitHub
[go: up one dir, main page]

Skip to content

Commit a41874f

Browse files
committed
minor symfony#26078 [TwigBundle] do not mock the container builder or definitions (xabbuh)
This PR was merged into the 3.4 branch. Discussion ---------- [TwigBundle] do not mock the container builder or definitions | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | Commits ------- 8bba882 do not mock the container builder or definitions
2 parents 39e88ed + 8bba882 commit a41874f

File tree

1 file changed

+10
-54
lines changed

1 file changed

+10
-54
lines changed

src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Compiler/TwigEnvironmentPassTest.php

Lines changed: 10 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -12,78 +12,34 @@
1212
namespace Symfony\Bundle\TwigBundle\Tests\DependencyInjection\Compiler;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\Twig\Extension\FormExtension;
1516
use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\TwigEnvironmentPass;
1617
use Symfony\Component\DependencyInjection\ContainerBuilder;
17-
use Symfony\Component\DependencyInjection\Definition;
1818
use Symfony\Component\DependencyInjection\Reference;
1919

2020
class TwigEnvironmentPassTest extends TestCase
2121
{
2222
public function testTwigBridgeExtensionsAreRegisteredFirst()
2323
{
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');
7230

7331
$twigEnvironmentPass = new TwigEnvironmentPass();
74-
$twigEnvironmentPass->process($containerBuilderMock);
32+
$twigEnvironmentPass->process($container);
7533

7634
$methodCalls = $twigDefinition->getMethodCalls();
7735
$this->assertCount(2, $methodCalls);
7836

7937
$twigBridgeExtensionReference = $methodCalls[0][1][0];
8038
$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);
8340

8441
$otherExtensionReference = $methodCalls[1][1][0];
8542
$this->assertInstanceOf(Reference::class, $otherExtensionReference);
86-
/* @var Reference $otherExtensionReference */
87-
$this->assertEquals('other_extension', $otherExtensionReference->__toString());
43+
$this->assertSame('other_extension', (string) $otherExtensionReference);
8844
}
8945
}

0 commit comments

Comments
 (0)
0