it_destroys_a_pipeline()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 1
eloc 4
nc 1
nop 2
1
<?php
2
3
namespace spec\Cerbero\Workflow\Repositories;
4
5
use PhpSpec\ObjectBehavior;
6
use Prophecy\Argument;
7
use Cerbero\Workflow\Wrappers\YamlParserInterface;
8
use Illuminate\Filesystem\Filesystem;
9
10
class YamlPipelineRepositorySpec extends ObjectBehavior
11
{
12
13
    /**
14
     * @author    Andrea Marco Sartori
15
     * @var        array    $pipeline    Example of pipeline.
16
     */
17
    private $pipeline = array('RegisterUser' => ['Notifier', 'Logger']);
18
19
	function let(YamlParserInterface $parser, Filesystem $files)
20
	{
21
		$this->beConstructedWith($parser, $files, 'path/to/workflows');
22
23
		$parser->parse('path/to/workflows/workflows.yml')->shouldBeCalled()->willReturn($this->pipeline);
24
	}
25
26
    function it_is_initializable()
27
    {
28
        $this->shouldHaveType('Cerbero\Workflow\Repositories\YamlPipelineRepository');
29
        $this->shouldHaveType('Cerbero\Workflow\Repositories\PipelineRepositoryInterface');
30
    }
31
32
    /**
33
     * @testdox	It returns false when a pipeline does not exist.
34
     *
35
     * @author	Andrea Marco Sartori
36
     * @return	void
37
     */
38
    public function it_returns_false_when_a_pipeline_does_not_exist()
39
    {
40
    	$this->exists('unknownPipeline')->shouldReturn(false);
41
    }
42
43
    /**
44
     * @testdox	It returns true when a pipeline exists.
45
     *
46
     * @author	Andrea Marco Sartori
47
     * @return	void
48
     */
49
    public function it_returns_true_when_a_pipeline_exists()
50
    {
51
    	$this->exists('RegisterUser')->shouldReturn(true);
52
    }
53
54
    /**
55
     * @testdox	It returns the pipeline of a fiven workflow.
56
     *
57
     * @author	Andrea Marco Sartori
58
     * @return	void
59
     */
60
    public function it_returns_the_pipeline_of_a_fiven_workflow()
61
    {
62
    	$expected = ['Notifier', 'Logger'];
63
64
    	$this->getPipesByPipeline('registerUser')->shouldReturn($expected);
65
    }
66
67
    /**
68
     * @testdox    It retrieves the source of the pipelines.
69
     *
70
     * @author    Andrea Marco Sartori
71
     * @return    void
72
     */
73
    public function it_retrieves_the_source_of_the_pipelines()
74
    {
75
        $this->getSource()->shouldReturn('path/to/workflows/workflows.yml');
76
    }
77
78
    /**
79
     * @testdox    It creates the YAML file.
80
     *
81
     * @author    Andrea Marco Sartori
82
     * @return    void
83
     */
84
    public function it_creates_the_YAML_file($files)
85
    {
86
        $files->makeDirectory('path/to/workflows', 0755, true, true)->shouldBeCalled();
87
88
        $files->put('path/to/workflows/workflows.yml', '')->shouldBeCalled();
89
90
        $this->settle();
91
    }
92
93
    /**
94
     * @testdox    It stores the given pipeline and its pipes.
95
     *
96
     * @author    Andrea Marco Sartori
97
     * @return    void
98
     */
99
    public function it_stores_the_given_pipeline_and_its_pipes($parser, $files)
100
    {
101
        $parser->dump($this->pipeline)->willReturn('foo');
102
103
        $files->append('path/to/workflows/workflows.yml', 'foo')->shouldBeCalled();
104
105
        $this->store('RegisterUser', ['Notifier', 'Logger']);
106
    }
107
108
    /**
109
     * @testdox    It updates an existing pipeline by attaching and detaching pipes.
110
     *
111
     * @author    Andrea Marco Sartori
112
     * @return    void
113
     */
114
    public function it_updates_an_existing_pipeline_by_attaching_and_detaching_pipes($parser, $files)
115
    {
116
        $updated = ['RegisterUser' => ['Logger', 'Buzzer']];
117
118
        $parser->dump($updated)->willReturn('foo');
119
120
        $files->put('path/to/workflows/workflows.yml', 'foo')->shouldBeCalled();
121
122
        $this->update('RegisterUser', ['Buzzer'], ['Notifier']);
123
    }
124
125
    /**
126
     * @testdox    It does not attach if no attachments are specified.
127
     *
128
     * @author    Andrea Marco Sartori
129
     * @return    void
130
     */
131
    public function it_does_not_attach_if_no_attachments_are_specified($parser, $files)
132
    {
133
        $updated = ['RegisterUser' => ['Notifier']];
134
135
        $parser->dump($updated)->willReturn('foo');
136
137
        $files->put('path/to/workflows/workflows.yml', 'foo')->shouldBeCalled();
138
139
        $this->update('RegisterUser', [], ['Logger']);
140
    }
141
142
    /**
143
     * @testdox    It does not detach if no detachments are specified.
144
     *
145
     * @author    Andrea Marco Sartori
146
     * @return    void
147
     */
148
    public function it_does_not_detach_if_no_detachments_are_specified($parser, $files)
149
    {
150
        $updated = ['RegisterUser' => ['Notifier', 'Logger', 'Buzzer']];
151
152
        $parser->dump($updated)->willReturn('foo');
153
154
        $files->put('path/to/workflows/workflows.yml', 'foo')->shouldBeCalled();
155
156
        $this->update('RegisterUser', ['Buzzer'], []);
157
    }
158
159
    /**
160
     * @testdox    It destroys a pipeline.
161
     *
162
     * @author    Andrea Marco Sartori
163
     * @return    void
164
     */
165
    public function it_destroys_a_pipeline($parser, $files)
166
    {
167
        $parser->dump([])->willReturn('foo');
168
169
        $files->put('path/to/workflows/workflows.yml', 'foo')->shouldBeCalled();
170
171
        $this->destroy('RegisterUser');
172
    }
173
}
174