1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright (c) 2011-present Mediasift Ltd |
5
|
|
|
* All rights reserved. |
6
|
|
|
* |
7
|
|
|
* Redistribution and use in source and binary forms, with or without |
8
|
|
|
* modification, are permitted provided that the following conditions |
9
|
|
|
* are met: |
10
|
|
|
* |
11
|
|
|
* * Redistributions of source code must retain the above copyright |
12
|
|
|
* notice, this list of conditions and the following disclaimer. |
13
|
|
|
* |
14
|
|
|
* * Redistributions in binary form must reproduce the above copyright |
15
|
|
|
* notice, this list of conditions and the following disclaimer in |
16
|
|
|
* the documentation and/or other materials provided with the |
17
|
|
|
* distribution. |
18
|
|
|
* |
19
|
|
|
* * Neither the names of the copyright holders nor the names of his |
20
|
|
|
* contributors may be used to endorse or promote products derived |
21
|
|
|
* from this software without specific prior written permission. |
22
|
|
|
* |
23
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
24
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
25
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
26
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
27
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
28
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
29
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
30
|
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
31
|
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
32
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
33
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
34
|
|
|
* POSSIBILITY OF SUCH DAMAGE. |
35
|
|
|
* |
36
|
|
|
* @category Libraries |
37
|
|
|
* @package Storyplayer/Stories |
38
|
|
|
* @author Stuart Herbert <[email protected]> |
39
|
|
|
* @copyright 2011-present Mediasift Ltd www.datasift.com |
40
|
|
|
* @license http://www.opensource.org/licenses/bsd-license.php BSD License |
41
|
|
|
* @link http://datasift.github.io/storyplayer |
42
|
|
|
*/ |
43
|
|
|
|
44
|
|
|
namespace Storyplayer\SPv2\Stories; |
45
|
|
|
|
46
|
|
|
use ReflectionObject; |
47
|
|
|
|
48
|
|
|
use DataSift\Storyplayer\PlayerLib\Story; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Base class for reusable test environment setup/teardown instructions |
52
|
|
|
* |
53
|
|
|
* @category Libraries |
54
|
|
|
* @package Storyplayer/Stories |
55
|
|
|
* @author Stuart Herbert <[email protected]> |
56
|
|
|
* @copyright 2011-present Mediasift Ltd www.datasift.com |
57
|
|
|
* @license http://www.opensource.org/licenses/bsd-license.php BSD License |
58
|
|
|
* @link http://datasift.github.io/storyplayer |
59
|
|
|
*/ |
60
|
|
View Code Duplication |
class StoryTemplate |
|
|
|
|
61
|
|
|
{ |
62
|
|
|
protected $story; |
63
|
|
|
|
64
|
|
|
protected $params = array(); |
65
|
|
|
|
66
|
|
|
public function getStory() |
67
|
|
|
{ |
68
|
|
|
return $this->story; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function setStory(Story $story) |
72
|
|
|
{ |
73
|
|
|
$this->story = $story; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function getParams() |
77
|
|
|
{ |
78
|
|
|
return $this->params; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function setParams($params = array()) |
82
|
|
|
{ |
83
|
|
|
$this->params = $params; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Helper methods to keep the Templates API in line with the phases |
88
|
|
|
*/ |
89
|
|
|
|
90
|
|
|
public function hasTestCanRunCheck() |
91
|
|
|
{ |
92
|
|
|
return method_exists($this, 'testCanRunCheck'); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function hasTestSetup() |
96
|
|
|
{ |
97
|
|
|
return method_exists($this, 'testSetup'); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function hasPerPhaseSetup() |
101
|
|
|
{ |
102
|
|
|
return method_exists($this, 'perPhaseSetup'); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function hasPerPhaseTeardown() |
106
|
|
|
{ |
107
|
|
|
return method_exists($this, 'perPhaseTeardown'); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
public function hasDeviceSetup() |
111
|
|
|
{ |
112
|
|
|
return method_exists($this, 'deviceSetup'); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
public function hasDeviceTeardown() |
116
|
|
|
{ |
117
|
|
|
return method_exists($this, 'deviceTeardown'); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
public function hasHints() |
121
|
|
|
{ |
122
|
|
|
return method_exists($this, 'hints'); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
public function hasPreTestPrediction() |
126
|
|
|
{ |
127
|
|
|
return method_exists($this, 'preTestPrediction'); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
public function hasPreTestInspection() |
131
|
|
|
{ |
132
|
|
|
return method_exists($this, 'preTestInspection'); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
public function hasAction() |
136
|
|
|
{ |
137
|
|
|
return method_exists($this, 'action'); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
public function hasPostTestInspection() |
141
|
|
|
{ |
142
|
|
|
return method_exists($this, 'postTestInspection'); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
public function hasTestTeardown() |
146
|
|
|
{ |
147
|
|
|
return method_exists($this, 'testTeardown'); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
public function getTestCanRunCheck() |
151
|
|
|
{ |
152
|
|
|
return array($this, 'testCanRunCheck'); |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
public function getTestSetup() |
156
|
|
|
{ |
157
|
|
|
return array($this, 'testSetup'); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
public function getPerPhaseSetup() |
161
|
|
|
{ |
162
|
|
|
return array($this, 'perPhaseSetup'); |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
public function getPerPhaseTeardown() |
166
|
|
|
{ |
167
|
|
|
return array($this, 'perPhaseTeardown'); |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
public function getDeviceSetup() |
171
|
|
|
{ |
172
|
|
|
return array($this, 'deviceSetup'); |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
public function getDeviceTeardown() |
176
|
|
|
{ |
177
|
|
|
return array($this, 'deviceTeardown'); |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
public function getHints() |
181
|
|
|
{ |
182
|
|
|
return array($this, 'hints'); |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
public function getPreTestPrediction() |
186
|
|
|
{ |
187
|
|
|
return array($this, 'preTestPrediction'); |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
public function getPreTestInspection() |
191
|
|
|
{ |
192
|
|
|
return array($this, 'preTestInspection'); |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
public function getAction() |
196
|
|
|
{ |
197
|
|
|
return array($this, 'action'); |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
public function getPostTestInspection() |
201
|
|
|
{ |
202
|
|
|
return array($this, 'postTestInspection'); |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
public function getTestTeardown() |
206
|
|
|
{ |
207
|
|
|
return array($this, 'testTeardown'); |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
public function getSourceFilename() |
211
|
|
|
{ |
212
|
|
|
$refObj = new ReflectionObject($this); |
213
|
|
|
return $refObj->getFileName(); |
214
|
|
|
} |
215
|
|
|
} |
216
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.