Skip to content

Commit 05a41c4

Browse files
committed
Add test for multiple transitions with the same name
Also fixed the existing tests since there were errors that prevent the tests from running.
1 parent 14760cf commit 05a41c4

File tree

3 files changed

+51
-3
lines changed

3 files changed

+51
-3
lines changed

tests/WorkflowDumpCommandTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Mockery;
66
use PHPUnit\Framework\TestCase;
77

8-
class WorkflowRegistryTest extends TestCase
8+
class WorkflowDumpCommandTest extends TestCase
99
{
1010
public function testWorkflowCommand()
1111
{

tests/WorkflowRegistryTest.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,50 @@ public function testIfStateMachineIsRegistered()
7979
$this->assertTrue($workflow instanceof StateMachine);
8080
$this->assertTrue($markingStore instanceof MultipleStateMarkingStore);
8181
}
82+
83+
public function testIfTransitionsWithSameNameCanBothBeUsed()
84+
{
85+
$config = [
86+
'straight' => [
87+
'type' => 'state_machine',
88+
'supports' => ['Tests\Fixtures\TestObject'],
89+
'places' => ['a', 'b', 'c'],
90+
'transitions' => [
91+
[
92+
'name' => 't1',
93+
'from' => 'a',
94+
'to' => 'b',
95+
],
96+
[
97+
'name' => 't1',
98+
'from' => 'c',
99+
'to' => 'b',
100+
],
101+
[
102+
'name' => 't2',
103+
'from' => 'b',
104+
'to' => 'c',
105+
]
106+
],
107+
]
108+
];
109+
110+
$registry = new WorkflowRegistry($config);
111+
$subject = new TestObject;
112+
$workflow = $registry->get($subject);
113+
114+
$markingStoreProp = new ReflectionProperty(Workflow::class, 'markingStore');
115+
$markingStoreProp->setAccessible(true);
116+
117+
$markingStore = $markingStoreProp->getValue($workflow);
118+
119+
$this->assertTrue($workflow instanceof StateMachine);
120+
$this->assertTrue($markingStore instanceof SingleStateMarkingStore);
121+
$this->assertTrue($workflow->can($subject, 't1'));
122+
123+
$workflow->apply($subject, 't1');
124+
$workflow->apply($subject, 't2');
125+
126+
$this->assertTrue($workflow->can($subject, 't1'));
127+
}
82128
}

tests/WorkflowSubscriberTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
use Tests\Fixtures\TestObject;
77
use Illuminate\Support\Facades\Event;
88

9-
class WorkflowRegistryTest extends TestCase
9+
class WorkflowSubscriberTest extends TestCase
1010
{
11-
public function testIfWorkflowIsRegisrter()
11+
public function testIfWorkflowEmitsEvents()
1212
{
1313
global $events;
1414

15+
$events = [];
16+
1517
$config = [
1618
'straight' => [
1719
'supports' => ['Tests\Fixtures\TestObject'],

0 commit comments

Comments
 (0)