Completed
Push — master ( 444125...462f30 )
by Alfred
03:14
created

BaseGherkinToDusk::setParser()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
4
namespace GD;
5
6
use Behat\Gherkin\Parser;
7
use Illuminate\Filesystem\Filesystem;
8
use Silly\Edition\Pimple\Application;
9
10
class BaseGherkinToDusk
11
{
12
13
    protected $features_folder = '/tests/features/';
14
15
    protected $source_path = null;
16
17
    protected $context = "domain";
18
19
    protected $path_to_feature = null;
20
21
22
    protected $dusk_test_name;
23
24
    /**
25
     * Conventions
26
     * file should be in tests/features for now
27
     * @var null
28
     */
29
    protected $file_name = null;
30
31
    protected $file_name_and_path = null;
32
33
    protected $destination_folder_root = null;
34
35
    /**
36
     * @var Filesystem
37
     */
38
    protected $filesystem;
39
40
    /**
41
     * @var Parser
42
     */
43
    protected $parser;
44
45
46
    protected $output;
47
48
    /**
49
     * @var Application
50
     */
51
    protected $app;
52
53 51
    public function __construct(Application $app)
54
    {
55 51
        $this->app = $app;
56
57 51
        $this->filesystem = $this->app->getContainer()['filesystem'];
58
59 51
        $this->parser = $this->app->getContainer()['parser'];
60 51
    }
61
62
63
    public function getFileName()
64
    {
65
        return $this->file_name;
66
    }
67
68
    public function setFileName($file_name)
69
    {
70
        $this->file_name = $file_name;
71
        return $this;
72
    }
73
74
    /**
75
     * @return Filesystem
76
     */
77 33
    public function getFilesystem()
78
    {
79 33
        return $this->filesystem;
80
    }
81
82
    /**
83
     * @param null $filesystem
84
     * @return $this
85
     */
86
    public function setFilesystem($filesystem = null)
87
    {
88
89
        if (!$filesystem) {
90
            $filesystem = new Filesystem();
91
        }
92
        $this->filesystem = $filesystem;
93
        return $this;
94
    }
95
96
    /**
97
     * @return null
98
     */
99
    public function getFileNameAndPath()
100
    {
101
        if ($this->file_name_and_path == null) {
102
            $this->setFileNameAndPath();
103
        }
104
        return $this->file_name_and_path;
105
    }
106
107
    /**
108
     * @param null $file_name_and_path
109
     * @return $this
110
     */
111
    public function setFileNameAndPath($file_name_and_path = null)
112
    {
113
        if (!$file_name_and_path) {
114
            $file_name_and_path =
115
                $this->getSourcePath() . $this->features_folder . $this->getFileName();
116
        }
117
118
        $this->file_name_and_path = $file_name_and_path;
119
120
        return $this;
121
    }
122
123
124
125
    /**
126
     * @return null
127
     */
128 39
    public function getSourcePath()
129
    {
130 39
        if ($this->source_path == null) {
131 39
            $this->setSourcePath();
132 26
        }
133 39
        return $this->source_path;
134
    }
135
136
    /**
137
     * @param null $source_path
138
     */
139 39
    public function setSourcePath($source_path = null)
140
    {
141 39
        if (!$source_path) {
142 39
            $source_path = getcwd() . '/tests/features/';
143 26
        }
144
145 39
        $this->source_path = $source_path;
146 39
    }
147
148
    /**
149
     * @return null
150
     */
151 45
    public function getDestinationFolderRoot()
152
    {
153 45
        if (!$this->destination_folder_root) {
154 45
            $this->setDestinationFolderRoot();
155 30
        }
156 45
        return $this->destination_folder_root;
157
    }
158
159
    /**
160
     * @param null $destination_folder_root
161
     */
162 45
    public function setDestinationFolderRoot($destination_folder_root = null)
163
    {
164 45
        if (!$destination_folder_root) {
165 45
            $destination_folder_root = getcwd() . sprintf('/tests/%s', $this->getContextFolder());
166 30
        }
167
168 45
        $this->destination_folder_root = $destination_folder_root;
169 45
    }
170
171
    /**
172
     * @return string
173
     */
174
    public function getContext()
175
    {
176
        return $this->context;
177
    }
178
179
    /**
180
     * @param string $context
181
     * @return $this
182
     */
183 39
    public function setContext($context)
184
    {
185 39
        $this->context = $context;
186 39
        return $this;
187
    }
188
189
    /**
190
     * @return Parser
191
     */
192 30
    public function getParser()
193
    {
194 30
        return $this->parser;
195
    }
196
197
    /**
198
     * @param Parser $parser
199
     */
200
    public function setParser($parser)
201
    {
202
        $this->parser = $parser;
203
    }
204
205
    
206
    /**
207
     * @return null
208
     */
209 33
    public function getPathToFeature()
210
    {
211 33
        return $this->path_to_feature;
212
    }
213
214
    /**
215
     * @param null $path_to_feature
216
     * @return $this
217
     */
218 33
    public function setPathToFeature($path_to_feature)
219
    {
220 33
        $this->path_to_feature = $path_to_feature;
221 33
        return $this;
222
    }
223
224 33
    public function fullPathToDestinationFile()
225
    {
226 33
        return $this->getDestinationFolderRoot() . '/' . $this->getDuskTestName() . '.php';
227
    }
228
229
230 33
    protected function buildDuskTestName()
231
    {
232 33
        if (!$this->dusk_test_name) {
233 33
            $name = $this->getFilesystem()->name($this->getFullPathToFileAndFileName());
234 33
            $this->dusk_test_name = ucfirst(camel_case($name) . 'Test');
235 22
        }
236 33
    }
237
238 33
    protected function getFullPathToFileAndFileName()
239
    {
240 33
        return getcwd() . DIRECTORY_SEPARATOR . $this->getPathToFeature();
241
    }
242
243
    /**
244
     * @return mixed
245
     */
246 33
    public function getDuskTestName()
247
    {
248 33
        return $this->dusk_test_name;
249
    }
250
251
    /**
252
     * @param mixed $dusk_test_name
253
     */
254
    public function setDuskTestName($dusk_test_name)
255
    {
256
        $this->dusk_test_name = $dusk_test_name;
257
    }
258
    
259 45
    private function getContextFolder()
260
    {
261 45
        switch ($this->context) {
262 45
            case "domain":
263 36
                return "Unit";
264 9
            case "ui":
265 9
            case "browser":
266 9
                return "Browser";
267
            default:
268
                return "Unit";
269
        }
270
    }
271
}
272