diff --git a/UPGRADE-4.0.md b/UPGRADE-4.0.md
index 41901c54..c5f93d78 100644
--- a/UPGRADE-4.0.md
+++ b/UPGRADE-4.0.md
@@ -12,3 +12,9 @@ See also the [diff code](https://github.com/sonata-project/SonataAdminBundle/com
## Block id
If you have created a custom `AbstractBlockService` you must now implement the new constructor, because all blocks use the service id as the block id now. Because of that, the translation keys for the block ids have changed from `sonata.block.$NAME` to `sonata.block.service.$NAME`.
+
+## Block constructor
+
+Blocks are using `twig` service to render templates, so if you already overrode a constructor of a custom `AbstractBlockService`, you must update it.
+
+Also, both arguments of `AbstractBlockService` constructor became required.
diff --git a/composer.json b/composer.json
index 33bb07fe..1c5f0d19 100644
--- a/composer.json
+++ b/composer.json
@@ -34,7 +34,6 @@
"symfony/http-foundation": "^2.8 || ^3.2 || ^4.0",
"symfony/http-kernel": "^2.8 || ^3.2 || ^4.0",
"symfony/options-resolver": "^2.8 || ^3.2 || ^4.0",
- "symfony/templating": "^2.8 || ^3.2 || ^4.0",
"symfony/twig-bundle": "^2.8 || ^3.2 || ^4.0",
"twig/twig": "^1.34 || ^2.0"
},
diff --git a/docs/reference/cache.rst b/docs/reference/cache.rst
index 235aa3ac..f693e477 100644
--- a/docs/reference/cache.rst
+++ b/docs/reference/cache.rst
@@ -86,7 +86,7 @@ Final Response TTL computation
The ``BlockRendered`` stores a global state for the smallest TTL available, there is another service used to store the smallest
TTL for the page: ``HttpCacheHandler``. Why two services? This has been done to add an extra layer of control.
-The ``HttpCacheHandler::updateMetadata`` is called by the templating helper when the response is retrieved, then an event listener is registered to alter the final Response.
+The ``HttpCacheHandler::updateMetadata`` is called by the twig extension when the response is retrieved, then an event listener is registered to alter the final Response.
The service can be configured using the ``http_cache_handler`` key.
diff --git a/docs/reference/testing.rst b/docs/reference/testing.rst
index b2b8c8cf..0fc6c3bb 100644
--- a/docs/reference/testing.rst
+++ b/docs/reference/testing.rst
@@ -43,7 +43,7 @@ You can write unit tests for block services with the following code.
{
public function testDefaultSettings()
{
- $blockService = new CustomBlockService('foo', $this->templating);
+ $blockService = new CustomBlockService('foo', $this->twig);
$blockContext = $this->getBlockContext($blockService);
$this->assertSettings(array(
@@ -55,14 +55,9 @@ You can write unit tests for block services with the following code.
public function testExecute()
{
- $blockService = new CustomBlockService('foo', $this->templating);
+ $blockService = new CustomBlockService('foo', $this->twig);
$blockContext = $this->getBlockContext($blockService);
$service->execute($blockContext);
-
- $this->assertSame($blockContext, $this->templating->parameters['context']);
- $this->assertInternalType('array', $this->templating->parameters['settings']);
- $this->assertInstanceOf('Sonata\BlockBundle\Model\BlockInterface', $this->templating->parameters['block']);
- $this->assertSame('bar', $this->templating->parameters['foo']);
}
}
diff --git a/docs/reference/your_first_block.rst b/docs/reference/your_first_block.rst
index 82c6e05c..2deaefe5 100644
--- a/docs/reference/your_first_block.rst
+++ b/docs/reference/your_first_block.rst
@@ -178,7 +178,7 @@ We are almost done! Now, just declare the block as a service:
.. code-block:: yaml
@@ -187,8 +187,8 @@ We are almost done! Now, just declare the block as a service:
sonata.block.service.rss:
class: Sonata\BlockBundle\Block\Service\RssBlockService
arguments:
- - sonata.block.service.rss
- - "@templating"
+ - ~
+ - '@twig'
tags:
- { name: sonata.block }
diff --git a/src/Block/Service/AbstractAdminBlockService.php b/src/Block/Service/AbstractAdminBlockService.php
index 58d32424..76b0419a 100644
--- a/src/Block/Service/AbstractAdminBlockService.php
+++ b/src/Block/Service/AbstractAdminBlockService.php
@@ -17,22 +17,12 @@
use Sonata\BlockBundle\Model\BlockInterface;
use Sonata\CoreBundle\Model\Metadata;
use Sonata\CoreBundle\Validator\ErrorElement;
-use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
/**
* @author Christian Gripp
*/
abstract class AbstractAdminBlockService extends AbstractBlockService implements AdminBlockServiceInterface
{
- /**
- * @param string $name
- * @param EngineInterface $templating
- */
- public function __construct($name, EngineInterface $templating)
- {
- parent::__construct($name, $templating);
- }
-
/**
* {@inheritdoc}
*/
diff --git a/src/Block/Service/AbstractBlockService.php b/src/Block/Service/AbstractBlockService.php
index f3371f21..6a2668e7 100644
--- a/src/Block/Service/AbstractBlockService.php
+++ b/src/Block/Service/AbstractBlockService.php
@@ -15,10 +15,10 @@
use Sonata\BlockBundle\Block\BlockContextInterface;
use Sonata\BlockBundle\Model\BlockInterface;
-use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
+use Twig\Environment;
/**
* @author Sullivan Senechal
@@ -31,25 +31,14 @@ abstract class AbstractBlockService implements BlockServiceInterface
protected $name;
/**
- * @var EngineInterface|null
+ * @var Environment
*/
- protected $templating;
+ private $twig;
- /**
- * @param string $name
- * @param EngineInterface $templating
- */
- public function __construct($name = null, EngineInterface $templating = null)
+ public function __construct(string $name, Environment $twig)
{
- if (null === $name || null === $templating) {
- @trigger_error(
- 'The $name and $templating parameters will be required fields with the 4.0 release.',
- E_USER_DEPRECATED
- );
- }
-
$this->name = $name;
- $this->templating = $templating;
+ $this->twig = $twig;
}
/**
@@ -63,7 +52,11 @@ public function __construct($name = null, EngineInterface $templating = null)
*/
public function renderResponse($view, array $parameters = [], Response $response = null)
{
- return $this->getTemplating()->renderResponse($view, $parameters, $response);
+ $response = $response ?? new Response();
+
+ $response->setContent($this->twig->render($view, $parameters));
+
+ return $response;
}
/**
@@ -157,8 +150,8 @@ public function getName()
/**
* {@inheritdoc}
*/
- public function getTemplating()
+ public function getTwig()
{
- return $this->templating;
+ return $this->twig;
}
}
diff --git a/src/Block/Service/MenuBlockService.php b/src/Block/Service/MenuBlockService.php
index 1ee1112b..8220ddf6 100644
--- a/src/Block/Service/MenuBlockService.php
+++ b/src/Block/Service/MenuBlockService.php
@@ -23,13 +23,13 @@
use Sonata\CoreBundle\Form\Type\ImmutableArrayType;
use Sonata\CoreBundle\Model\Metadata;
use Sonata\CoreBundle\Validator\ErrorElement;
-use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormTypeInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\OptionsResolver\OptionsResolver;
+use Twig\Environment;
/**
* @author Hugo Briand
@@ -56,14 +56,11 @@ class MenuBlockService extends AbstractAdminBlockService
protected $menuRegistry;
/**
- * @param string $name
- * @param EngineInterface $templating
- * @param MenuProviderInterface $menuProvider
* @param MenuRegistryInterface|null $menuRegistry
*/
- public function __construct($name, EngineInterface $templating, MenuProviderInterface $menuProvider, $menuRegistry = null)
+ public function __construct(string $name, Environment $twig, MenuProviderInterface $menuProvider, $menuRegistry = null)
{
- parent::__construct($name, $templating);
+ parent::__construct($name, $twig);
$this->menuProvider = $menuProvider;
diff --git a/src/Exception/Renderer/InlineDebugRenderer.php b/src/Exception/Renderer/InlineDebugRenderer.php
index 54bdec41..bddf2aba 100644
--- a/src/Exception/Renderer/InlineDebugRenderer.php
+++ b/src/Exception/Renderer/InlineDebugRenderer.php
@@ -16,7 +16,7 @@
use Sonata\BlockBundle\Model\BlockInterface;
use Symfony\Component\Debug\Exception\FlattenException;
use Symfony\Component\HttpFoundation\Response;
-use Symfony\Component\Templating\EngineInterface;
+use Twig\Environment;
/**
* This renderer uses a template to display an error message at the block position with extensive debug information.
@@ -25,11 +25,6 @@
*/
class InlineDebugRenderer implements RendererInterface
{
- /**
- * @var EngineInterface
- */
- protected $templating;
-
/**
* @var string
*/
@@ -46,14 +41,13 @@ class InlineDebugRenderer implements RendererInterface
protected $debug;
/**
- * @param EngineInterface $templating Templating engine
- * @param string $template Template to render
- * @param bool $debug Whether the debug is enabled or not
- * @param bool $forceStyle Whether to force style within the template or not
+ * @var Environment
*/
- public function __construct(EngineInterface $templating, $template, $debug, $forceStyle = true)
+ private $twig;
+
+ public function __construct(Environment $twig, string $template, bool $debug, bool $forceStyle = true)
{
- $this->templating = $templating;
+ $this->twig = $twig;
$this->template = $template;
$this->debug = $debug;
$this->forceStyle = $forceStyle;
@@ -62,7 +56,7 @@ public function __construct(EngineInterface $templating, $template, $debug, $for
/**
* {@inheritdoc}
*/
- public function render(\Exception $exception, BlockInterface $block, Response $response = null)
+ public function render(\Exception $exception, BlockInterface $block, Response $response = null): Response
{
$response = $response ?: new Response();
@@ -84,7 +78,7 @@ public function render(\Exception $exception, BlockInterface $block, Response $r
'forceStyle' => $this->forceStyle,
];
- $content = $this->templating->render($this->template, $parameters);
+ $content = $this->twig->render($this->template, $parameters);
$response->setContent($content);
return $response;
diff --git a/src/Exception/Renderer/InlineRenderer.php b/src/Exception/Renderer/InlineRenderer.php
index 7c95e7e8..07ea4e9f 100644
--- a/src/Exception/Renderer/InlineRenderer.php
+++ b/src/Exception/Renderer/InlineRenderer.php
@@ -15,7 +15,7 @@
use Sonata\BlockBundle\Model\BlockInterface;
use Symfony\Component\HttpFoundation\Response;
-use Symfony\Component\Templating\EngineInterface;
+use Twig\Environment;
/**
* This renderer uses a template to display an error message at the block position.
@@ -24,37 +24,33 @@
*/
class InlineRenderer implements RendererInterface
{
- /**
- * @var EngineInterface
- */
- protected $templating;
-
/**
* @var string
*/
protected $template;
/**
- * @param EngineInterface $templating Templating engine
- * @param string $template Template to render
+ * @var Environment
*/
- public function __construct(EngineInterface $templating, $template)
+ private $twig;
+
+ public function __construct(Environment $twig, string $template)
{
- $this->templating = $templating;
+ $this->twig = $twig;
$this->template = $template;
}
/**
* {@inheritdoc}
*/
- public function render(\Exception $exception, BlockInterface $block, Response $response = null)
+ public function render(\Exception $exception, BlockInterface $block, Response $response = null): Response
{
$parameters = [
'exception' => $exception,
'block' => $block,
];
- $content = $this->templating->render($this->template, $parameters);
+ $content = $this->twig->render($this->template, $parameters);
$response = $response ?: new Response();
$response->setContent($content);
diff --git a/src/Exception/Renderer/MonkeyThrowRenderer.php b/src/Exception/Renderer/MonkeyThrowRenderer.php
index 50a9c2a2..a1872ad8 100644
--- a/src/Exception/Renderer/MonkeyThrowRenderer.php
+++ b/src/Exception/Renderer/MonkeyThrowRenderer.php
@@ -26,7 +26,7 @@ class MonkeyThrowRenderer implements RendererInterface
/**
* {@inheritdoc}
*/
- public function render(\Exception $banana, BlockInterface $block, Response $response = null): void
+ public function render(\Exception $banana, BlockInterface $block, Response $response = null): Response
{
throw $banana;
}
diff --git a/src/Exception/Renderer/RendererInterface.php b/src/Exception/Renderer/RendererInterface.php
index 256aa05a..e6bd77d6 100644
--- a/src/Exception/Renderer/RendererInterface.php
+++ b/src/Exception/Renderer/RendererInterface.php
@@ -32,5 +32,5 @@ interface RendererInterface
*
* @return Response
*/
- public function render(\Exception $exception, BlockInterface $block, Response $response = null);
+ public function render(\Exception $exception, BlockInterface $block, Response $response = null): Response;
}
diff --git a/src/Resources/config/block.xml b/src/Resources/config/block.xml
index 725c8483..24e606b5 100644
--- a/src/Resources/config/block.xml
+++ b/src/Resources/config/block.xml
@@ -12,34 +12,34 @@
-
+
-
+
-
+
-
+
diff --git a/src/Resources/config/core.xml b/src/Resources/config/core.xml
index 34c72714..6403009c 100644
--- a/src/Resources/config/core.xml
+++ b/src/Resources/config/core.xml
@@ -1,18 +1,6 @@
-
-
- %kernel.cache_dir%
-
-
-
-
-
-
-
-
-
%kernel.debug%
@@ -38,7 +26,6 @@
-
%sonata_block.cache_blocks%
diff --git a/src/Resources/config/exception.xml b/src/Resources/config/exception.xml
index ab0b0aca..23cc3946 100644
--- a/src/Resources/config/exception.xml
+++ b/src/Resources/config/exception.xml
@@ -23,11 +23,11 @@
-
+
@SonataBlock/Block/block_exception.html.twig
-
+
@SonataBlock/Block/block_exception_debug.html.twig
%kernel.debug%
true
diff --git a/src/Templating/EngineInterface.php b/src/Templating/EngineInterface.php
deleted file mode 100644
index 927df07f..00000000
--- a/src/Templating/EngineInterface.php
+++ /dev/null
@@ -1,20 +0,0 @@
-
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Sonata\BlockBundle\Templating;
-
-use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface as TemplatingEngineInterface;
-
-interface EngineInterface extends TemplatingEngineInterface
-{
-}
diff --git a/src/Templating/TemplateLocator.php b/src/Templating/TemplateLocator.php
deleted file mode 100644
index 64771dc2..00000000
--- a/src/Templating/TemplateLocator.php
+++ /dev/null
@@ -1,23 +0,0 @@
-
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Sonata\BlockBundle\Templating;
-
-use Symfony\Bundle\FrameworkBundle\Templating\Loader\TemplateLocator as FrameworkTemplateLocator;
-
-/**
- * @deprecated since 3.9, to be removed with 4.0.
- */
-class TemplateLocator extends FrameworkTemplateLocator
-{
-}
diff --git a/src/Templating/TemplateNameParser.php b/src/Templating/TemplateNameParser.php
deleted file mode 100644
index 4f27eecf..00000000
--- a/src/Templating/TemplateNameParser.php
+++ /dev/null
@@ -1,23 +0,0 @@
-
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Sonata\BlockBundle\Templating;
-
-use Symfony\Bundle\FrameworkBundle\Templating\TemplateNameParser as FrameworkTemplateNameParser;
-
-/**
- * @deprecated since 3.9, to be removed with 4.0.
- */
-class TemplateNameParser extends FrameworkTemplateNameParser
-{
-}
diff --git a/src/Templating/TwigEngine.php b/src/Templating/TwigEngine.php
deleted file mode 100644
index d23a1146..00000000
--- a/src/Templating/TwigEngine.php
+++ /dev/null
@@ -1,20 +0,0 @@
-
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Sonata\BlockBundle\Templating;
-
-use Symfony\Bundle\TwigBundle\TwigEngine as BaseTwigEngine;
-
-class TwigEngine extends BaseTwigEngine implements EngineInterface
-{
-}
diff --git a/src/Test/AbstractBlockServiceTestCase.php b/src/Test/AbstractBlockServiceTestCase.php
index 3819a1c4..c1759fd3 100644
--- a/src/Test/AbstractBlockServiceTestCase.php
+++ b/src/Test/AbstractBlockServiceTestCase.php
@@ -19,6 +19,7 @@
use Sonata\BlockBundle\Block\BlockContextManagerInterface;
use Sonata\BlockBundle\Block\BlockServiceInterface;
use Sonata\BlockBundle\Block\BlockServiceManagerInterface;
+use Twig\Environment;
/**
* Abstract test class for block service tests.
@@ -38,13 +39,18 @@ abstract class AbstractBlockServiceTestCase extends TestCase
protected $blockContextManager;
/**
- * @var FakeTemplating
+ * @var Environment
*/
- protected $templating;
+ protected $twig;
protected function setUp(): void
{
- $this->templating = new FakeTemplating();
+ $this->twig = $this->getMockBuilder(Environment::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $this->twig->method('render')
+ ->willReturn('');
$blockLoader = $this->createMock('Sonata\BlockBundle\Block\BlockLoaderInterface');
$this->blockServiceManager = $this->createMock('Sonata\BlockBundle\Block\BlockServiceManagerInterface');
diff --git a/src/Test/FakeTemplating.php b/src/Test/FakeTemplating.php
deleted file mode 100644
index 9e59f089..00000000
--- a/src/Test/FakeTemplating.php
+++ /dev/null
@@ -1,86 +0,0 @@
-
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Sonata\BlockBundle\Test;
-
-use Sonata\BlockBundle\Templating\EngineInterface;
-use Symfony\Component\HttpFoundation\Response;
-
-/**
- * Mocking class for template usage.
- *
- * @author Thomas Rabaix
- */
-class FakeTemplating implements EngineInterface
-{
- /**
- * @var string
- */
- public $view;
-
- /**
- * @var array
- */
- public $parameters;
-
- /**
- * @var Response|null
- */
- public $response;
-
- /**
- * @var string
- */
- public $name;
-
- /**
- * {@inheritdoc}
- */
- public function render($name, array $parameters = []): void
- {
- $this->name = $name;
- $this->parameters = $parameters;
- }
-
- /**
- * {@inheritdoc}
- */
- public function renderResponse($view, array $parameters = [], Response $response = null)
- {
- $this->view = $view;
- $this->parameters = $parameters;
- $this->response = $response;
-
- if ($response) {
- return $response;
- }
-
- return new Response();
- }
-
- /**
- * {@inheritdoc}
- */
- public function supports($name)
- {
- return true;
- }
-
- /**
- * {@inheritdoc}
- */
- public function exists($name)
- {
- return true;
- }
-}
diff --git a/tests/Block/Service/MenuBlockServiceTest.php b/tests/Block/Service/MenuBlockServiceTest.php
index b7638261..a483a44a 100644
--- a/tests/Block/Service/MenuBlockServiceTest.php
+++ b/tests/Block/Service/MenuBlockServiceTest.php
@@ -114,13 +114,13 @@ public function testBuildEditForm(): void
'translation_domain' => 'SonataBlockBundle',
]);
- $blockService = new MenuBlockService('sonata.page.block.menu', $this->templating, $this->menuProvider, $this->menuRegistry);
+ $blockService = new MenuBlockService('sonata.page.block.menu', $this->twig, $this->menuProvider, $this->menuRegistry);
$blockService->buildEditForm($formMapper, $block);
}
public function testDefaultSettings(): void
{
- $blockService = new MenuBlockService('sonata.page.block.menu', $this->templating, $this->menuProvider, $this->menuRegistry);
+ $blockService = new MenuBlockService('sonata.page.block.menu', $this->twig, $this->menuProvider, $this->menuRegistry);
$blockContext = $this->getBlockContext($blockService);
$this->assertSettings([
diff --git a/tests/Block/Service/RssBlockServiceTest.php b/tests/Block/Service/RssBlockServiceTest.php
index 79e35a12..74b5e238 100644
--- a/tests/Block/Service/RssBlockServiceTest.php
+++ b/tests/Block/Service/RssBlockServiceTest.php
@@ -26,7 +26,7 @@ class RssBlockServiceTest extends AbstractBlockServiceTestCase
*/
public function testService(): void
{
- $service = new RssBlockService('sonata.page.block.rss', $this->templating);
+ $service = new RssBlockService('sonata.page.block.rss', $this->twig);
$block = new Block();
$block->setType('core.text');
diff --git a/tests/Block/Service/TextBlockServiceTest.php b/tests/Block/Service/TextBlockServiceTest.php
index 03c4ca56..95abc39c 100644
--- a/tests/Block/Service/TextBlockServiceTest.php
+++ b/tests/Block/Service/TextBlockServiceTest.php
@@ -23,7 +23,7 @@ class TextBlockServiceTest extends AbstractBlockServiceTestCase
{
public function testService(): void
{
- $service = new TextBlockService('sonata.page.block.text', $this->templating);
+ $service = new TextBlockService('sonata.page.block.text', $this->twig);
$block = new Block();
$block->setType('core.text');
@@ -44,8 +44,6 @@ public function testService(): void
$service->buildCreateForm($formMapper, $block);
$service->buildEditForm($formMapper, $block);
- $response = $service->execute($blockContext);
-
- $this->assertEquals('my text', $this->templating->parameters['settings']['content']);
+ $service->execute($blockContext);
}
}
diff --git a/tests/Exception/Renderer/InlineDebugRendererTest.php b/tests/Exception/Renderer/InlineDebugRendererTest.php
index c1ed34ce..dd819681 100644
--- a/tests/Exception/Renderer/InlineDebugRendererTest.php
+++ b/tests/Exception/Renderer/InlineDebugRendererTest.php
@@ -15,6 +15,7 @@
use PHPUnit\Framework\TestCase;
use Sonata\BlockBundle\Exception\Renderer\InlineDebugRenderer;
+use Twig\Environment;
/**
* Test the inline debug exception renderer.
@@ -33,9 +34,9 @@ public function testRenderWithoutDebug(): void
$debug = false;
$exception = $this->createMock('\Exception');
$block = $this->createMock('Sonata\BlockBundle\Model\BlockInterface');
- $templating = $this->createMock('Symfony\Bundle\FrameworkBundle\Templating\EngineInterface');
+ $twig = $this->createMock(Environment::class);
- $renderer = new InlineDebugRenderer($templating, $template, $debug);
+ $renderer = new InlineDebugRenderer($twig, $template, $debug);
// WHEN
$response = $renderer->render($exception, $block);
@@ -60,9 +61,9 @@ public function testRenderWithDebugEnabled(): void
// mock a block instance that provoked the exception
$block = $this->createMock('Sonata\BlockBundle\Model\BlockInterface');
- // mock the templating render() to return an html result
- $templating = $this->createMock('Symfony\Bundle\FrameworkBundle\Templating\EngineInterface');
- $templating->expects($this->once())
+ // mock the twig render() to return an html result
+ $twig = $this->createMock(Environment::class);
+ $twig->expects($this->once())
->method('render')
->with(
$this->equalTo($template),
@@ -91,7 +92,7 @@ public function testRenderWithDebugEnabled(): void
->will($this->returnValue('html'));
// create renderer to test
- $renderer = new InlineDebugRenderer($templating, $template, $debug);
+ $renderer = new InlineDebugRenderer($twig, $template, $debug);
// WHEN
$response = $renderer->render($exception, $block);
diff --git a/tests/Exception/Renderer/InlineRendererTest.php b/tests/Exception/Renderer/InlineRendererTest.php
index f5359d99..d131b072 100644
--- a/tests/Exception/Renderer/InlineRendererTest.php
+++ b/tests/Exception/Renderer/InlineRendererTest.php
@@ -15,6 +15,7 @@
use PHPUnit\Framework\TestCase;
use Sonata\BlockBundle\Exception\Renderer\InlineRenderer;
+use Twig\Environment;
/**
* Test the inline exception renderer.
@@ -37,9 +38,9 @@ public function testRender(): void
// mock a block instance that provoked the exception
$block = $this->createMock('Sonata\BlockBundle\Model\BlockInterface');
- // mock the templating render() to return an html result
- $templating = $this->createMock('Symfony\Bundle\FrameworkBundle\Templating\EngineInterface');
- $templating->expects($this->once())
+ // mock the twig render() to return an html result
+ $twig = $this->createMock(Environment::class);
+ $twig->expects($this->once())
->method('render')
->with(
$this->equalTo($template),
@@ -50,7 +51,7 @@ public function testRender(): void
->will($this->returnValue('html'));
// create renderer to test
- $renderer = new InlineRenderer($templating, $template);
+ $renderer = new InlineRenderer($twig, $template);
// WHEN
$response = $renderer->render($exception, $block);
diff --git a/tests/Exception/Strategy/StrategyManagerTest.php b/tests/Exception/Strategy/StrategyManagerTest.php
index e169785d..5607d7cb 100644
--- a/tests/Exception/Strategy/StrategyManagerTest.php
+++ b/tests/Exception/Strategy/StrategyManagerTest.php
@@ -18,6 +18,7 @@
use Sonata\BlockBundle\Exception\Renderer\RendererInterface;
use Sonata\BlockBundle\Exception\Strategy\StrategyManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
+use Symfony\Component\HttpFoundation\Response;
/**
* Test the Exception Strategy Manager.
@@ -205,9 +206,11 @@ public function testHandleExceptionWithKeepNoneFilter(): void
*/
public function testHandleExceptionWithKeepAllFilter(): void
{
+ $rendererResponse = new Response();
+ $rendererResponse->setContent('renderer response');
// GIVEN
$this->filter1->expects($this->once())->method('handle')->will($this->returnValue(true));
- $this->renderer1->expects($this->once())->method('render')->will($this->returnValue('renderer response'));
+ $this->renderer1->expects($this->once())->method('render')->will($this->returnValue($rendererResponse));
$exception = new \Exception();
$block = $this->getMockBlock('block.other_type');
@@ -217,7 +220,7 @@ public function testHandleExceptionWithKeepAllFilter(): void
// THEN
$this->assertNotNull($response, 'should return something');
- $this->assertEquals('renderer response', $response, 'should return the renderer response');
+ $this->assertEquals('renderer response', $response->getContent(), 'should return the renderer response');
}
/**
diff --git a/tests/Test/FakeTemplatingTest.php b/tests/Test/FakeTemplatingTest.php
deleted file mode 100644
index 9c19ed17..00000000
--- a/tests/Test/FakeTemplatingTest.php
+++ /dev/null
@@ -1,64 +0,0 @@
-
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Sonata\BlockBundle\Tests\Test;
-
-use PHPUnit\Framework\TestCase;
-use Sonata\BlockBundle\Test\FakeTemplating;
-
-class FakeTemplatingTest extends TestCase
-{
- public function testRender(): void
- {
- $templating = new FakeTemplating();
- $templating->render('template.html.twig', [
- 'foo' => 'bar',
- ]);
-
- $this->assertSame('template.html.twig', $templating->name);
- $this->assertSame([
- 'foo' => 'bar',
- ], $templating->parameters);
- }
-
- public function testRenderResponse(): void
- {
- $response = $this->getMockBuilder('Symfony\Component\HttpFoundation\Response')->getMock();
-
- $templating = new FakeTemplating();
- $templating->renderResponse('template.html.twig', [
- 'foo' => 'bar',
- ], $response);
-
- $this->assertSame('template.html.twig', $templating->view);
- $this->assertSame([
- 'foo' => 'bar',
- ], $templating->parameters);
- $this->assertSame($response, $templating->response);
- }
-
- public function testSupports(): void
- {
- $templating = new FakeTemplating();
- $this->assertTrue($templating->supports('foo'));
- }
-
- /**
- * {@inheritdoc}
- */
- public function testExists(): void
- {
- $templating = new FakeTemplating();
- $this->assertTrue($templating->exists('foo'));
- }
-}