@@ -48,7 +48,7 @@ public function testGetMarkingWithEmptyDefinition()
4848 public function testGetMarkingWithImpossiblePlace ()
4949 {
5050 $ subject = new \stdClass ();
51- $ subject ->marking = array ('nope ' => true );
51+ $ subject ->marking = array ('nope ' => 1 );
5252 $ workflow = new Workflow (new Definition (array (), array ()), new MultipleStateMarkingStore ());
5353
5454 $ workflow ->getMarking ($ subject );
@@ -83,18 +83,14 @@ public function testGetMarkingWithExistingMarking()
8383 $ this ->assertTrue ($ marking ->has ('c ' ));
8484 }
8585
86- /**
87- * @expectedException \Symfony\Component\Workflow\Exception\LogicException
88- * @expectedExceptionMessage Transition "foobar" does not exist for workflow "unnamed".
89- */
9086 public function testCanWithUnexistingTransition ()
9187 {
9288 $ definition = $ this ->createComplexWorkflowDefinition ();
9389 $ subject = new \stdClass ();
9490 $ subject ->marking = null ;
9591 $ workflow = new Workflow ($ definition , new MultipleStateMarkingStore ());
9692
97- $ workflow ->can ($ subject , 'foobar ' );
93+ $ this -> assertFalse ( $ workflow ->can ($ subject , 'foobar ' ) );
9894 }
9995
10096 public function testCan ()
@@ -136,6 +132,23 @@ public function testApplyWithImpossibleTransition()
136132 $ workflow ->apply ($ subject , 't2 ' );
137133 }
138134
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+
139152 public function testApply ()
140153 {
141154 $ definition = $ this ->createComplexWorkflowDefinition ();
@@ -151,6 +164,59 @@ public function testApply()
151164 $ this ->assertTrue ($ marking ->has ('c ' ));
152165 }
153166
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+
154220 public function testApplyWithEventDispatcher ()
155221 {
156222 $ definition = $ this ->createComplexWorkflowDefinition ();
@@ -198,17 +264,36 @@ public function testGetEnabledTransitions()
198264
199265 $ this ->assertEmpty ($ workflow ->getEnabledTransitions ($ subject ));
200266
201- $ subject ->marking = array ('d ' => true );
267+ $ subject ->marking = array ('d ' => 1 );
202268 $ transitions = $ workflow ->getEnabledTransitions ($ subject );
203269 $ this ->assertCount (2 , $ transitions );
204270 $ this ->assertSame ('t3 ' , $ transitions [0 ]->getName ());
205271 $ this ->assertSame ('t4 ' , $ transitions [1 ]->getName ());
206272
207- $ subject ->marking = array ('c ' => true , 'e ' => true );
273+ $ subject ->marking = array ('c ' => 1 , 'e ' => 1 );
208274 $ transitions = $ workflow ->getEnabledTransitions ($ subject );
209275 $ this ->assertCount (1 , $ transitions );
210276 $ this ->assertSame ('t5 ' , $ transitions [0 ]->getName ());
211277 }
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+ }
212297}
213298
214299class EventDispatcherMock implements \Symfony \Component \EventDispatcher \EventDispatcherInterface
@@ -223,21 +308,27 @@ public function dispatch($eventName, \Symfony\Component\EventDispatcher\Event $e
223308 public function addListener ($ eventName , $ listener , $ priority = 0 )
224309 {
225310 }
311+
226312 public function addSubscriber (\Symfony \Component \EventDispatcher \EventSubscriberInterface $ subscriber )
227313 {
228314 }
315+
229316 public function removeListener ($ eventName , $ listener )
230317 {
231318 }
319+
232320 public function removeSubscriber (\Symfony \Component \EventDispatcher \EventSubscriberInterface $ subscriber )
233321 {
234322 }
323+
235324 public function getListeners ($ eventName = null )
236325 {
237326 }
327+
238328 public function getListenerPriority ($ eventName , $ listener )
239329 {
240330 }
331+
241332 public function hasListeners ($ eventName = null )
242333 {
243334 }
0 commit comments