Skip to content

Commit

Permalink
Merge pull request hwi#1685 from stloyd/drop-sf34
Browse files Browse the repository at this point in the history
[BC Break] Drop Support for Symfony <4.4
  • Loading branch information
stloyd authored Jan 2, 2021
2 parents 4ebc607 + 7ad12fc commit 14bd1e1
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 124 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ jobs:
fail-fast: false
env:
SYMFONY_PHPUNIT_VERSION: '8.5'
# Symfony Event Dispatcher proxy deprecation
SYMFONY_DEPRECATIONS_HELPER: max[total]=1
steps:
- name: Checkout
uses: actions/checkout@v2
Expand Down Expand Up @@ -135,8 +133,6 @@ jobs:
fail-fast: false
env:
SYMFONY_PHPUNIT_VERSION: '8.5'
# Symfony Event Dispatcher proxy deprecation
SYMFONY_DEPRECATIONS_HELPER: max[total]=1
steps:
- name: Checkout
uses: actions/checkout@v2
Expand Down
10 changes: 1 addition & 9 deletions Controller/ConnectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
use HWI\Bundle\OAuthBundle\Security\Http\ResourceOwnerMapLocator;
use HWI\Bundle\OAuthBundle\Security\OAuthUtils;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy;
use Symfony\Component\Form\Extension\Core\Type\FormType;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\Request;
Expand Down Expand Up @@ -351,13 +350,6 @@ private function getConfirmationResponse(Request $request, array $accessToken, s

private function dispatch($event, string $eventName = null): void
{
// LegacyEventDispatcherProxy exists in Symfony >= 4.3
if (class_exists(LegacyEventDispatcherProxy::class)) {
// New Symfony 4.3 EventDispatcher signature
$this->get('event_dispatcher')->dispatch($event, $eventName);
} else {
// Old EventDispatcher signature
$this->get('event_dispatcher')->dispatch($eventName, $event);
}
$this->get('event_dispatcher')->dispatch($event, $eventName);
}
}
72 changes: 22 additions & 50 deletions Tests/Controller/ConnectControllerConnectServiceActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
use HWI\Bundle\OAuthBundle\Event\GetResponseUserEvent;
use HWI\Bundle\OAuthBundle\HWIOAuthEvents;
use HWI\Bundle\OAuthBundle\Tests\Fixtures\CustomOAuthToken;
use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;

class ConnectControllerConnectServiceActionTest extends AbstractConnectControllerTest
{
public function testNotEnabled()
{
$this->expectException(\Symfony\Component\HttpKernel\Exception\NotFoundHttpException::class);
$this->expectException(NotFoundHttpException::class);

$this->container->setParameter('hwi_oauth.connect', false);

Expand All @@ -31,7 +32,7 @@ public function testNotEnabled()

public function testAlreadyConnected()
{
$this->expectException(\Symfony\Component\Security\Core\Exception\AccessDeniedException::class);
$this->expectException(AccessDeniedException::class);
$this->expectExceptionMessage('Cannot connect an account.');

$this->mockAuthorizationCheck(false);
Expand All @@ -41,7 +42,7 @@ public function testAlreadyConnected()

public function testUnknownResourceOwner()
{
$this->expectException(\Symfony\Component\HttpKernel\Exception\NotFoundHttpException::class);
$this->expectException(NotFoundHttpException::class);

$this->container->setParameter('hwi_oauth.firewall_names', []);

Expand Down Expand Up @@ -75,17 +76,9 @@ public function testConnectConfirm()
->willReturn($form)
;

$this->eventDispatcher->expects($this->once())->method('dispatch');

if (class_exists(LegacyEventDispatcherProxy::class)) {
$this->eventDispatcher->expects($this->at(0))
->method('dispatch')
->with($this->isInstanceOf(GetResponseUserEvent::class), HWIOAuthEvents::CONNECT_INITIALIZE);
} else {
$this->eventDispatcher->expects($this->at(0))
->method('dispatch')
->with(HWIOAuthEvents::CONNECT_INITIALIZE);
}
$this->eventDispatcher->expects($this->once())
->method('dispatch')
->with($this->isInstanceOf(GetResponseUserEvent::class), HWIOAuthEvents::CONNECT_INITIALIZE);

$this->twig->expects($this->once())
->method('render')
Expand Down Expand Up @@ -125,21 +118,12 @@ public function testConnectSuccess()
;

$this->eventDispatcher->expects($this->exactly(2))->method('dispatch');
if (class_exists(LegacyEventDispatcherProxy::class)) {
$this->eventDispatcher->expects($this->at(0))
->method('dispatch')
->with($this->isInstanceOf(GetResponseUserEvent::class), HWIOAuthEvents::CONNECT_CONFIRMED);
$this->eventDispatcher->expects($this->at(1))
->method('dispatch')
->with($this->isInstanceOf(FilterUserResponseEvent::class), HWIOAuthEvents::CONNECT_COMPLETED);
} else {
$this->eventDispatcher->expects($this->at(0))
->method('dispatch')
->with(HWIOAuthEvents::CONNECT_CONFIRMED);
$this->eventDispatcher->expects($this->at(1))
->method('dispatch')
->with(HWIOAuthEvents::CONNECT_COMPLETED);
}
$this->eventDispatcher->expects($this->at(0))
->method('dispatch')
->with($this->isInstanceOf(GetResponseUserEvent::class), HWIOAuthEvents::CONNECT_CONFIRMED);
$this->eventDispatcher->expects($this->at(1))
->method('dispatch')
->with($this->isInstanceOf(FilterUserResponseEvent::class), HWIOAuthEvents::CONNECT_COMPLETED);

$this->twig->expects($this->once())
->method('render')
Expand Down Expand Up @@ -170,26 +154,14 @@ public function testConnectNoConfirmation()
;

$this->eventDispatcher->expects($this->exactly(2))->method('dispatch');

if (class_exists(LegacyEventDispatcherProxy::class)) {
$this->eventDispatcher->expects($this->at(0))
->method('dispatch')
->with($this->isInstanceOf(GetResponseUserEvent::class), HWIOAuthEvents::CONNECT_CONFIRMED)
;
$this->eventDispatcher->expects($this->at(1))
->method('dispatch')
->with($this->isInstanceOf(FilterUserResponseEvent::class), HWIOAuthEvents::CONNECT_COMPLETED)
;
} else {
$this->eventDispatcher->expects($this->at(0))
->method('dispatch')
->with(HWIOAuthEvents::CONNECT_CONFIRMED)
;
$this->eventDispatcher->expects($this->at(1))
->method('dispatch')
->with(HWIOAuthEvents::CONNECT_COMPLETED)
;
}
$this->eventDispatcher->expects($this->at(0))
->method('dispatch')
->with($this->isInstanceOf(GetResponseUserEvent::class), HWIOAuthEvents::CONNECT_CONFIRMED)
;
$this->eventDispatcher->expects($this->at(1))
->method('dispatch')
->with($this->isInstanceOf(FilterUserResponseEvent::class), HWIOAuthEvents::CONNECT_COMPLETED)
;

$this->twig->expects($this->once())
->method('render')
Expand Down
65 changes: 19 additions & 46 deletions Tests/Controller/ConnectControllerRegistrationActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,17 @@
use HWI\Bundle\OAuthBundle\Form\RegistrationFormHandlerInterface;
use HWI\Bundle\OAuthBundle\HWIOAuthEvents;
use HWI\Bundle\OAuthBundle\Tests\Fixtures\User;
use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy;
use Symfony\Component\Form\Form;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
use Symfony\Component\Security\Http\SecurityEvents;

class ConnectControllerRegistrationActionTest extends AbstractConnectControllerTest
{
public function testNotEnabled()
{
$this->expectException(\Symfony\Component\HttpKernel\Exception\NotFoundHttpException::class);
$this->expectException(NotFoundHttpException::class);

$this->container->setParameter('hwi_oauth.connect', false);

Expand All @@ -36,7 +37,7 @@ public function testNotEnabled()

public function testAlreadyConnected()
{
$this->expectException(\Symfony\Component\Security\Core\Exception\AccessDeniedException::class);
$this->expectException(AccessDeniedException::class);
$this->expectExceptionMessage('Cannot connect already registered account.');

$this->mockAuthorizationCheck();
Expand Down Expand Up @@ -94,17 +95,9 @@ public function testFailedProcess()
;
$this->container->set('hwi_oauth.registration.form.handler', $registrationFormHandler);

$this->eventDispatcher->expects($this->once())->method('dispatch');

if (class_exists(LegacyEventDispatcherProxy::class)) {
$this->eventDispatcher->expects($this->at(0))
->method('dispatch')
->with($this->isInstanceOf(GetResponseUserEvent::class), HWIOAuthEvents::REGISTRATION_INITIALIZE);
} else {
$this->eventDispatcher->expects($this->at(0))
->method('dispatch')
->with(HWIOAuthEvents::REGISTRATION_INITIALIZE);
}
$this->eventDispatcher->expects($this->once())
->method('dispatch')
->with($this->isInstanceOf(GetResponseUserEvent::class), HWIOAuthEvents::REGISTRATION_INITIALIZE);

$this->twig->expects($this->once())
->method('render')
Expand Down Expand Up @@ -141,38 +134,18 @@ public function test()
;

$this->eventDispatcher->expects($this->exactly(3))->method('dispatch');

if (class_exists(LegacyEventDispatcherProxy::class)) {
$this->eventDispatcher->expects($this->at(0))
->method('dispatch')
->with($this->isInstanceOf(FormEvent::class), HWIOAuthEvents::REGISTRATION_SUCCESS)
;

$this->eventDispatcher->expects($this->at(1))
->method('dispatch')
->with($this->isInstanceOf(InteractiveLoginEvent::class), SecurityEvents::INTERACTIVE_LOGIN)
;

$this->eventDispatcher->expects($this->at(2))
->method('dispatch')
->with($this->isInstanceOf(FilterUserResponseEvent::class), HWIOAuthEvents::REGISTRATION_COMPLETED)
;
} else {
$this->eventDispatcher->expects($this->at(0))
->method('dispatch')
->with(HWIOAuthEvents::REGISTRATION_SUCCESS)
;

$this->eventDispatcher->expects($this->at(1))
->method('dispatch')
->with(SecurityEvents::INTERACTIVE_LOGIN)
;

$this->eventDispatcher->expects($this->at(2))
->method('dispatch')
->with(HWIOAuthEvents::REGISTRATION_COMPLETED)
;
}
$this->eventDispatcher->expects($this->at(0))
->method('dispatch')
->with($this->isInstanceOf(FormEvent::class), HWIOAuthEvents::REGISTRATION_SUCCESS)
;
$this->eventDispatcher->expects($this->at(1))
->method('dispatch')
->with($this->isInstanceOf(InteractiveLoginEvent::class), SecurityEvents::INTERACTIVE_LOGIN)
;
$this->eventDispatcher->expects($this->at(2))
->method('dispatch')
->with($this->isInstanceOf(FilterUserResponseEvent::class), HWIOAuthEvents::REGISTRATION_COMPLETED)
;

$this->twig->expects($this->once())
->method('render')
Expand Down
30 changes: 15 additions & 15 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@

"require": {
"php": "^7.2 || ^8.0",
"symfony/framework-bundle": "^3.4.26|^4.4|^5.0",
"symfony/security-bundle": "^3.4|^4.4|^5.0",
"symfony/options-resolver": "^3.4|^4.4|^5.0",
"symfony/form": "^3.4|^4.4|^5.0",
"symfony/yaml": "^3.4|^4.4|^5.0",
"symfony/templating": "^3.4|^4.4|^5.0",
"symfony/framework-bundle": "^4.4|^5.0",
"symfony/security-bundle": "^4.4|^5.0",
"symfony/options-resolver": "^4.4|^5.0",
"symfony/form": "^4.4|^5.0",
"symfony/yaml": "^4.4|^5.0",
"symfony/templating": "^4.4|^5.0",

"psr/http-message": "^1.0",
"php-http/client-implementation": "^1.0",
Expand All @@ -111,22 +111,22 @@
},

"require-dev": {
"doctrine/orm": "^2.3",
"symfony/browser-kit": "^3.4|^4.4|^5.0",
"symfony/css-selector": "^3.4|^4.4|^5.0",
"symfony/property-access": "^3.4|^4.4|^5.0",
"symfony/validator": "^3.4|^4.4|^5.0",
"symfony/twig-bundle": "^3.4|^4.4|^5.0",
"symfony/stopwatch": "^3.4|^4.4|^5.0",
"doctrine/orm": "^2.6",
"symfony/browser-kit": "^4.4|^5.0",
"symfony/css-selector": "^4.4|^5.0",
"symfony/property-access": "^4.4|^5.0",
"symfony/validator": "^4.4|^5.0",
"symfony/twig-bundle": "^4.4|^5.0",
"symfony/stopwatch": "^4.4|^5.0",
"symfony/phpunit-bridge": "^5.1",
"symfony/translation": "^3.4|^4.4|^5.0",
"symfony/translation": "^4.4|^5.0",
"friendsofsymfony/user-bundle": "^2.1",
"php-http/httplug-bundle": "^1.7",
"php-http/guzzle6-adapter": "^2.0",
"phpunit/phpunit": "^8.5",
"friendsofphp/php-cs-fixer": "^2.0",
"symfony/monolog-bundle": "^3.4",
"doctrine/doctrine-bundle": "^1.11|^2.0"
"doctrine/doctrine-bundle": "^2.0"
},

"conflict": {
Expand Down

0 comments on commit 14bd1e1

Please sign in to comment.