From 592c57acce42c477376638be3eab280592b65e0b Mon Sep 17 00:00:00 2001 From: core23 Date: Fri, 27 Dec 2019 08:23:16 +0100 Subject: [PATCH] Remove test deprecation --- src/Test/BlockServiceTestCase.php | 24 ++++++++---- tests/Block/Service/EmptyBlockServiceTest.php | 39 ++++++++++++++++--- 2 files changed, 51 insertions(+), 12 deletions(-) diff --git a/src/Test/BlockServiceTestCase.php b/src/Test/BlockServiceTestCase.php index c4a90b10..72b5ffd5 100644 --- a/src/Test/BlockServiceTestCase.php +++ b/src/Test/BlockServiceTestCase.php @@ -49,17 +49,29 @@ abstract class InternalBlockServiceTestCase extends TestCase */ protected $blockContextManager; + /** + * @var Environment + */ + protected $twig; + /** * NEXT_MAJOR: Remove this property. - * - * @var FakeTemplating */ - protected $templating; + private $internalTemplating; /** - * @var Environment + * NEXT_MAJOR: Remove this property hack. */ - protected $twig; + public function __get($name) + { + if ('templating' === $name) { + if (null === $this->internalTemplating) { + $this->internalTemplating = new FakeTemplating(); + } + + return $this->internalTemplating; + } + } /** * @internal @@ -67,8 +79,6 @@ abstract class InternalBlockServiceTestCase extends TestCase protected function internalSetUp(): void { $this->container = $this->createMock(ContainerInterface::class); - // NEXT_MAJOR: Remove the following assignment. - $this->templating = new FakeTemplating(); $blockLoader = $this->createMock(BlockLoaderInterface::class); $this->blockServiceManager = $this->createMock(BlockServiceManagerInterface::class); diff --git a/tests/Block/Service/EmptyBlockServiceTest.php b/tests/Block/Service/EmptyBlockServiceTest.php index d2a5ea52..d597252c 100644 --- a/tests/Block/Service/EmptyBlockServiceTest.php +++ b/tests/Block/Service/EmptyBlockServiceTest.php @@ -23,15 +23,44 @@ final class EmptyBlockServiceTest extends BlockServiceTestCase { /** * NEXT_MAJOR: Remove this test. + * + * @group legacy */ - public function testArgumentCheck() + public function testInvalidConstructor(): void { - new EmptyBlockService($this->twig); - new EmptyBlockService($this->templating); - new EmptyBlockService('sonata.page.block.rss'); - $this->expectException(\TypeError::class); $this->expectExceptionMessage('Argument 1 passed to Sonata\BlockBundle\Block\Service\EmptyBlockService::__construct() must be a string or an instance of Twig\Environment or Symfony\Component\Templating\EngineInterface, instance of stdClass given.'); + new EmptyBlockService(new \stdClass()); } + + /** + * NEXT_MAJOR: Remove this test. + * + * @group legacy + */ + public function testDeprecatedStringConstructor(): void + { + new EmptyBlockService('sonata.page.block.empty'); + } + + /** + * NEXT_MAJOR: Remove this test. + * + * @group legacy + * + * @expectedDeprecation The Sonata\BlockBundle\Test\FakeTemplating class is deprecated since 3.17 and will be removed in version 4.0. + */ + public function testDeprecatedTemplatingConstructor(): void + { + new EmptyBlockService($this->templating); + } + + /** + * NEXT_MAJOR: Remove this test. + */ + public function testValiConstructor(): void + { + new EmptyBlockService($this->twig); + } }