|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace spec\Cerbero\Workflow; |
|
4
|
|
|
|
|
5
|
|
|
use PhpSpec\ObjectBehavior; |
|
6
|
|
|
use Prophecy\Argument; |
|
7
|
|
|
use Cerbero\Workflow\Repositories\PipelineRepositoryInterface; |
|
8
|
|
|
use Cerbero\Workflow\Inflectors\InflectorInterface; |
|
9
|
|
|
use Illuminate\Contracts\Container\Container; |
|
10
|
|
|
use Cerbero\Workflow\Wrappers\DispatcherInterface; |
|
11
|
|
|
use ArrayAccess; |
|
12
|
|
|
|
|
13
|
|
|
class WorkflowSpec extends ObjectBehavior { |
|
14
|
|
|
|
|
15
|
|
|
public function let( |
|
16
|
|
|
PipelineRepositoryInterface $pipelines, |
|
17
|
|
|
InflectorInterface $inflector, |
|
18
|
|
|
Container $container, |
|
19
|
|
|
DispatcherInterface $dispatcher |
|
20
|
|
|
) { |
|
21
|
|
|
$this->beConstructedWith($pipelines, $inflector, $container, $dispatcher); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
public function it_is_initializable() |
|
25
|
|
|
{ |
|
26
|
|
|
$this->shouldHaveType('Cerbero\Workflow\Workflow'); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @testdox It throws an exception if a workflow does not exist. |
|
31
|
|
|
* |
|
32
|
|
|
* @author Andrea Marco Sartori |
|
33
|
|
|
* @return void |
|
34
|
|
|
*/ |
|
35
|
|
|
public function it_throws_an_exception_if_a_workflow_does_not_exist($pipelines) |
|
36
|
|
|
{ |
|
37
|
|
|
$pipelines->exists('unknownWorkflow')->shouldBeCalled()->willReturn(false); |
|
38
|
|
|
|
|
39
|
|
|
$this->shouldThrow('BadFunctionCallException')->duringUnknownWorkflow(); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @testdox It resolves the proper request if existing. |
|
44
|
|
|
* |
|
45
|
|
|
* @author Andrea Marco Sartori |
|
46
|
|
|
* @return void |
|
47
|
|
|
*/ |
|
48
|
|
|
public function it_resolves_the_proper_request_if_existing($pipelines, $container, Router $router, $inflector, $dispatcher, ExistingRequest $request) |
|
49
|
|
|
{ |
|
50
|
|
|
$pipelines->exists('registerUser')->willReturn(true); |
|
51
|
|
|
|
|
52
|
|
|
$inflector->of('registerUser')->shouldBeCalled(); |
|
53
|
|
|
|
|
54
|
|
|
$inflector->getRequest()->willReturn('spec\Cerbero\Workflow\ExistingRequest'); |
|
55
|
|
|
|
|
56
|
|
|
$container->make('spec\Cerbero\Workflow\ExistingRequest')->shouldBeCalled()->willReturn($request); |
|
57
|
|
|
|
|
58
|
|
|
$container->make('router')->willReturn($router); |
|
59
|
|
|
|
|
60
|
|
|
$router->current()->willReturn($router); |
|
61
|
|
|
|
|
62
|
|
|
$router->parameters()->willReturn(['foo' => 'bar']); |
|
63
|
|
|
|
|
64
|
|
|
$inflector->getJob()->willReturn('job'); |
|
65
|
|
|
|
|
66
|
|
|
$pipelines->getPipesByPipeline('registerUser')->willReturn(['pipe']); |
|
67
|
|
|
|
|
68
|
|
|
$dispatcher->pipeThrough(['pipe'])->willReturn($dispatcher); |
|
69
|
|
|
|
|
70
|
|
|
$dispatcher->dispatchFrom('job', $request, ['foo' => 'bar'])->shouldBeCalled(); |
|
71
|
|
|
|
|
72
|
|
|
$this->registerUser(); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @testdox It dispatches a job through a pipeline from a default request. |
|
77
|
|
|
* |
|
78
|
|
|
* @author Andrea Marco Sartori |
|
79
|
|
|
* @return void |
|
80
|
|
|
*/ |
|
81
|
|
|
public function it_dispatches_a_job_through_a_pipeline_from_a_default_request($pipelines, $container, Router $router, $inflector, $dispatcher, ArrayAccess $request) |
|
82
|
|
|
{ |
|
83
|
|
|
$pipelines->exists('registerUser')->willReturn(true); |
|
84
|
|
|
|
|
85
|
|
|
$inflector->of('registerUser')->shouldBeCalled(); |
|
86
|
|
|
|
|
87
|
|
|
$inflector->getRequest()->willReturn('NotExistingRequest'); |
|
88
|
|
|
|
|
89
|
|
|
$container->make('Illuminate\Http\Request')->shouldBeCalled()->willReturn($request); |
|
90
|
|
|
|
|
91
|
|
|
$container->make('router')->willReturn($router); |
|
92
|
|
|
|
|
93
|
|
|
$router->current()->willReturn($router); |
|
94
|
|
|
|
|
95
|
|
|
$router->parameters()->willReturn(['foo' => 'bar']); |
|
96
|
|
|
|
|
97
|
|
|
$inflector->getJob()->willReturn('job'); |
|
98
|
|
|
|
|
99
|
|
|
$pipelines->getPipesByPipeline('registerUser')->willReturn(['pipe']); |
|
100
|
|
|
|
|
101
|
|
|
$dispatcher->pipeThrough(['pipe'])->willReturn($dispatcher); |
|
102
|
|
|
|
|
103
|
|
|
$dispatcher->dispatchFrom('job', $request, ['foo' => 'bar'])->shouldBeCalled(); |
|
104
|
|
|
|
|
105
|
|
|
$this->registerUser('foo', 'bar'); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
|
|
111
|
|
|
abstract class ExistingRequest implements ArrayAccess {} |
|
112
|
|
|
|
|
113
|
|
|
interface Router { |
|
114
|
|
|
function current(); |
|
115
|
|
|
function parameters(); |
|
116
|
|
|
} |
|
117
|
|
|
|