Skip to content

Commit

Permalink
Add Symfony 7 support (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheCadien authored Jul 24, 2024
1 parent 1166ef2 commit 110ba44
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 78 deletions.
2 changes: 1 addition & 1 deletion Command/ImportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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%');
Expand Down
2 changes: 1 addition & 1 deletion DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
class Configuration implements ConfigurationInterface
{
public function getConfigTreeBuilder()
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('sulu_redirect');
$treeBuilder->getRootNode()
Expand Down
15 changes: 1 addition & 14 deletions GoneSubscriber/GoneEntitySubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion Resources/config/gone_subscriber.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
class="Sulu\Bundle\RedirectBundle\GoneSubscriber\GoneEntitySubscriber">
<argument type="service" id="sulu_redirect.redirect_route_manager"/>

<tag name="doctrine.event_subscriber"/>
<tag name="doctrine.event_listener" event="preRemove"/>
</service>
</services>
</container>
36 changes: 12 additions & 24 deletions Tests/Unit/Controller/RedirectControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -25,16 +24,6 @@ class RedirectControllerTest extends TestCase
*/
private $controller;

/**
* @var Request
*/
private $request;

/**
* @var ParameterBag
*/
private $queryBag;

/**
* @var RedirectRouteInterface
*/
Expand All @@ -43,25 +32,20 @@ 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()
{
$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());
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand Down
24 changes: 12 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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": [
Expand Down
25 changes: 0 additions & 25 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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\\<Symfony\\\\Component\\\\HttpFoundation\\\\ParameterBag\\>\\.$#"
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\\<Sulu\\\\Bundle\\\\RedirectBundle\\\\Model\\\\RedirectRouteInterface\\>\\.$#"
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\\<Symfony\\\\Component\\\\HttpFoundation\\\\Request\\>\\.$#"
count: 1
path: Tests/Unit/Controller/RedirectControllerTest.php

-
message: "#^Property Symfony\\\\Component\\\\HttpFoundation\\\\Request\\:\\:\\$query \\(Symfony\\\\Component\\\\HttpFoundation\\\\InputBag\\<string\\>\\) does not accept Symfony\\\\Component\\\\HttpFoundation\\\\ParameterBag\\.$#"
count: 1
path: Tests/Unit/Controller/RedirectControllerTest.php

-
message: "#^Cannot access offset 'exceptions' on mixed\\.$#"
count: 2
Expand Down

0 comments on commit 110ba44

Please sign in to comment.