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

Skip to content

Commit 2ebc71a

Browse files
author
GDIBass
committed
Created new Exception to throw and modified tests
1 parent 3a8b2ed commit 2ebc71a

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

src/Symfony/Component/Workflow/EventListener/GuardListener.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
1717
use Symfony\Component\Security\Core\Role\RoleHierarchyInterface;
1818
use Symfony\Component\Workflow\Event\GuardEvent;
19+
use Symfony\Component\Workflow\Exception\InvalidTokenConfigurationException;
1920

2021
/**
2122
* @author Grégoire Pineau <[email protected]>
@@ -56,7 +57,7 @@ private function getVariables(GuardEvent $event)
5657
$token = $this->tokenStorage->getToken();
5758

5859
if (null === $token) {
59-
throw new \Exception('No token is set');
60+
throw new InvalidTokenConfigurationException('No token is set');
6061
}
6162

6263
if (null !== $this->roleHierarchy) {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Workflow\Exception;
13+
14+
/**
15+
* Thrown by GuardListener when there is no token set, but guards are placed on a transition
16+
*
17+
* @author Matt Johnson <[email protected]>
18+
*/
19+
class InvalidTokenConfigurationException extends LogicException implements ExceptionInterface
20+
{
21+
}

src/Symfony/Component/Workflow/Tests/EventListener/GuardListenerTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,14 @@ public function testWithSupportedEventAndAccept()
6969
$this->assertTrue($event->isBlocked());
7070
}
7171

72+
/**
73+
* @expectedException \Symfony\Component\Workflow\Exception\InvalidTokenConfigurationException
74+
* @expectedExceptionMessage No token is set
75+
*/
7276
public function testWithNoTokenStorage()
7377
{
7478
$event = $this->createEvent();
75-
$this->tokenStorage = null;
76-
77-
$this->expectException(\Exception::class);
79+
$this->tokenStorage->setToken(null);
7880

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

0 commit comments

Comments
 (0)