|
15 | 15 | use Symfony\Component\Workflow\Definition; |
16 | 16 | use Symfony\Component\Workflow\Marking; |
17 | 17 | use Symfony\Component\Workflow\Registry; |
| 18 | +use Symfony\Component\Workflow\Transition; |
18 | 19 | use Symfony\Component\Workflow\Workflow; |
19 | 20 |
|
20 | 21 | class WorkflowExtensionTest extends \PHPUnit_Framework_TestCase |
21 | 22 | { |
| 23 | + private $extension; |
| 24 | + |
22 | 25 | protected function setUp() |
23 | 26 | { |
24 | 27 | if (!class_exists(Workflow::class)) { |
25 | 28 | $this->markTestSkipped('The Workflow component is needed to run tests for this extension.'); |
26 | 29 | } |
27 | | - } |
28 | 30 |
|
29 | | - public function testHasMarkedPlace() |
30 | | - { |
31 | | - $definition = new Definition(['ordered', 'waiting_for_payment', 'processed'], []); |
| 31 | + $places = array('ordered', 'waiting_for_payment', 'processed'); |
| 32 | + $transitions = array( |
| 33 | + new Transition('t1', 'ordered', 'waiting_for_payment'), |
| 34 | + new Transition('t2', 'waiting_for_payment', 'processed'), |
| 35 | + ); |
| 36 | + $definition = new Definition($places, $transitions); |
32 | 37 | $workflow = new Workflow($definition); |
33 | 38 |
|
34 | 39 | $registry = new Registry(); |
35 | 40 | $registry->add($workflow, \stdClass::class); |
36 | 41 |
|
37 | | - $extension = new WorkflowExtension($registry); |
| 42 | + $this->extension = new WorkflowExtension($registry); |
| 43 | + } |
| 44 | + |
| 45 | + public function testCanTransition() |
| 46 | + { |
| 47 | + $subject = new \stdClass(); |
| 48 | + $subject->marking = array(); |
| 49 | + |
| 50 | + $this->assertTrue($this->extension->canTransition($subject, 't1')); |
| 51 | + $this->assertFalse($this->extension->canTransition($subject, 't2')); |
| 52 | + } |
| 53 | + |
| 54 | + public function testGetEnabledTransitions() |
| 55 | + { |
| 56 | + $subject = new \stdClass(); |
| 57 | + $subject->marking = array(); |
| 58 | + |
| 59 | + $transitions = $this->extension->getEnabledTransitions($subject); |
38 | 60 |
|
| 61 | + $this->assertCount(1, $transitions); |
| 62 | + $this->assertInstanceOf(Transition::class, $transitions[0]); |
| 63 | + $this->assertSame('t1', $transitions[0]->getName()); |
| 64 | + } |
| 65 | + |
| 66 | + public function testHasMarkedPlace() |
| 67 | + { |
39 | 68 | $subject = new \stdClass(); |
| 69 | + $subject->marking = array(); |
40 | 70 | $subject->marking = array('ordered' => 1, 'waiting_for_payment' => 1); |
41 | 71 |
|
42 | | - $this->assertTrue($extension->hasMarkedPlace($subject, 'ordered')); |
43 | | - $this->assertTrue($extension->hasMarkedPlace($subject, 'waiting_for_payment')); |
44 | | - $this->assertFalse($extension->hasMarkedPlace($subject, 'processed')); |
| 72 | + $this->assertTrue($this->extension->hasMarkedPlace($subject, 'ordered')); |
| 73 | + $this->assertTrue($this->extension->hasMarkedPlace($subject, 'waiting_for_payment')); |
| 74 | + $this->assertFalse($this->extension->hasMarkedPlace($subject, 'processed')); |
45 | 75 | } |
46 | 76 | } |
0 commit comments