@@ -48,7 +48,7 @@ public function testGetMarkingWithEmptyDefinition()
48
48
public function testGetMarkingWithImpossiblePlace ()
49
49
{
50
50
$ subject = new \stdClass ();
51
- $ subject ->marking = array ('nope ' => true );
51
+ $ subject ->marking = array ('nope ' => 1 );
52
52
$ workflow = new Workflow (new Definition (array (), array ()), new MultipleStateMarkingStore ());
53
53
54
54
$ workflow ->getMarking ($ subject );
@@ -83,18 +83,14 @@ public function testGetMarkingWithExistingMarking()
83
83
$ this ->assertTrue ($ marking ->has ('c ' ));
84
84
}
85
85
86
- /**
87
- * @expectedException \Symfony\Component\Workflow\Exception\LogicException
88
- * @expectedExceptionMessage Transition "foobar" does not exist for workflow "unnamed".
89
- */
90
86
public function testCanWithUnexistingTransition ()
91
87
{
92
88
$ definition = $ this ->createComplexWorkflowDefinition ();
93
89
$ subject = new \stdClass ();
94
90
$ subject ->marking = null ;
95
91
$ workflow = new Workflow ($ definition , new MultipleStateMarkingStore ());
96
92
97
- $ workflow ->can ($ subject , 'foobar ' );
93
+ $ this -> assertFalse ( $ workflow ->can ($ subject , 'foobar ' ) );
98
94
}
99
95
100
96
public function testCan ()
@@ -136,6 +132,23 @@ public function testApplyWithImpossibleTransition()
136
132
$ workflow ->apply ($ subject , 't2 ' );
137
133
}
138
134
135
+ public function testCanWithSameNameTransition ()
136
+ {
137
+ $ definition = $ this ->createWorkflowWithSameNameTransition ();
138
+ $ workflow = new Workflow ($ definition , new MultipleStateMarkingStore ());
139
+
140
+ $ subject = new \stdClass ();
141
+ $ subject ->marking = null ;
142
+ $ this ->assertTrue ($ workflow ->can ($ subject , 'a_to_bc ' ));
143
+ $ this ->assertFalse ($ workflow ->can ($ subject , 'b_to_c ' ));
144
+ $ this ->assertFalse ($ workflow ->can ($ subject , 'to_a ' ));
145
+
146
+ $ subject ->marking = array ('b ' => 1 );
147
+ $ this ->assertFalse ($ workflow ->can ($ subject , 'a_to_bc ' ));
148
+ $ this ->assertTrue ($ workflow ->can ($ subject , 'b_to_c ' ));
149
+ $ this ->assertTrue ($ workflow ->can ($ subject , 'to_a ' ));
150
+ }
151
+
139
152
public function testApply ()
140
153
{
141
154
$ definition = $ this ->createComplexWorkflowDefinition ();
@@ -151,6 +164,59 @@ public function testApply()
151
164
$ this ->assertTrue ($ marking ->has ('c ' ));
152
165
}
153
166
167
+ public function testApplyWithSameNameTransition ()
168
+ {
169
+ $ subject = new \stdClass ();
170
+ $ subject ->marking = null ;
171
+ $ definition = $ this ->createWorkflowWithSameNameTransition ();
172
+ $ workflow = new Workflow ($ definition , new MultipleStateMarkingStore ());
173
+
174
+ $ marking = $ workflow ->apply ($ subject , 'a_to_bc ' );
175
+
176
+ $ this ->assertFalse ($ marking ->has ('a ' ));
177
+ $ this ->assertTrue ($ marking ->has ('b ' ));
178
+ $ this ->assertTrue ($ marking ->has ('c ' ));
179
+
180
+ $ marking = $ workflow ->apply ($ subject , 'to_a ' );
181
+
182
+ $ this ->assertTrue ($ marking ->has ('a ' ));
183
+ $ this ->assertFalse ($ marking ->has ('b ' ));
184
+ $ this ->assertFalse ($ marking ->has ('c ' ));
185
+
186
+ $ marking = $ workflow ->apply ($ subject , 'a_to_bc ' );
187
+ $ marking = $ workflow ->apply ($ subject , 'b_to_c ' );
188
+
189
+ $ this ->assertFalse ($ marking ->has ('a ' ));
190
+ $ this ->assertFalse ($ marking ->has ('b ' ));
191
+ $ this ->assertTrue ($ marking ->has ('c ' ));
192
+
193
+ $ marking = $ workflow ->apply ($ subject , 'to_a ' );
194
+
195
+ $ this ->assertTrue ($ marking ->has ('a ' ));
196
+ $ this ->assertFalse ($ marking ->has ('b ' ));
197
+ $ this ->assertFalse ($ marking ->has ('c ' ));
198
+ }
199
+
200
+ public function testApplyWithSameNameTransition2 ()
201
+ {
202
+ $ subject = new \stdClass ();
203
+ $ subject ->marking = array ('a ' => 1 , 'b ' => 1 );
204
+
205
+ $ places = range ('a ' , 'd ' );
206
+ $ transitions = array ();
207
+ $ transitions [] = new Transition ('t ' , 'a ' , 'c ' );
208
+ $ transitions [] = new Transition ('t ' , 'b ' , 'd ' );
209
+ $ definition = new Definition ($ places , $ transitions );
210
+ $ workflow = new Workflow ($ definition , new MultipleStateMarkingStore ());
211
+
212
+ $ marking = $ workflow ->apply ($ subject , 't ' );
213
+
214
+ $ this ->assertFalse ($ marking ->has ('a ' ));
215
+ $ this ->assertFalse ($ marking ->has ('b ' ));
216
+ $ this ->assertTrue ($ marking ->has ('c ' ));
217
+ $ this ->assertTrue ($ marking ->has ('d ' ));
218
+ }
219
+
154
220
public function testApplyWithEventDispatcher ()
155
221
{
156
222
$ definition = $ this ->createComplexWorkflowDefinition ();
@@ -198,17 +264,36 @@ public function testGetEnabledTransitions()
198
264
199
265
$ this ->assertEmpty ($ workflow ->getEnabledTransitions ($ subject ));
200
266
201
- $ subject ->marking = array ('d ' => true );
267
+ $ subject ->marking = array ('d ' => 1 );
202
268
$ transitions = $ workflow ->getEnabledTransitions ($ subject );
203
269
$ this ->assertCount (2 , $ transitions );
204
270
$ this ->assertSame ('t3 ' , $ transitions [0 ]->getName ());
205
271
$ this ->assertSame ('t4 ' , $ transitions [1 ]->getName ());
206
272
207
- $ subject ->marking = array ('c ' => true , 'e ' => true );
273
+ $ subject ->marking = array ('c ' => 1 , 'e ' => 1 );
208
274
$ transitions = $ workflow ->getEnabledTransitions ($ subject );
209
275
$ this ->assertCount (1 , $ transitions );
210
276
$ this ->assertSame ('t5 ' , $ transitions [0 ]->getName ());
211
277
}
278
+
279
+ public function testGetEnabledTransitionsWithSameNameTransition ()
280
+ {
281
+ $ definition = $ this ->createWorkflowWithSameNameTransition ();
282
+ $ subject = new \stdClass ();
283
+ $ subject ->marking = null ;
284
+ $ workflow = new Workflow ($ definition , new MultipleStateMarkingStore ());
285
+
286
+ $ transitions = $ workflow ->getEnabledTransitions ($ subject );
287
+ $ this ->assertCount (1 , $ transitions );
288
+ $ this ->assertSame ('a_to_bc ' , $ transitions [0 ]->getName ());
289
+
290
+ $ subject ->marking = array ('b ' => 1 , 'c ' => 1 );
291
+ $ transitions = $ workflow ->getEnabledTransitions ($ subject );
292
+ $ this ->assertCount (3 , $ transitions );
293
+ $ this ->assertSame ('b_to_c ' , $ transitions [0 ]->getName ());
294
+ $ this ->assertSame ('to_a ' , $ transitions [1 ]->getName ());
295
+ $ this ->assertSame ('to_a ' , $ transitions [2 ]->getName ());
296
+ }
212
297
}
213
298
214
299
class EventDispatcherMock implements \Symfony \Component \EventDispatcher \EventDispatcherInterface
@@ -223,21 +308,27 @@ public function dispatch($eventName, \Symfony\Component\EventDispatcher\Event $e
223
308
public function addListener ($ eventName , $ listener , $ priority = 0 )
224
309
{
225
310
}
311
+
226
312
public function addSubscriber (\Symfony \Component \EventDispatcher \EventSubscriberInterface $ subscriber )
227
313
{
228
314
}
315
+
229
316
public function removeListener ($ eventName , $ listener )
230
317
{
231
318
}
319
+
232
320
public function removeSubscriber (\Symfony \Component \EventDispatcher \EventSubscriberInterface $ subscriber )
233
321
{
234
322
}
323
+
235
324
public function getListeners ($ eventName = null )
236
325
{
237
326
}
327
+
238
328
public function getListenerPriority ($ eventName , $ listener )
239
329
{
240
330
}
331
+
241
332
public function hasListeners ($ eventName = null )
242
333
{
243
334
}
0 commit comments