Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
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 <[email protected]>
Expand Down Expand Up @@ -55,6 +56,10 @@ private function getVariables(GuardEvent $event)
{
$token = $this->tokenStorage->getToken();

if (null === $token) {
throw new InvalidTokenConfigurationException(sprintf('There are no tokens available for workflow %s.', $event->getWorkflowName()));
}

if (null !== $this->roleHierarchy) {
$roles = $this->roleHierarchy->getReachableRoles($token->getRoles());
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* 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 <[email protected]>
*/
class InvalidTokenConfigurationException extends LogicException implements ExceptionInterface
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@ public function testWithSupportedEventAndAccept()
$this->assertTrue($event->isBlocked());
}

/**
* @expectedException \Symfony\Component\Workflow\Exception\InvalidTokenConfigurationException
* @expectedExceptionMessage There are no tokens available for workflow unnamed.
*/
public function testWithNoTokensInTokenStorage()
{
$event = $this->createEvent();
$this->tokenStorage->setToken(null);

$this->listener->onTransition($event, 'event_name_a');
}

private function createEvent()
{
$subject = new \stdClass();
Expand Down