From 2ebc71a61671d30142b1f67989c9c48dff5bf425 Mon Sep 17 00:00:00 2001 From: GDIBass Date: Fri, 18 Aug 2017 08:37:36 -0700 Subject: [PATCH] Created new Exception to throw and modified tests --- .../Workflow/EventListener/GuardListener.php | 3 ++- .../InvalidTokenConfigurationException.php | 21 +++++++++++++++++++ .../Tests/EventListener/GuardListenerTest.php | 8 ++++--- 3 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 src/Symfony/Component/Workflow/Exception/InvalidTokenConfigurationException.php diff --git a/src/Symfony/Component/Workflow/EventListener/GuardListener.php b/src/Symfony/Component/Workflow/EventListener/GuardListener.php index 3e402e9280..5d10cbcfce 100644 --- a/src/Symfony/Component/Workflow/EventListener/GuardListener.php +++ b/src/Symfony/Component/Workflow/EventListener/GuardListener.php @@ -16,6 +16,7 @@ use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInt use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; use Symfony\Component\Security\Core\Role\RoleHierarchyInterface; use Symfony\Component\Workflow\Event\GuardEvent; +use Symfony\Component\Workflow\Exception\InvalidTokenConfigurationException; /** * @author Grégoire Pineau @@ -56,7 +57,7 @@ class GuardListener $token = $this->tokenStorage->getToken(); if (null === $token) { - throw new \Exception('No token is set'); + throw new InvalidTokenConfigurationException('No token is set'); } if (null !== $this->roleHierarchy) { diff --git a/src/Symfony/Component/Workflow/Exception/InvalidTokenConfigurationException.php b/src/Symfony/Component/Workflow/Exception/InvalidTokenConfigurationException.php new file mode 100644 index 0000000000..367d4c6eb6 --- /dev/null +++ b/src/Symfony/Component/Workflow/Exception/InvalidTokenConfigurationException.php @@ -0,0 +1,21 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Workflow\Exception; + +/** + * Thrown by GuardListener when there is no token set, but guards are placed on a transition + * + * @author Matt Johnson + */ +class InvalidTokenConfigurationException extends LogicException implements ExceptionInterface +{ +} \ No newline at end of file diff --git a/src/Symfony/Component/Workflow/Tests/EventListener/GuardListenerTest.php b/src/Symfony/Component/Workflow/Tests/EventListener/GuardListenerTest.php index d72e319313..c32aec06a4 100644 --- a/src/Symfony/Component/Workflow/Tests/EventListener/GuardListenerTest.php +++ b/src/Symfony/Component/Workflow/Tests/EventListener/GuardListenerTest.php @@ -69,12 +69,14 @@ class GuardListenerTest extends TestCase $this->assertTrue($event->isBlocked()); } + /** + * @expectedException \Symfony\Component\Workflow\Exception\InvalidTokenConfigurationException + * @expectedExceptionMessage No token is set + */ public function testWithNoTokenStorage() { $event = $this->createEvent(); - $this->tokenStorage = null; - - $this->expectException(\Exception::class); + $this->tokenStorage->setToken(null); $this->listener->onTransition($event, 'event_name_a'); }