From e293357e2b73f3a6ba7ec3c84f3853f7627f0618 Mon Sep 17 00:00:00 2001 From: conciergerie-numerique <57376688+conciergerie-numerique@users.noreply.github.com> Date: Tue, 21 Jan 2020 11:05:38 +0100 Subject: [PATCH] Fix code-level breaking changes for Symfony 5 (#35) * fix Symfony 5 breaking change (removal of FilterResponseEvent class) * set explicit dependency on twig (excluding Twig 3+ because of BC) * set php requirement to >=5.4 because of php traits usage * remove unused imports * disable \Twig_Environment constructor invocation in a test case * configure Travis CI to check all php versions between 5.4 and 7.4 * remove php7.4 from Travis CI configuration because it is not available Co-authored-by: Valentin Sviridov --- .travis.yml | 2 +- EventListener/GoogleTagManagerListener.php | 10 ++++------ Helper/GoogleTagManagerHelperInterface.php | 2 -- .../AbstractGoogleTagManagerExtensionTest.php | 2 +- Twig/GoogleTagManagerExtension.php | 2 -- composer.json | 8 ++++++-- 6 files changed, 12 insertions(+), 14 deletions(-) diff --git a/.travis.yml b/.travis.yml index faf0e00..0f30d82 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,13 +1,13 @@ language: php php: - - 5.3 - 5.4 - 5.5 - 5.6 - 7.0 - 7.1 - 7.2 + - 7.3 - nightly sudo: false diff --git a/EventListener/GoogleTagManagerListener.php b/EventListener/GoogleTagManagerListener.php index bbf79a1..b56f6db 100644 --- a/EventListener/GoogleTagManagerListener.php +++ b/EventListener/GoogleTagManagerListener.php @@ -2,8 +2,6 @@ namespace Xynnn\GoogleTagManagerBundle\EventListener; -use Symfony\Component\DependencyInjection\ContainerInterface; -use Symfony\Component\HttpKernel\Event\FilterResponseEvent; use Xynnn\GoogleTagManagerBundle\Twig\GoogleTagManagerExtension; /** @@ -41,11 +39,11 @@ public function __construct(\Twig_Environment $environment, GoogleTagManagerExte } /** - * @param FilterResponseEvent $event + * @param mixed $event FilterResponseEvent before Symfony 5 and ResponseEvent afterwards * * @return bool */ - public function onKernelResponse(FilterResponseEvent $event) + public function onKernelResponse($event) { if (!$this->allowRender($event)) { return false; @@ -80,11 +78,11 @@ public function onKernelResponse(FilterResponseEvent $event) } /** - * @param FilterResponseEvent $event + * @param mixed $event FilterResponseEvent before Symfony 5 and ResponseEvent afterwards * * @return bool */ - private function allowRender(FilterResponseEvent $event) + private function allowRender($event) { // not configured to append automatically if (!$this->autoAppend) { diff --git a/Helper/GoogleTagManagerHelperInterface.php b/Helper/GoogleTagManagerHelperInterface.php index df812f6..054c203 100644 --- a/Helper/GoogleTagManagerHelperInterface.php +++ b/Helper/GoogleTagManagerHelperInterface.php @@ -10,9 +10,7 @@ namespace Xynnn\GoogleTagManagerBundle\Helper; -use Symfony\Component\Templating\Helper\Helper; use Symfony\Component\Templating\Helper\HelperInterface; -use Xynnn\GoogleTagManagerBundle\Service\GoogleTagManagerInterface; /** * Interface GoogleTagManagerHelperInterface diff --git a/Tests/DependencyInjection/AbstractGoogleTagManagerExtensionTest.php b/Tests/DependencyInjection/AbstractGoogleTagManagerExtensionTest.php index 1a95aec..3f04e1c 100644 --- a/Tests/DependencyInjection/AbstractGoogleTagManagerExtensionTest.php +++ b/Tests/DependencyInjection/AbstractGoogleTagManagerExtensionTest.php @@ -32,7 +32,7 @@ protected function setUp() $this->extension = new GoogleTagManagerExtension(); $this->container = new ContainerBuilder(); - $this->container->register('twig', $this->getMockBuilder('\Twig_Environment')->getMock()); + $this->container->register('twig', $this->getMockBuilder('\Twig_Environment')->disableOriginalConstructor()->getMock()); $this->container->registerExtension($this->extension); } diff --git a/Twig/GoogleTagManagerExtension.php b/Twig/GoogleTagManagerExtension.php index ff85616..993bc22 100644 --- a/Twig/GoogleTagManagerExtension.php +++ b/Twig/GoogleTagManagerExtension.php @@ -10,9 +10,7 @@ namespace Xynnn\GoogleTagManagerBundle\Twig; -use Symfony\Component\Templating\Helper\HelperInterface; use Twig_Extension; -use Xynnn\GoogleTagManagerBundle\Helper\GoogleTagManagerHelper; use Xynnn\GoogleTagManagerBundle\Helper\GoogleTagManagerHelperInterface; /** diff --git a/composer.json b/composer.json index c5d62a7..dcfeebc 100644 --- a/composer.json +++ b/composer.json @@ -13,11 +13,15 @@ ], "minimum-stability": "dev", "require": { - "php": ">=5.3.2", + "php": ">=5.4", "symfony/dependency-injection": "~2.8|~3.0|~4.0|~5.0", "symfony/http-kernel": "~2.8|~3.0|~4.0|~5.0", "symfony/config": "~2.8|~3.0|~4.0|~5.0", - "symfony/templating": "~2.8|~3.0|~4.0|~5.0" + "symfony/templating": "~2.8|~3.0|~4.0|~5.0", + "twig/twig": "~1.23|~2.0" + }, + "conflict": { + "twig/twig": ">=3.0" }, "require-dev": { "phpunit/phpunit": "~4.3"