From 110ba4471804a9ba0c5150eecc297792bd887670 Mon Sep 17 00:00:00 2001 From: Oliver Kossin Date: Wed, 24 Jul 2024 15:46:42 +0200 Subject: [PATCH] Add Symfony 7 support (#92) --- Command/ImportCommand.php | 2 +- DependencyInjection/Configuration.php | 2 +- GoneSubscriber/GoneEntitySubscriber.php | 15 +------- Resources/config/gone_subscriber.xml | 2 +- .../Controller/RedirectControllerTest.php | 36 +++++++------------ composer.json | 24 ++++++------- phpstan-baseline.neon | 25 ------------- 7 files changed, 28 insertions(+), 78 deletions(-) diff --git a/Command/ImportCommand.php b/Command/ImportCommand.php index fc6030f..3dff618 100644 --- a/Command/ImportCommand.php +++ b/Command/ImportCommand.php @@ -46,7 +46,7 @@ public function configure(): void ); } - public function execute(InputInterface $input, OutputInterface $output) + public function execute(InputInterface $input, OutputInterface $output): int { $progressBar = new ProgressBar($output); $progressBar->setFormat(' %current% [%bar%] %elapsed:6s% %memory:6s%'); diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index d96b229..c288a47 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -21,7 +21,7 @@ */ class Configuration implements ConfigurationInterface { - public function getConfigTreeBuilder() + public function getConfigTreeBuilder(): TreeBuilder { $treeBuilder = new TreeBuilder('sulu_redirect'); $treeBuilder->getRootNode() diff --git a/GoneSubscriber/GoneEntitySubscriber.php b/GoneSubscriber/GoneEntitySubscriber.php index 1e0ba40..8ffd51f 100644 --- a/GoneSubscriber/GoneEntitySubscriber.php +++ b/GoneSubscriber/GoneEntitySubscriber.php @@ -11,25 +11,19 @@ namespace Sulu\Bundle\RedirectBundle\GoneSubscriber; -use Doctrine\Common\EventSubscriber; use Doctrine\ORM\Event\LifecycleEventArgs; -use Doctrine\ORM\Events; use Sulu\Bundle\RedirectBundle\Entity\RedirectRoute; use Sulu\Bundle\RedirectBundle\Exception\RedirectRouteNotUniqueException; use Sulu\Bundle\RedirectBundle\Manager\RedirectRouteManagerInterface; use Sulu\Bundle\RouteBundle\Model\RouteInterface; -use Symfony\Component\DependencyInjection\ContainerAwareInterface; -use Symfony\Component\DependencyInjection\ContainerAwareTrait; /** * This gone subscriber listens for removed route entities. * * @internal this is a internal listener which should not be used directly */ -class GoneEntitySubscriber implements EventSubscriber, ContainerAwareInterface +class GoneEntitySubscriber { - use ContainerAwareTrait; - /** * @var RedirectRouteManagerInterface */ @@ -41,13 +35,6 @@ public function __construct( $this->redirectRouteManager = $redirectRouteManager; } - public function getSubscribedEvents() - { - return [ - Events::preRemove, - ]; - } - public function preRemove(LifecycleEventArgs $event): void { $route = $event->getObject(); diff --git a/Resources/config/gone_subscriber.xml b/Resources/config/gone_subscriber.xml index 45add9f..24bbebd 100644 --- a/Resources/config/gone_subscriber.xml +++ b/Resources/config/gone_subscriber.xml @@ -19,7 +19,7 @@ class="Sulu\Bundle\RedirectBundle\GoneSubscriber\GoneEntitySubscriber"> - + diff --git a/Tests/Unit/Controller/RedirectControllerTest.php b/Tests/Unit/Controller/RedirectControllerTest.php index eb20eec..31f4302 100644 --- a/Tests/Unit/Controller/RedirectControllerTest.php +++ b/Tests/Unit/Controller/RedirectControllerTest.php @@ -14,7 +14,6 @@ use PHPUnit\Framework\TestCase; use Sulu\Bundle\RedirectBundle\Controller\WebsiteRedirectController; use Sulu\Bundle\RedirectBundle\Model\RedirectRouteInterface; -use Symfony\Component\HttpFoundation\ParameterBag; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; @@ -25,16 +24,6 @@ class RedirectControllerTest extends TestCase */ private $controller; - /** - * @var Request - */ - private $request; - - /** - * @var ParameterBag - */ - private $queryBag; - /** * @var RedirectRouteInterface */ @@ -43,12 +32,7 @@ class RedirectControllerTest extends TestCase protected function setUp(): void { $this->controller = new WebsiteRedirectController(); - - $this->request = $this->prophesize(Request::class); - $this->queryBag = $this->prophesize(ParameterBag::class); $this->redirectRoute = $this->prophesize(RedirectRouteInterface::class); - - $this->request->reveal()->query = $this->queryBag->reveal(); } public function testRedirect() @@ -56,12 +40,12 @@ public function testRedirect() $target = '/test'; $statusCode = 301; - $this->queryBag->all()->willReturn([]); + $request = Request::create('http://captain-sulu.io/'); $this->redirectRoute->getTarget()->willReturn($target); $this->redirectRoute->getStatusCode()->willReturn($statusCode); - $response = $this->controller->redirect($this->request->reveal(), $this->redirectRoute->reveal()); + $response = $this->controller->redirect($request, $this->redirectRoute->reveal()); $this->assertInstanceOf(RedirectResponse::class, $response); $this->assertEquals($target, $response->getTargetUrl()); @@ -74,12 +58,14 @@ public function testRedirectWithQuery() $statusCode = 301; $query = ['test' => 1, 'my-parameter' => 'awesome sulu']; - $this->queryBag->all()->willReturn($query); + $request = Request::create('http://captain-sulu.io/'); + $request->query->set('test', $query['test']); + $request->query->set('my-parameter', $query['my-parameter']); $this->redirectRoute->getTarget()->willReturn($target); $this->redirectRoute->getStatusCode()->willReturn($statusCode); - $response = $this->controller->redirect($this->request->reveal(), $this->redirectRoute->reveal()); + $response = $this->controller->redirect($request, $this->redirectRoute->reveal()); $this->assertInstanceOf(RedirectResponse::class, $response); $this->assertEquals( @@ -94,12 +80,12 @@ public function testRedirectExternal() $target = 'http://captain-sulu.io/test'; $statusCode = 301; - $this->queryBag->all()->willReturn([]); + $request = Request::create('http://captain-sulu.io/'); $this->redirectRoute->getTarget()->willReturn($target); $this->redirectRoute->getStatusCode()->willReturn($statusCode); - $response = $this->controller->redirect($this->request->reveal(), $this->redirectRoute->reveal()); + $response = $this->controller->redirect($request, $this->redirectRoute->reveal()); $this->assertInstanceOf(RedirectResponse::class, $response); $this->assertEquals( @@ -115,12 +101,14 @@ public function testRedirectExternalWithQuery() $statusCode = 301; $query = ['test' => 1, 'my-parameter' => 'awesome sulu']; - $this->queryBag->all()->willReturn($query); + $request = Request::create('http://captain-sulu.io/'); + $request->query->set('test', $query['test']); + $request->query->set('my-parameter', $query['my-parameter']); $this->redirectRoute->getTarget()->willReturn($target); $this->redirectRoute->getStatusCode()->willReturn($statusCode); - $response = $this->controller->redirect($this->request->reveal(), $this->redirectRoute->reveal()); + $response = $this->controller->redirect($request, $this->redirectRoute->reveal()); $this->assertInstanceOf(RedirectResponse::class, $response); $this->assertEquals( diff --git a/composer.json b/composer.json index a7d8120..863c95b 100644 --- a/composer.json +++ b/composer.json @@ -7,18 +7,18 @@ "php": "^7.2 || ^8.0", "sulu/sulu": "^2.2.5 || ^2.3@dev", "ramsey/uuid": "^3.1 || ^4.0", - "symfony/dependency-injection": "^4.3 || ^5.0 || ^6.0", - "symfony/config": "^4.3 || ^5.0 || ^6.0", - "symfony/console": "^4.3 || ^5.0 || ^6.0", - "symfony/http-foundation": "^4.3 || ^5.0 || ^6.0", + "symfony/dependency-injection": "^4.3 || ^5.0 || ^6.0 || ^7.0", + "symfony/config": "^4.3 || ^5.0 || ^6.0 || ^7.0", + "symfony/console": "^4.3 || ^5.0 || ^6.0 || ^7.0", + "symfony/http-foundation": "^4.3 || ^5.0 || ^6.0 || ^7.0", "handcraftedinthealps/rest-routing-bundle": "^1.0", "friendsofsymfony/rest-bundle": "^2.8 || ^3.0", "jms/serializer-bundle": "^3.0 || ^4.0 || ^5.0", - "symfony/http-kernel": "^4.3 || ^5.0 || ^6.0", + "symfony/http-kernel": "^4.3 || ^5.0 || ^6.0 || ^7.0", "doctrine/orm": "^2.5.3", - "symfony/event-dispatcher": "^4.3 || ^5.0 || ^6.0", - "symfony/property-access": "^4.3 || ^5.0 || ^6.0", - "symfony/routing": "^4.3 || ^5.0 || ^6.0", + "symfony/event-dispatcher": "^4.3 || ^5.0 || ^6.0 || ^7.0", + "symfony/property-access": "^4.3 || ^5.0 || ^6.0 || ^7.0", + "symfony/routing": "^4.3 || ^5.0 || ^6.0 || ^7.0", "symfony-cmf/routing": "^2.1 || ^3.0" }, "require-dev": { @@ -30,12 +30,12 @@ "phpstan/phpstan-symfony": "^1.0", "phpunit/phpunit": "^8.0", "php-cs-fixer/shim": "^3.0", - "symfony/browser-kit": "^4.3 || ^5.0 || ^6.0", - "symfony/dotenv": "^4.3 || ^5.0 || ^6.0", + "symfony/browser-kit": "^4.3 || ^5.0 || ^6.0 || ^7.0", + "symfony/dotenv": "^4.3 || ^5.0 || ^6.0 || ^7.0", "symfony/monolog-bundle": "^3.1", - "jackalope/jackalope-doctrine-dbal": "^1.3.4", + "jackalope/jackalope-doctrine-dbal": "^1.3.4 || ^2.0", "handcraftedinthealps/zendsearch": "^2.0", - "symfony/framework-bundle": "^4.3 || ^5.0 || ^6.0", + "symfony/framework-bundle": "^4.3 || ^5.0 || ^6.0 || ^7.0", "phpspec/prophecy": "^1.10" }, "keywords": [ diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 389b837..2e4b222 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -320,16 +320,6 @@ parameters: count: 4 path: Tests/Unit/Controller/RedirectControllerTest.php - - - message: "#^Call to an undefined method Symfony\\\\Component\\\\HttpFoundation\\\\Request\\:\\:reveal\\(\\)\\.$#" - count: 4 - path: Tests/Unit/Controller/RedirectControllerTest.php - - - - message: "#^Cannot call method willReturn\\(\\) on array\\.$#" - count: 4 - path: Tests/Unit/Controller/RedirectControllerTest.php - - message: "#^Cannot call method willReturn\\(\\) on int\\.$#" count: 4 @@ -360,26 +350,11 @@ parameters: count: 1 path: Tests/Unit/Controller/RedirectControllerTest.php - - - message: "#^Property Sulu\\\\Bundle\\\\RedirectBundle\\\\Tests\\\\Unit\\\\Controller\\\\RedirectControllerTest\\:\\:\\$queryBag \\(Symfony\\\\Component\\\\HttpFoundation\\\\ParameterBag\\) does not accept Prophecy\\\\Prophecy\\\\ObjectProphecy\\\\.$#" - count: 1 - path: Tests/Unit/Controller/RedirectControllerTest.php - - message: "#^Property Sulu\\\\Bundle\\\\RedirectBundle\\\\Tests\\\\Unit\\\\Controller\\\\RedirectControllerTest\\:\\:\\$redirectRoute \\(Sulu\\\\Bundle\\\\RedirectBundle\\\\Model\\\\RedirectRouteInterface\\) does not accept Prophecy\\\\Prophecy\\\\ObjectProphecy\\\\.$#" count: 1 path: Tests/Unit/Controller/RedirectControllerTest.php - - - message: "#^Property Sulu\\\\Bundle\\\\RedirectBundle\\\\Tests\\\\Unit\\\\Controller\\\\RedirectControllerTest\\:\\:\\$request \\(Symfony\\\\Component\\\\HttpFoundation\\\\Request\\) does not accept Prophecy\\\\Prophecy\\\\ObjectProphecy\\\\.$#" - count: 1 - path: Tests/Unit/Controller/RedirectControllerTest.php - - - - message: "#^Property Symfony\\\\Component\\\\HttpFoundation\\\\Request\\:\\:\\$query \\(Symfony\\\\Component\\\\HttpFoundation\\\\InputBag\\\\) does not accept Symfony\\\\Component\\\\HttpFoundation\\\\ParameterBag\\.$#" - count: 1 - path: Tests/Unit/Controller/RedirectControllerTest.php - - message: "#^Cannot access offset 'exceptions' on mixed\\.$#" count: 2