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

Skip to content

Commit 838548c

Browse files
committed
Finished implementation of TransitionException
1 parent 9fa4f79 commit 838548c

File tree

5 files changed

+26
-37
lines changed

5 files changed

+26
-37
lines changed

src/Symfony/Component/Workflow/Exception/NotEnabledTransitionException.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,20 @@
1212
namespace Symfony\Component\Workflow\Exception;
1313

1414
use Symfony\Component\Workflow\TransitionBlockerList;
15+
use Symfony\Component\Workflow\WorkflowInterface;
1516

1617
/**
1718
* Thrown by Workflow when a not enabled transition is applied on a subject.
1819
*
1920
* @author Grégoire Pineau <[email protected]>
2021
*/
21-
class NotEnabledTransitionException extends LogicException
22+
class NotEnabledTransitionException extends TransitionException
2223
{
2324
private $transitionBlockerList;
2425

25-
public function __construct(string $transitionName, string $workflowName, TransitionBlockerList $transitionBlockerList)
26+
public function __construct($subject, string $transitionName, WorkflowInterface $workflow, TransitionBlockerList $transitionBlockerList)
2627
{
27-
parent::__construct(sprintf('Transition "%s" is not enabled for workflow "%s".', $transitionName, $workflowName));
28+
parent::__construct($subject, $transitionName, $workflow, sprintf('Transition "%s" is not enabled for workflow "%s".', $transitionName, $workflow->getName()));
2829

2930
$this->transitionBlockerList = $transitionBlockerList;
3031
}

src/Symfony/Component/Workflow/Exception/TransitionException.php

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,56 +11,39 @@
1111

1212
namespace Symfony\Component\Workflow\Exception;
1313

14+
use Symfony\Component\Workflow\WorkflowInterface;
15+
1416
/**
1517
* @author Andrew Tch <[email protected]>
18+
* @author Grégoire Pineau <[email protected]>
1619
*/
1720
class TransitionException extends LogicException
1821
{
19-
/**
20-
* @var mixed
21-
*/
2222
private $subject;
23-
24-
/**
25-
* @var string
26-
*/
2723
private $transitionName;
24+
private $workflow;
2825

29-
/**
30-
* @var string
31-
*/
32-
private $workflowName;
33-
34-
public function __construct($subject, $transitionName, $workflowName)
26+
public function __construct($subject, string $transitionName, WorkflowInterface $workflow, string $message)
3527
{
28+
parent::__construct($message);
29+
3630
$this->subject = $subject;
3731
$this->transitionName = $transitionName;
38-
$this->workflowName = $workflowName;
39-
40-
parent::__construct(sprintf('Unable to apply transition "%s" for workflow "%s".', $this->transitionName, $this->workflowName));
32+
$this->workflow = $workflow;
4133
}
4234

43-
/**
44-
* @return mixed
45-
*/
4635
public function getSubject()
4736
{
4837
return $this->subject;
4938
}
5039

51-
/**
52-
* @return string
53-
*/
54-
public function getTransitionName()
40+
public function getTransitionName(): string
5541
{
5642
return $this->transitionName;
5743
}
5844

59-
/**
60-
* @return string
61-
*/
62-
public function getWorkflowName()
45+
public function getWorkflow(): WorkflowInterface
6346
{
64-
return $this->workflowName;
47+
return $this->workflow;
6548
}
6649
}

src/Symfony/Component/Workflow/Exception/UndefinedTransitionException.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,17 @@
1111

1212
namespace Symfony\Component\Workflow\Exception;
1313

14+
use Symfony\Component\Workflow\WorkflowInterface;
15+
1416
/**
1517
* Thrown by Workflow when an undefined transition is applied on a subject.
1618
*
1719
* @author Grégoire Pineau <[email protected]>
1820
*/
19-
class UndefinedTransitionException extends LogicException
21+
class UndefinedTransitionException extends TransitionException
2022
{
21-
public function __construct(string $transitionName, string $workflowName)
23+
public function __construct($subject, string $transitionName, WorkflowInterface $workflow)
2224
{
23-
parent::__construct(sprintf('Transition "%s" is not defined for workflow "%s".', $transitionName, $workflowName));
25+
parent::__construct($subject, $transitionName, $workflow, sprintf('Transition "%s" is not defined for workflow "%s".', $transitionName, $workflow->getName()));
2426
}
2527
}

src/Symfony/Component/Workflow/Tests/WorkflowTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,9 @@ public function testApplyWithNotEnabledTransition()
271271
$this->assertCount(1, $e->getTransitionBlockerList());
272272
$list = iterator_to_array($e->getTransitionBlockerList());
273273
$this->assertSame('The marking does not enable the transition.', $list[0]->getMessage());
274+
$this->assertSame($e->getWorkflow(), $workflow);
275+
$this->assertSame($e->getSubject(), $subject);
276+
$this->assertSame($e->getTransitionName(), 't2');
274277
}
275278
}
276279

src/Symfony/Component/Workflow/Workflow.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public function buildTransitionBlockerList($subject, string $transitionName): Tr
124124
}
125125

126126
if (!$transitionBlockerList) {
127-
throw new UndefinedTransitionException($transitionName, $this->name);
127+
throw new UndefinedTransitionException($subject, $transitionName, $this);
128128
}
129129

130130
return $transitionBlockerList;
@@ -168,11 +168,11 @@ public function apply($subject, $transitionName)
168168
}
169169

170170
if (!$transitionBlockerList) {
171-
throw new UndefinedTransitionException($transitionName, $this->name);
171+
throw new UndefinedTransitionException($subject, $transitionName, $this);
172172
}
173173

174174
if (!$applied) {
175-
throw new NotEnabledTransitionException($transitionName, $this->name, $transitionBlockerList);
175+
throw new NotEnabledTransitionException($subject, $transitionName, $this, $transitionBlockerList);
176176
}
177177

178178
return $marking;

0 commit comments

Comments
 (0)