8000 Added support for guards when advancing workflow from a command by GDIBass · Pull Request #23906 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Added support for guards when advancing workflow from a command #23906

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Oct 5, 2017
Prev Previous commit
Next Next commit
Created new Exception to throw and modified tests
  • Loading branch information
GDIBass committed Aug 18, 2017
commit 2ebc71a61671d30142b1f67989c9c48dff5bf425
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Symfony\Component\Security\Core\Authoriz 10000 ation\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>
Expand Down Expand Up @@ -56,7 +57,7 @@ private function getVariables(GuardEvent $event)
$token = $this->tokenStorage->getToken();

if (null === $token) {
throw new \Exception('No token is set');
throw new InvalidTokenConfigurationException('No token is set');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could maybe be something like sprintf('There are no token available for the transition event %s', $eventName) ?

WDYT @lyrixx ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So:

throw new InvalidTokenConfigurationException(sprintf('There are no token available for the transition event %s', $event->getWorkflowName()));

}

if (null !== $this->roleHierarchy) {
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 <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
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,14 @@ public function testWithSupportedEventAndAccept()
$this->assertTrue($event->isBlocked());
}

/**
* @expectedException \Symfony\Component\Workflow\Exception\InvalidTokenConfigurationException
* @expectedExceptionMessage No token is set
*/
public function testWithNoTokenStorage()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, there is a token storage but no token

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated!

{
$event = $this->createEvent();
$this->tokenStorage = null;

$this->expectException(\Exception::class);
$this->tokenStorage->setToken(null);

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