Created new Exception to throw and modified tests

This commit is contained in:
GDIBass 2017-08-18 08:37:36 -07:00
parent 3a8b2eded1
commit 2ebc71a616
3 changed files with 28 additions and 4 deletions

View File

@ -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 <lyrixx@lyrixx.info>
@ -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) {

View File

@ -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
{
}

View File

@ -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');
}