From b1ebbb3bd0d7a4b923130e4146b6da74c2b9c7c9 Mon Sep 17 00:00:00 2001 From: Emanuele Minotto Date: Thu, 16 Jun 2016 23:45:04 +0200 Subject: [PATCH] Move from deprecated SecurityContext to AuthorizationChecker --- Resources/config/services.xml | 2 +- Security/FeatureSecurity.php | 8 +++--- Tests/Security/FeatureSecurityTest.php | 7 +++-- Tests/Security/LegacyFeatureSecurityTest.php | 29 ++++++++++++++++++++ 4 files changed, 38 insertions(+), 8 deletions(-) create mode 100644 Tests/Security/LegacyFeatureSecurityTest.php diff --git a/Resources/config/services.xml b/Resources/config/services.xml index 693973b..0a23efd 100644 --- a/Resources/config/services.xml +++ b/Resources/config/services.xml @@ -16,7 +16,7 @@ - + diff --git a/Security/FeatureSecurity.php b/Security/FeatureSecurity.php index fbdafe0..0bfe1c5 100644 --- a/Security/FeatureSecurity.php +++ b/Security/FeatureSecurity.php @@ -3,7 +3,7 @@ namespace Ae\FeatureBundle\Security; use Ae\FeatureBundle\Entity\Feature; -use Symfony\Component\Security\Core\SecurityContextInterface; +use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; /** * Controls access to a Feature. @@ -13,14 +13,14 @@ class FeatureSecurity { /** - * @param SecurityContextInterface|null + * @param AuthorizationCheckerInterface|null */ protected $context; /** - * @param SecurityContextInterface $context + * @param AuthorizationCheckerInterface $context */ - public function __construct(SecurityContextInterface $context = null) + public function __construct(AuthorizationCheckerInterface $context = null) { $this->context = $context; } diff --git a/Tests/Security/FeatureSecurityTest.php b/Tests/Security/FeatureSecurityTest.php index 62838d6..22d7d19 100644 --- a/Tests/Security/FeatureSecurityTest.php +++ b/Tests/Security/FeatureSecurityTest.php @@ -5,7 +5,7 @@ use Ae\FeatureBundle\Entity\Feature; use Ae\FeatureBundle\Security\FeatureSecurity; use PHPUnit_Framework_TestCase; -use Symfony\Component\Security\Core\SecurityContextInterface; +use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; /** * @author Carlo Forghieri @@ -18,10 +18,11 @@ class FeatureSecurityTest extends PHPUnit_Framework_TestCase protected function setUp() { $context = $this - ->getMockBuilder(SecurityContextInterface::class) + ->getMockBuilder(AuthorizationCheckerInterface::class) ->disableOriginalConstructor() ->getMock(); - $context->expects($this->any()) + $context + ->expects($this->any()) ->method('isGranted') ->will($this->returnValueMap([ ['ROLE_USER', null, true], diff --git a/Tests/Security/LegacyFeatureSecurityTest.php b/Tests/Security/LegacyFeatureSecurityTest.php new file mode 100644 index 0000000..4f03346 --- /dev/null +++ b/Tests/Security/LegacyFeatureSecurityTest.php @@ -0,0 +1,29 @@ + + * @covers Ae\FeatureBundle\Security\FeatureSecurity + */ +class LegacyFeatureSecurityTest extends FeatureSecurityTest +{ + protected function setUp() + { + $context = $this + ->getMockBuilder(SecurityContextInterface::class) + ->disableOriginalConstructor() + ->getMock(); + $context + ->expects($this->any()) + ->method('isGranted') + ->will($this->returnValueMap([ + ['ROLE_USER', null, true], + ['ROLE_ADMIN', null, false], + ])); + $this->security = new FeatureSecurity($context); + } +}