1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* (c) 2019, Wesley O. Nichols |
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 Wesnick\WorkflowBundle\Tests\Controller; |
13
|
|
|
|
14
|
|
|
use PHPUnit\Framework\TestCase; |
|
|
|
|
15
|
|
|
use Prophecy\Argument; |
|
|
|
|
16
|
|
|
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; |
17
|
|
|
use Symfony\Component\Workflow\MarkingStore\MultipleStateMarkingStore; |
18
|
|
|
use Symfony\Component\Workflow\Registry; |
19
|
|
|
use Symfony\Component\Workflow\Tests\WorkflowBuilderTrait; |
|
|
|
|
20
|
|
|
use Symfony\Component\Workflow\Workflow; |
21
|
|
|
use Wesnick\WorkflowBundle\Controller\DefaultTransitionController; |
22
|
|
|
use Wesnick\WorkflowBundle\Model\WorkflowDTO; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Class DefaultTransitionControllerTest. |
26
|
|
|
*/ |
27
|
|
|
class DefaultTransitionControllerTest extends TestCase |
28
|
|
|
{ |
29
|
|
|
use WorkflowBuilderTrait; |
30
|
|
|
|
31
|
|
|
public function testInvalidSubjectThrowsException() |
32
|
|
|
{ |
33
|
|
|
$definition = $this->createComplexWorkflowDefinition(); |
34
|
|
|
$workflow = new Workflow($definition, new MultipleStateMarkingStore()); |
|
|
|
|
35
|
|
|
|
36
|
|
|
$registry = $this->createRegistry($workflow); |
37
|
|
|
$controller = new DefaultTransitionController($registry->reveal()); |
38
|
|
|
|
39
|
|
|
$this->expectException(BadRequestHttpException::class); |
40
|
|
|
$this->expectExceptionMessage('Expected object for workflow "workflow", got array'); |
41
|
|
|
$controller(new WorkflowDTO(), [], 'workflow', 'transition'); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @dataProvider workflowProvider |
46
|
|
|
*/ |
47
|
|
|
public function test__invoke($workflow, $subject, $transition, bool $success) |
48
|
|
|
{ |
49
|
|
|
$registry = $this->createRegistry($workflow, $success); |
|
|
|
|
50
|
|
|
$controller = new DefaultTransitionController($registry->reveal()); |
51
|
|
|
|
52
|
|
|
if (!$success) { |
53
|
|
|
$this->expectException(BadRequestHttpException::class); |
54
|
|
|
$this->expectExceptionMessage(sprintf('Transition "%s" in Workflow "workflow" is not available.', $transition)); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
$result = $controller(new WorkflowDTO(), $subject, 'workflow', $transition); |
58
|
|
|
|
59
|
|
|
$this->assertSame($subject, $result); |
60
|
|
|
$this->assertFalse($workflow->can($subject, $transition)); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function workflowProvider() |
64
|
|
|
{ |
65
|
|
|
$definition = $this->createComplexWorkflowDefinition(); |
66
|
|
|
$workflow = new Workflow($definition, new MultipleStateMarkingStore()); |
|
|
|
|
67
|
|
|
|
68
|
|
|
$subject = new \stdClass(); |
69
|
|
|
$subject->marking = null; |
70
|
|
|
yield [$workflow, $subject, 't1', true]; |
71
|
|
|
|
72
|
|
|
$subject = new \stdClass(); |
73
|
|
|
$subject->marking = null; |
74
|
|
|
yield [$workflow, $subject, 't2', false]; |
75
|
|
|
|
76
|
|
|
$subject = new \stdClass(); |
77
|
|
|
$subject->marking = ['b' => 1]; |
78
|
|
|
yield [$workflow, $subject, 't1', false]; |
79
|
|
|
|
80
|
|
|
$subject = new \stdClass(); |
81
|
|
|
$subject->marking = ['b' => 1]; |
82
|
|
|
yield [$workflow, $subject, 't2', false]; |
83
|
|
|
|
84
|
|
|
$subject = new \stdClass(); |
85
|
|
|
$subject->marking = ['b' => 1, 'c' => 1]; |
86
|
|
|
yield [$workflow, $subject, 't1', false]; |
87
|
|
|
|
88
|
|
|
$subject = new \stdClass(); |
89
|
|
|
$subject->marking = ['b' => 1, 'c' => 1]; |
90
|
|
|
yield [$workflow, $subject, 't2', true]; |
91
|
|
|
|
92
|
|
|
$subject = new \stdClass(); |
93
|
|
|
$subject->marking = ['f' => 1]; |
94
|
|
|
yield [$workflow, $subject, 't5', false]; |
95
|
|
|
|
96
|
|
|
$subject = new \stdClass(); |
97
|
|
|
$subject->marking = ['f' => 1]; |
98
|
|
|
yield [$workflow, $subject, 't6', true]; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
private function createRegistry(Workflow $workflow) |
102
|
|
|
{ |
103
|
|
|
$registry = $this->prophesize(Registry::class); |
104
|
|
|
$registry->get(Argument::type(\stdClass::class), Argument::type('string')) |
105
|
|
|
->willReturn($workflow) |
106
|
|
|
; |
107
|
|
|
|
108
|
|
|
return $registry; |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths