Skip to content
This repository has been archived by the owner on Sep 30, 2021. It is now read-only.

Commit

Permalink
Avoid mocking what we do not own
Browse files Browse the repository at this point in the history
This breaks with Symfony 3.4, but luckily, there is a very simple
implementation of Twig_RuntimeLoaderInterface, let's try it!
Implies a minor Twig version bump.
  • Loading branch information
greg0ire committed Nov 4, 2017
1 parent f4ac19b commit 94f03f6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
24 changes: 15 additions & 9 deletions Test/AbstractWidgetTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
use Symfony\Bridge\Twig\Form\TwigRenderer;
use Symfony\Bridge\Twig\Form\TwigRendererEngine;
use Symfony\Bridge\Twig\Form\TwigRendererEngineInterface;
use Symfony\Bridge\Twig\Form\TwigRendererInterface;
use Symfony\Bridge\Twig\Tests\Extension\Fixtures\StubFilesystemLoader;
use Symfony\Bundle\FrameworkBundle\Tests\Templating\Helper\Fixtures\StubTranslator;
use Symfony\Component\Form\FormExtensionInterface;
use Symfony\Component\Form\FormRenderer;
use Symfony\Component\Form\FormView;
use Symfony\Component\Form\Test\TypeTestCase;
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
Expand Down Expand Up @@ -55,18 +57,14 @@ protected function setUp()
if (method_exists('Symfony\Bridge\Twig\AppVariable', 'getToken')) {
$this->extension = new FormExtension();
$environment = $this->getEnvironment();
$this->renderer = new TwigRenderer(
$this->renderer = new FormRenderer(
$this->getRenderingEngine($environment),
$this->createMock(CsrfTokenManagerInterface::class)
);
$runtimeLoader = $this
->getMockBuilder('Twig_RuntimeLoaderInterface')
->getMock();

$runtimeLoader->expects($this->any())
->method('load')
->with($this->equalTo('Symfony\Bridge\Twig\Form\TwigRenderer'))
->will($this->returnValue($this->renderer));
$runtimeLoader = new \Twig_FactoryRuntimeLoader([
FormRenderer::class => [$this, 'getRenderer'],
TwigRenderer::class => [$this, 'getRenderer'],
]);

$environment->addRuntimeLoader($runtimeLoader);
} else {
Expand All @@ -81,6 +79,14 @@ protected function setUp()
$this->extension->initRuntime($environment);
}

/**
* @return TwigRendererInterface
*/
public function getRenderer()
{
return $this->renderer;
}

/**
* @return \Twig_Environment
*/
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"symfony/twig-bridge": "^2.8 || ^3.2",
"symfony/validator": "^2.8 || ^3.2",
"twig/extensions": "^1.0",
"twig/twig": "^1.23 || ^2.0"
"twig/twig": "^1.30 || ^2.0"
},
"require-dev": {
"doctrine/orm": "^2.4",
Expand Down

0 comments on commit 94f03f6

Please sign in to comment.