These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * This file is part of the Global Trading Technologies Ltd workflow-extension-bundle package. |
||
4 | * |
||
5 | * For the full copyright and license information, please view the LICENSE |
||
6 | * file that was distributed with this source code. |
||
7 | * |
||
8 | * (c) fduch <[email protected]> |
||
9 | * @date 08.08.16 |
||
10 | */ |
||
11 | |||
12 | namespace Gtt\Bundle\WorkflowExtensionsBundle\Tests\Actions; |
||
13 | |||
14 | use Gtt\Bundle\WorkflowExtensionsBundle\WorkflowContext; |
||
15 | use Gtt\Bundle\WorkflowExtensionsBundle\WorkflowSubject\SubjectManipulator; |
||
16 | use Gtt\Bundle\WorkflowExtensionsBundle\Actions\TransitionApplier; |
||
17 | use PHPUnit_Framework_TestCase; |
||
18 | use Psr\Log\LoggerInterface; |
||
19 | use Symfony\Component\Workflow\Exception\LogicException; |
||
20 | use Symfony\Component\Workflow\Workflow; |
||
21 | |||
22 | class TransitionApplierTest extends PHPUnit_Framework_TestCase |
||
23 | { |
||
24 | /** |
||
25 | * @dataProvider exceptionAndLogLevelProvider |
||
26 | */ |
||
27 | public function testUnavailabilityToPerformTransitionIsReportedByLogger(\Exception $exception, $loggerLevel) |
||
28 | { |
||
29 | $transitionName = "t1"; |
||
30 | $subject = new \StdClass(); |
||
31 | |||
32 | $workflow = $this->getMockBuilder(Workflow::class)->disableOriginalConstructor()->getMock(); |
||
33 | $workflow->expects(self::once())->method('apply')->with($subject, $transitionName)->willThrowException($exception); |
||
34 | |||
35 | $workflowContext = new WorkflowContext($workflow, $subject, "id"); |
||
36 | |||
37 | $logger = $this->getMock(LoggerInterface::class); |
||
38 | $logger->expects(self::once())->method($loggerLevel); |
||
39 | |||
40 | $applier = new TransitionApplier( |
||
41 | $this->getMockBuilder(SubjectManipulator::class)->disableOriginalConstructor()->getMock(), |
||
42 | $logger |
||
43 | ); |
||
44 | |||
45 | $applier->applyTransition($workflowContext, $transitionName); |
||
46 | } |
||
47 | |||
48 | public function exceptionAndLogLevelProvider() |
||
49 | { |
||
50 | return [ |
||
51 | // workflow logic exception should trigger info-level logging |
||
52 | [new LogicException(), "info"], |
||
53 | [new \Exception(), "error"] |
||
54 | ]; |
||
55 | } |
||
56 | |||
57 | /** |
||
58 | * @dataProvider transitionEnvironmentProvider |
||
59 | */ |
||
60 | public function testSeveralTransitionsHandledCorrectly(array $transitions = [], array $appliedTransitions = [], $cascade = false) |
||
61 | { |
||
62 | $workflowName = "w1"; |
||
0 ignored issues
–
show
|
|||
63 | $subject = new \StdClass(); |
||
64 | |||
65 | $workflow = $this->getMockBuilder(Workflow::class)->disableOriginalConstructor()->getMock(); |
||
66 | |||
67 | $appliedTransitionCount = count($appliedTransitions); |
||
68 | |||
69 | $callIndex = 0; |
||
70 | $workflow->expects(self::at($callIndex))->method('getName'); |
||
71 | $callIndex++; |
||
72 | foreach ($appliedTransitions as $transitionName => $applicationResult) { |
||
73 | $invocationMocker = $workflow->expects(self::at($callIndex))->method('apply')->with($subject, $transitionName); |
||
74 | if ($applicationResult instanceof \Exception) { |
||
75 | $invocationMocker->willThrowException($applicationResult); |
||
76 | } |
||
77 | $callIndex++; |
||
78 | } |
||
79 | $workflow->expects($this->exactly($appliedTransitionCount))->method('apply'); |
||
80 | |||
81 | $workflowContext = new WorkflowContext($workflow, $subject, "id"); |
||
82 | |||
83 | $applier = new TransitionApplier( |
||
84 | $this->getMockBuilder(SubjectManipulator::class)->disableOriginalConstructor()->getMock(), |
||
85 | $this->getMock(LoggerInterface::class) |
||
86 | ); |
||
87 | |||
88 | $applier->applyTransitions($workflowContext, $transitions, $cascade); |
||
89 | } |
||
90 | |||
91 | public function transitionEnvironmentProvider() |
||
92 | { |
||
93 | return [ |
||
94 | [['t1', 't2'], ['t1' => true]], |
||
95 | [['t1', 't2'], ['t1' => new \Exception(), 't2' => true], true], |
||
96 | [['t1', 't2'], ['t1' => new \Exception(), 't2' => true], false], |
||
97 | [['t1', 't2'], ['t1' => new LogicException(), 't2' => true], true], |
||
98 | [['t1', 't2'], ['t1' => new LogicException(), 't2' => true], false], |
||
99 | ]; |
||
100 | } |
||
101 | } |
||
102 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.