15
15
class StatusObjectTest extends TestCase
16
16
{
17
17
use \Codeception \Specify;
18
-
18
+
19
19
protected function setUp ()
20
20
{
21
21
parent ::setUp ();
22
22
$ this ->src = new WorkflowFileSource ();
23
23
}
24
-
24
+
25
25
public function testStatusCreationSuccess ()
26
26
{
27
27
$ this ->specify ('create a status instance ' , function ()
@@ -74,7 +74,7 @@ public function testUnknownMetadata()
74
74
{
75
75
$ this ->specify ('status creation fails when no id is provided ' , function ()
76
76
{
77
- $ this ->setExpectedException ('raoul2000\workflow\base\WorkflowException ' );
77
+ $ this ->expectException ('raoul2000\workflow\base\WorkflowException ' );
78
78
79
79
$ s = new Status ([
80
80
'id ' => 'draft ' ,
@@ -93,7 +93,7 @@ public function testMissingId()
93
93
{
94
94
$ this ->specify ('status creation fails when no id is provided ' , function ()
95
95
{
96
- $ this ->setExpectedException ('yii\base\InvalidConfigException ' );
96
+ $ this ->expectException ('yii\base\InvalidConfigException ' );
97
97
98
98
new Status ([
99
99
'workflowId ' => 'workflow1 '
@@ -144,15 +144,15 @@ public function testNullWorkflowId()
144
144
]);
145
145
});
146
146
}
147
-
147
+
148
148
public function testCreateWithSourceSuccess ()
149
149
{
150
150
$ this ->specify ('create a status instance with source component ' , function ()
151
151
{
152
152
$ src = Yii::createObject ([
153
153
'class ' => WorkflowFileSource::className ()
154
154
]);
155
-
155
+
156
156
$ start = new Status ([
157
157
'id ' => 'draft ' ,
158
158
'workflowId ' => 'workflow1 ' ,
@@ -168,35 +168,31 @@ public function testCreateWithSourceFails1()
168
168
$ this ->specify ('create a status instance with an invalid source component ' , function ()
169
169
{
170
170
$ src = new \stdClass ();
171
-
172
- $ this ->setExpectedException (
173
- 'yii\base\InvalidConfigException ' ,
174
- 'The "source" property must implement interface raoul2000\workflow\source\IWorkflowSource '
175
- );
171
+
172
+ $ this ->expectException ('yii\base\InvalidConfigException ' );
173
+ $ this ->expectExceptionMessage ('The "source" property must implement interface raoul2000\workflow\source\IWorkflowSource ' );
176
174
$ start = new Status ([
177
175
'id ' => 'draft ' ,
178
176
'workflowId ' => 'workflow1 ' ,
179
177
'source ' => $ src
180
178
]);
181
- });
179
+ });
182
180
}
183
-
181
+
184
182
public function testCreateWithSourceFails2 ()
185
183
{
186
184
$ this ->specify ('create a status instance with an invalid source component ' , function ()
187
185
{
188
- $ this ->setExpectedException (
189
- 'yii\base\InvalidConfigException ' ,
190
- 'The "source" property must implement interface raoul2000\workflow\source\IWorkflowSource '
191
- );
186
+ $ this ->expectException ('yii\base\InvalidConfigException ' );
187
+ $ this ->expectExceptionMessage ('The "source" property must implement interface raoul2000\workflow\source\IWorkflowSource ' );
192
188
new Status ([
193
189
'id ' => 'draft ' ,
194
190
'workflowId ' => 'workflow1 ' ,
195
191
'source ' => ''
196
192
]);
197
193
});
198
- }
199
-
194
+ }
195
+
200
196
public function testStatusAccessorSuccess ()
201
197
{
202
198
$ this ->src ->addWorkflowDefinition ('wid ' , [
@@ -212,71 +208,69 @@ public function testStatusAccessorSuccess()
212
208
]);
213
209
$ w = $ this ->src ->getWorkflow ('wid ' );
214
210
verify_that ($ w != null );
215
-
211
+
216
212
$ this ->specify ('transitions can be obtained through status ' ,function () {
217
-
213
+
218
214
$ status = $ this ->src ->getStatus ('wid/A ' );
219
-
215
+
220
216
expect_that ($ status != null );
221
-
217
+
222
218
$ tr = $ status ->getTransitions ();
223
-
219
+
224
220
expect_that (is_array ($ tr ));
225
221
expect (count ($ tr ))->equals (2 );
226
-
222
+
227
223
$ keys = array_keys ($ tr );
228
-
224
+
229
225
expect ($ keys )->equals (['wid/B ' ,'wid/C ' ]);
230
226
expect_that ( $ tr ['wid/B ' ] instanceof TransitionInterface);
231
227
expect_that ( $ tr ['wid/C ' ] instanceof TransitionInterface);
232
228
});
233
-
229
+
234
230
$ this ->specify ('parent workflow can be obtained through status ' ,function () {
235
-
231
+
236
232
$ status = $ this ->src ->getStatus ('wid/A ' );
237
-
233
+
238
234
expect_that ($ status != null );
239
-
235
+
240
236
$ wrk = $ status ->getWorkflow ();
241
-
237
+
242
238
expect_that ($ wrk != null );
243
239
verify_that ( $ wrk instanceof WorkflowInterface);
244
240
verify ($ wrk ->getId ())->equals ('wid ' );
245
- });
246
- }
247
-
241
+ });
242
+ }
243
+
248
244
public function testStatusAccessorFails ()
249
245
{
250
246
$ st = new Status ([
251
247
'id ' => 'draft ' ,
252
248
'workflowId ' => 'workflow1 '
253
249
]);
254
-
250
+
255
251
$ this ->specify ('Failed to get transitions when no source is configured ' , function () use ($ st )
256
252
{
257
- $ this ->setExpectedException (
258
- 'raoul2000\workflow\base\WorkflowException ' ,
259
- 'no workflow source component available '
260
- );
253
+ $ this ->expectException ('raoul2000\workflow\base\WorkflowException ' );
254
+ $ this ->expectExceptionMessage ('no workflow source component available ' );
261
255
$ st ->getTransitions ();
262
256
});
263
-
257
+
264
258
$ this ->specify ('Failed to get workflow object when no source is configured ' , function () use ($ st )
265
259
{
266
- $ this ->setExpectedException (
267
- 'raoul2000\workflow\base\WorkflowException ' ,
268
- 'no workflow source component available '
269
- );
260
+ $ this ->expectException ('raoul2000\workflow\base\WorkflowException ' );
261
+ $ this ->expectExceptionMessage ('no workflow source component available ' );
270
262
$ st ->getWorkflow ();
271
- });
272
-
263
+ });
264
+
273
265
$ this ->specify ('Failed to call isInitialStatus when no source is configured ' , function () use ($ st )
274
266
{
275
- $ this ->setExpectedException (
276
- 'raoul2000\workflow\base\WorkflowException ' ,
267
+ $ this ->expectException (
268
+ 'raoul2000\workflow\base\WorkflowException '
269
+ );
270
+ $ this ->expectExceptionMessage (
277
271
'no workflow source component available '
278
272
);
279
273
$ st ->getWorkflow ();
280
- });
281
- }
274
+ });
275
+ }
282
276
}
0 commit comments