Created new Exception to throw and modified tests
This commit is contained in:
parent
3a8b2eded1
commit
2ebc71a616
@ -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\Authorization\AuthorizationCheckerInterface;
|
||||||
use Symfony\Component\Security\Core\Role\RoleHierarchyInterface;
|
use Symfony\Component\Security\Core\Role\RoleHierarchyInterface;
|
||||||
use Symfony\Component\Workflow\Event\GuardEvent;
|
use Symfony\Component\Workflow\Event\GuardEvent;
|
||||||
|
use Symfony\Component\Workflow\Exception\InvalidTokenConfigurationException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Grégoire Pineau <lyrixx@lyrixx.info>
|
* @author Grégoire Pineau <lyrixx@lyrixx.info>
|
||||||
@ -56,7 +57,7 @@ class GuardListener
|
|||||||
$token = $this->tokenStorage->getToken();
|
$token = $this->tokenStorage->getToken();
|
||||||
|
|
||||||
if (null === $token) {
|
if (null === $token) {
|
||||||
throw new \Exception('No token is set');
|
throw new InvalidTokenConfigurationException('No token is set');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (null !== $this->roleHierarchy) {
|
if (null !== $this->roleHierarchy) {
|
||||||
|
@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* 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 <matj1985@gmail.com>
|
||||||
|
*/
|
||||||
|
class InvalidTokenConfigurationException extends LogicException implements ExceptionInterface
|
||||||
|
{
|
||||||
|
}
|
@ -69,12 +69,14 @@ class GuardListenerTest extends TestCase
|
|||||||
$this->assertTrue($event->isBlocked());
|
$this->assertTrue($event->isBlocked());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException \Symfony\Component\Workflow\Exception\InvalidTokenConfigurationException
|
||||||
|
* @expectedExceptionMessage No token is set
|
||||||
|
*/
|
||||||
public function testWithNoTokenStorage()
|
public function testWithNoTokenStorage()
|
||||||
{
|
{
|
||||||
$event = $this->createEvent();
|
$event = $this->createEvent();
|
||||||
$this->tokenStorage = null;
|
$this->tokenStorage->setToken(null);
|
||||||
|
|
||||||
$this->expectException(\Exception::class);
|
|
||||||
|
|
||||||
$this->listener->onTransition($event, 'event_name_a');
|
$this->listener->onTransition($event, 'event_name_a');
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user