diff --git a/UPGRADE-4.3.md b/UPGRADE-4.3.md index a45814f09e67..655095a3b8e4 100644 --- a/UPGRADE-4.3.md +++ b/UPGRADE-4.3.md @@ -177,3 +177,46 @@ Workflow } } ``` + + * `MultipleStateMarkingStore` is deprecated. Use `MethodMarkingStore` instead. + + Before: + ```yaml + framework: + workflows: + article: + marking_store: + type: multiple + ``` + + After: + ```yaml + framework: + workflows: + article: + marking_store: + type: method + + ``` + + * `SingleStateMarkingStore` is deprecated. Use `MethodMarkingStore` instead. + + Before: + ```yaml + framework: + workflows: + article: + marking_store: + type: single + ``` + + After: + ```yaml + framework: + workflows: + article: + marking_store: + type: method + arguments: + - true + ``` diff --git a/UPGRADE-5.0.md b/UPGRADE-5.0.md index 16a034a85dc0..a5b2f0849e51 100644 --- a/UPGRADE-5.0.md +++ b/UPGRADE-5.0.md @@ -369,6 +369,8 @@ Workflow * `ClassInstanceSupportStrategy` has been removed, use `InstanceOfSupportStrategy` instead. * `MarkingStoreInterface::setMarking()` has a third argument: `array $context = []`. * Removed support of `initial_place`. Use `initial_places` instead. + * `MultipleStateMarkingStore` has been removed. + * `SingleStateMarkingStore` has been removed. Yaml ---- diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/WorkflowExtensionTest.php b/src/Symfony/Bridge/Twig/Tests/Extension/WorkflowExtensionTest.php index a3e3ca2daec6..32f4e82dad1c 100644 --- a/src/Symfony/Bridge/Twig/Tests/Extension/WorkflowExtensionTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Extension/WorkflowExtensionTest.php @@ -14,6 +14,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Bridge\Twig\Extension\WorkflowExtension; use Symfony\Component\Workflow\Definition; +use Symfony\Component\Workflow\MarkingStore\MethodMarkingStore; use Symfony\Component\Workflow\Metadata\InMemoryMetadataStore; use Symfony\Component\Workflow\Registry; use Symfony\Component\Workflow\SupportStrategy\ClassInstanceSupportStrategy; @@ -49,21 +50,20 @@ protected function setUp() ); } $definition = new Definition($places, $transitions, null, $metadataStore); - $workflow = new Workflow($definition); + $workflow = new Workflow($definition, new MethodMarkingStore()); $registry = new Registry(); $addWorkflow = method_exists($registry, 'addWorkflow') ? 'addWorkflow' : 'add'; $supportStrategy = class_exists(InstanceOfSupportStrategy::class) - ? new InstanceOfSupportStrategy(\stdClass::class) - : new ClassInstanceSupportStrategy(\stdClass::class); + ? new InstanceOfSupportStrategy(Subject::class) + : new ClassInstanceSupportStrategy(Subject::class); $registry->$addWorkflow($workflow, $supportStrategy); $this->extension = new WorkflowExtension($registry); } public function testCanTransition() { - $subject = new \stdClass(); - $subject->marking = []; + $subject = new Subject(); $this->assertTrue($this->extension->canTransition($subject, 't1')); $this->assertFalse($this->extension->canTransition($subject, 't2')); @@ -71,8 +71,7 @@ public function testCanTransition() public function testGetEnabledTransitions() { - $subject = new \stdClass(); - $subject->marking = []; + $subject = new Subject(); $transitions = $this->extension->getEnabledTransitions($subject); @@ -83,9 +82,7 @@ public function testGetEnabledTransitions() public function testHasMarkedPlace() { - $subject = new \stdClass(); - $subject->marking = []; - $subject->marking = ['ordered' => 1, 'waiting_for_payment' => 1]; + $subject = new Subject(['ordered' => 1, 'waiting_for_payment' => 1]); $this->assertTrue($this->extension->hasMarkedPlace($subject, 'ordered')); $this->assertTrue($this->extension->hasMarkedPlace($subject, 'waiting_for_payment')); @@ -94,12 +91,10 @@ public function testHasMarkedPlace() public function testGetMarkedPlaces() { - $subject = new \stdClass(); - $subject->marking = []; - $subject->marking = ['ordered' => 1, 'waiting_for_payment' => 1]; + $subject = new Subject(['ordered' => 1, 'waiting_for_payment' => 1]); $this->assertSame(['ordered', 'waiting_for_payment'], $this->extension->getMarkedPlaces($subject)); - $this->assertSame($subject->marking, $this->extension->getMarkedPlaces($subject, false)); + $this->assertSame($subject->getMarking(), $this->extension->getMarkedPlaces($subject, false)); } public function testGetMetadata() @@ -107,8 +102,7 @@ public function testGetMetadata() if (!class_exists(InMemoryMetadataStore::class)) { $this->markTestSkipped('This test requires symfony/workflow:4.1.'); } - $subject = new \stdClass(); - $subject->marking = []; + $subject = new Subject(); $this->assertSame('workflow title', $this->extension->getMetadata($subject, 'title')); $this->assertSame('ordered title', $this->extension->getMetadata($subject, 'title', 'orderer')); @@ -117,3 +111,23 @@ public function testGetMetadata() $this->assertNull($this->extension->getMetadata($subject, 'not found', $this->t1)); } } + +final class Subject +{ + private $marking; + + public function __construct($marking = null) + { + $this->marking = $marking; + } + + public function getMarking() + { + return $this->marking; + } + + public function setMarking($marking) + { + $this->marking = $marking; + } +} diff --git a/src/Symfony/Bridge/Twig/composer.json b/src/Symfony/Bridge/Twig/composer.json index 2c6e0625d39d..c083ff32f44b 100644 --- a/src/Symfony/Bridge/Twig/composer.json +++ b/src/Symfony/Bridge/Twig/composer.json @@ -41,12 +41,13 @@ "symfony/var-dumper": "~3.4|~4.0", "symfony/expression-language": "~3.4|~4.0", "symfony/web-link": "~3.4|~4.0", - "symfony/workflow": "~3.4|~4.0" + "symfony/workflow": "~4.3" }, "conflict": { "symfony/console": "<3.4", "symfony/form": "<4.3", - "symfony/translation": "<4.2" + "symfony/translation": "<4.2", + "symfony/workflow": "<4.3" }, "suggest": { "symfony/finder": "", diff --git a/src/Symfony/Component/Workflow/CHANGELOG.md b/src/Symfony/Component/Workflow/CHANGELOG.md index 0801deccc711..c3869c042439 100644 --- a/src/Symfony/Component/Workflow/CHANGELOG.md +++ b/src/Symfony/Component/Workflow/CHANGELOG.md @@ -4,7 +4,7 @@ CHANGELOG 4.3.0 ----- - * Trigger `entered` event for subject entering in the Workflow for the first time + * Trigger `entered` event for subject entering in the Workflow for the first time. * Added a context to `Workflow::apply()`. The `MethodMarkingStore` could be used to leverage this feature. * Add style to transitions by declaring metadata: @@ -27,6 +27,8 @@ CHANGELOG * Dispatch `CompletedEvent` on `workflow.completed` * Dispatch `AnnounceEvent` on `workflow.announce` * Added support for many `initialPlaces` + * Deprecated the `MultipleStateMarkingStore` class, use the `MethodMarkingStore` instead. + * Deprecated the `SingleStateMarkingStore` class, use the `MethodMarkingStore` instead. 4.1.0 ----- diff --git a/src/Symfony/Component/Workflow/MarkingStore/MethodMarkingStore.php b/src/Symfony/Component/Workflow/MarkingStore/MethodMarkingStore.php index e51ac0afa914..3e6294b0facf 100644 --- a/src/Symfony/Component/Workflow/MarkingStore/MethodMarkingStore.php +++ b/src/Symfony/Component/Workflow/MarkingStore/MethodMarkingStore.php @@ -19,6 +19,12 @@ * * This store deals with a "single state" or "multiple state" Marking. * + * "single state" Marking means a subject can be in one and only one state at + * the same time. Use it with state machine or specific workflow. + * + * "multiple state" Marking means a subject can be in many states at the same + * time. Use it with workflow. + * * @author Grégoire Pineau */ final class MethodMarkingStore implements MarkingStoreInterface diff --git a/src/Symfony/Component/Workflow/MarkingStore/MultipleStateMarkingStore.php b/src/Symfony/Component/Workflow/MarkingStore/MultipleStateMarkingStore.php index db6b03b30a4b..af37ae313a17 100644 --- a/src/Symfony/Component/Workflow/MarkingStore/MultipleStateMarkingStore.php +++ b/src/Symfony/Component/Workflow/MarkingStore/MultipleStateMarkingStore.php @@ -11,6 +11,8 @@ namespace Symfony\Component\Workflow\MarkingStore; +@trigger_error(sprintf('"%s" is deprecated since Symfony 4.3, use "%s" instead.', MultipleStateMarkingStore::class, MethodMarkingStore::class), E_USER_DEPRECATED); + use Symfony\Component\PropertyAccess\PropertyAccess; use Symfony\Component\PropertyAccess\PropertyAccessorInterface; use Symfony\Component\Workflow\Marking; @@ -22,6 +24,8 @@ * This store deals with a "multiple state" Marking. It means a subject can be * in many states at the same time. * + * @deprecated since Symfony 4.3, use MethodMarkingStore instead. + * * @author Grégoire Pineau */ class MultipleStateMarkingStore implements MarkingStoreInterface diff --git a/src/Symfony/Component/Workflow/MarkingStore/SingleStateMarkingStore.php b/src/Symfony/Component/Workflow/MarkingStore/SingleStateMarkingStore.php index 41da9b49b9ee..eca8a5d2a144 100644 --- a/src/Symfony/Component/Workflow/MarkingStore/SingleStateMarkingStore.php +++ b/src/Symfony/Component/Workflow/MarkingStore/SingleStateMarkingStore.php @@ -11,6 +11,8 @@ namespace Symfony\Component\Workflow\MarkingStore; +@trigger_error(sprintf('"%s" is deprecated since Symfony 4.3, use "%s" instead.', SingleStateMarkingStore::class, MethodMarkingStore::class), E_USER_DEPRECATED); + use Symfony\Component\PropertyAccess\PropertyAccess; use Symfony\Component\PropertyAccess\PropertyAccessorInterface; use Symfony\Component\Workflow\Marking; @@ -21,6 +23,8 @@ * This store deals with a "single state" Marking. It means a subject can be in * one and only one state at the same time. * + * @deprecated since Symfony 4.3, use MethodMarkingStore instead. + * * @author Grégoire Pineau */ class SingleStateMarkingStore implements MarkingStoreInterface diff --git a/src/Symfony/Component/Workflow/Tests/EventListener/AuditTrailListenerTest.php b/src/Symfony/Component/Workflow/Tests/EventListener/AuditTrailListenerTest.php index 8fab0e9ec717..9ebe6f4fb604 100644 --- a/src/Symfony/Component/Workflow/Tests/EventListener/AuditTrailListenerTest.php +++ b/src/Symfony/Component/Workflow/Tests/EventListener/AuditTrailListenerTest.php @@ -6,7 +6,8 @@ use Psr\Log\AbstractLogger; use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\Workflow\EventListener\AuditTrailListener; -use Symfony\Component\Workflow\MarkingStore\MultipleStateMarkingStore; +use Symfony\Component\Workflow\MarkingStore\MethodMarkingStore; +use Symfony\Component\Workflow\Tests\Subject; use Symfony\Component\Workflow\Tests\WorkflowBuilderTrait; use Symfony\Component\Workflow\Workflow; @@ -18,22 +19,21 @@ public function testItWorks() { $definition = $this->createSimpleWorkflowDefinition(); - $object = new \stdClass(); - $object->marking = null; + $object = new Subject(); $logger = new Logger(); $ed = new EventDispatcher(); $ed->addSubscriber(new AuditTrailListener($logger)); - $workflow = new Workflow($definition, new MultipleStateMarkingStore(), $ed); + $workflow = new Workflow($definition, new MethodMarkingStore(), $ed); $workflow->apply($object, 't1'); $expected = [ - 'Leaving "a" for subject of class "stdClass" in workflow "unnamed".', - 'Transition "t1" for subject of class "stdClass" in workflow "unnamed".', - 'Entering "b" for subject of class "stdClass" in workflow "unnamed".', + 'Leaving "a" for subject of class "Symfony\Component\Workflow\Tests\Subject" in workflow "unnamed".', + 'Transition "t1" for subject of class "Symfony\Component\Workflow\Tests\Subject" in workflow "unnamed".', + 'Entering "b" for subject of class "Symfony\Component\Workflow\Tests\Subject" in workflow "unnamed".', ]; $this->assertSame($expected, $logger->logs); diff --git a/src/Symfony/Component/Workflow/Tests/EventListener/GuardListenerTest.php b/src/Symfony/Component/Workflow/Tests/EventListener/GuardListenerTest.php index 6099cf20c8ad..805b62624656 100644 --- a/src/Symfony/Component/Workflow/Tests/EventListener/GuardListenerTest.php +++ b/src/Symfony/Component/Workflow/Tests/EventListener/GuardListenerTest.php @@ -13,6 +13,7 @@ use Symfony\Component\Workflow\EventListener\GuardExpression; use Symfony\Component\Workflow\EventListener\GuardListener; use Symfony\Component\Workflow\Marking; +use Symfony\Component\Workflow\Tests\Subject; use Symfony\Component\Workflow\Transition; use Symfony\Component\Workflow\WorkflowInterface; @@ -130,13 +131,12 @@ public function testGuardExpressionBlocks() private function createEvent(Transition $transition = null) { - $subject = new \stdClass(); - $subject->marking = new Marking(); + $subject = new Subject(); $transition = $transition ?: new Transition('name', 'from', 'to'); $workflow = $this->getMockBuilder(WorkflowInterface::class)->getMock(); - return new GuardEvent($subject, $subject->marking, $transition, $workflow); + return new GuardEvent($subject, new Marking($subject->getMarking() ?? []), $transition, $workflow); } private function configureAuthenticationChecker($isUsed, $granted = true) diff --git a/src/Symfony/Component/Workflow/Tests/MarkingStore/MethodMarkingStoreTest.php b/src/Symfony/Component/Workflow/Tests/MarkingStore/MethodMarkingStoreTest.php index 776f66002d23..7b5c7ffa9139 100644 --- a/src/Symfony/Component/Workflow/Tests/MarkingStore/MethodMarkingStoreTest.php +++ b/src/Symfony/Component/Workflow/Tests/MarkingStore/MethodMarkingStoreTest.php @@ -5,6 +5,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\Workflow\Marking; use Symfony\Component\Workflow\MarkingStore\MethodMarkingStore; +use Symfony\Component\Workflow\Tests\Subject; class MethodMarkingStoreTest extends TestCase { @@ -52,23 +53,3 @@ public function testGetSetMarkingWithSingleState() $this->assertEquals($marking, $marking2); } } - -final class Subject -{ - private $marking; - - public function __construct($marking = null) - { - $this->marking = $marking; - } - - public function getMarking() - { - return $this->marking; - } - - public function setMarking($marking) - { - $this->marking = $marking; - } -} diff --git a/src/Symfony/Component/Workflow/Tests/MarkingStore/MultipleStateMarkingStoreTest.php b/src/Symfony/Component/Workflow/Tests/MarkingStore/MultipleStateMarkingStoreTest.php index 647ae42b4b11..4ca81e1cd75f 100644 --- a/src/Symfony/Component/Workflow/Tests/MarkingStore/MultipleStateMarkingStoreTest.php +++ b/src/Symfony/Component/Workflow/Tests/MarkingStore/MultipleStateMarkingStoreTest.php @@ -6,6 +6,7 @@ use Symfony\Component\Workflow\Marking; use Symfony\Component\Workflow\MarkingStore\MultipleStateMarkingStore; +/** @group legacy*/ class MultipleStateMarkingStoreTest extends TestCase { public function testGetSetMarking() diff --git a/src/Symfony/Component/Workflow/Tests/MarkingStore/SingleStateMarkingStoreTest.php b/src/Symfony/Component/Workflow/Tests/MarkingStore/SingleStateMarkingStoreTest.php index 2e00714d2762..7b640559ffff 100644 --- a/src/Symfony/Component/Workflow/Tests/MarkingStore/SingleStateMarkingStoreTest.php +++ b/src/Symfony/Component/Workflow/Tests/MarkingStore/SingleStateMarkingStoreTest.php @@ -6,6 +6,7 @@ use Symfony\Component\Workflow\Marking; use Symfony\Component\Workflow\MarkingStore\SingleStateMarkingStore; +/** @group legacy*/ class SingleStateMarkingStoreTest extends TestCase { public function testGetSetMarking() diff --git a/src/Symfony/Component/Workflow/Tests/StateMachineTest.php b/src/Symfony/Component/Workflow/Tests/StateMachineTest.php index 7f76c4a70b1e..dd791239c4b7 100644 --- a/src/Symfony/Component/Workflow/Tests/StateMachineTest.php +++ b/src/Symfony/Component/Workflow/Tests/StateMachineTest.php @@ -17,15 +17,15 @@ public function testCan() $definition = $this->createComplexStateMachineDefinition(); $net = new StateMachine($definition); - $subject = new \stdClass(); + $subject = new Subject(); // If you are in place "a" you should be able to apply "t1" - $subject->marking = 'a'; + $subject->setMarking('a'); $this->assertTrue($net->can($subject, 't1')); - $subject->marking = 'd'; + $subject->setMarking('d'); $this->assertTrue($net->can($subject, 't1')); - $subject->marking = 'b'; + $subject->setMarking('b'); $this->assertFalse($net->can($subject, 't1')); } @@ -34,10 +34,10 @@ public function testCanWithMultipleTransition() $definition = $this->createComplexStateMachineDefinition(); $net = new StateMachine($definition); - $subject = new \stdClass(); + $subject = new Subject(); // If you are in place "b" you should be able to apply "t1" and "t2" - $subject->marking = 'b'; + $subject->setMarking('b'); $this->assertTrue($net->can($subject, 't2')); $this->assertTrue($net->can($subject, 't3')); } @@ -47,14 +47,14 @@ public function testBuildTransitionBlockerList() $definition = $this->createComplexStateMachineDefinition(); $net = new StateMachine($definition); - $subject = new \stdClass(); + $subject = new Subject(); - $subject->marking = 'a'; + $subject->setMarking('a'); $this->assertTrue($net->buildTransitionBlockerList($subject, 't1')->isEmpty()); - $subject->marking = 'd'; + $subject->setMarking('d'); $this->assertTrue($net->buildTransitionBlockerList($subject, 't1')->isEmpty()); - $subject->marking = 'b'; + $subject->setMarking('b'); $this->assertFalse($net->buildTransitionBlockerList($subject, 't1')->isEmpty()); } @@ -63,9 +63,9 @@ public function testBuildTransitionBlockerListWithMultipleTransitions() $definition = $this->createComplexStateMachineDefinition(); $net = new StateMachine($definition); - $subject = new \stdClass(); + $subject = new Subject(); - $subject->marking = 'b'; + $subject->setMarking('b'); $this->assertTrue($net->buildTransitionBlockerList($subject, 't2')->isEmpty()); $this->assertTrue($net->buildTransitionBlockerList($subject, 't3')->isEmpty()); } @@ -81,7 +81,7 @@ public function testBuildTransitionBlockerListReturnsExpectedReasonOnBranchMerge $event->addTransitionBlocker(new TransitionBlocker(\sprintf('Transition blocker of place %s', $event->getTransition()->getFroms()[0]), 'blocker')); }); - $subject = new \stdClass(); + $subject = new Subject(); // There may be multiple transitions with the same name. Make sure that transitions // that are not enabled by the marking are evaluated. @@ -89,7 +89,7 @@ public function testBuildTransitionBlockerListReturnsExpectedReasonOnBranchMerge // Test if when you are in place "a"trying transition "t1" then returned // blocker list contains guard blocker instead blockedByMarking - $subject->marking = 'a'; + $subject->setMarking('a'); $transitionBlockerList = $net->buildTransitionBlockerList($subject, 't1'); $this->assertCount(1, $transitionBlockerList); $blockers = iterator_to_array($transitionBlockerList); @@ -99,7 +99,7 @@ public function testBuildTransitionBlockerListReturnsExpectedReasonOnBranchMerge // Test if when you are in place "d" trying transition "t1" then // returned blocker list contains guard blocker instead blockedByMarking - $subject->marking = 'd'; + $subject->setMarking('d'); $transitionBlockerList = $net->buildTransitionBlockerList($subject, 't1'); $this->assertCount(1, $transitionBlockerList); $blockers = iterator_to_array($transitionBlockerList); diff --git a/src/Symfony/Component/Workflow/Tests/Subject.php b/src/Symfony/Component/Workflow/Tests/Subject.php new file mode 100644 index 000000000000..fafb167ee7e4 --- /dev/null +++ b/src/Symfony/Component/Workflow/Tests/Subject.php @@ -0,0 +1,23 @@ +marking = $marking; + } + + public function getMarking() + { + return $this->marking; + } + + public function setMarking($marking) + { + $this->marking = $marking; + } +} diff --git a/src/Symfony/Component/Workflow/Tests/WorkflowTest.php b/src/Symfony/Component/Workflow/Tests/WorkflowTest.php index 62150d2cb732..8762656a4550 100644 --- a/src/Symfony/Component/Workflow/Tests/WorkflowTest.php +++ b/src/Symfony/Component/Workflow/Tests/WorkflowTest.php @@ -10,6 +10,7 @@ use Symfony\Component\Workflow\Exception\NotEnabledTransitionException; use Symfony\Component\Workflow\Marking; use Symfony\Component\Workflow\MarkingStore\MarkingStoreInterface; +use Symfony\Component\Workflow\MarkingStore\MethodMarkingStore; use Symfony\Component\Workflow\MarkingStore\MultipleStateMarkingStore; use Symfony\Component\Workflow\Transition; use Symfony\Component\Workflow\TransitionBlocker; @@ -25,8 +26,7 @@ class WorkflowTest extends TestCase */ public function testGetMarkingWithInvalidStoreReturn() { - $subject = new \stdClass(); - $subject->marking = null; + $subject = new Subject(); $workflow = new Workflow(new Definition([], []), $this->getMockBuilder(MarkingStoreInterface::class)->getMock()); $workflow->getMarking($subject); @@ -38,8 +38,7 @@ public function testGetMarkingWithInvalidStoreReturn() */ public function testGetMarkingWithEmptyDefinition() { - $subject = new \stdClass(); - $subject->marking = null; + $subject = new Subject(); $workflow = new Workflow(new Definition([], []), new MultipleStateMarkingStore()); $workflow->getMarking($subject); @@ -51,8 +50,8 @@ public function testGetMarkingWithEmptyDefinition() */ public function testGetMarkingWithImpossiblePlace() { - $subject = new \stdClass(); - $subject->marking = ['nope' => 1]; + $subject = new Subject(); + $subject->setMarking(['nope' => 1]); $workflow = new Workflow(new Definition([], []), new MultipleStateMarkingStore()); $workflow->getMarking($subject); @@ -61,23 +60,21 @@ public function testGetMarkingWithImpossiblePlace() public function testGetMarkingWithEmptyInitialMarking() { $definition = $this->createComplexWorkflowDefinition(); - $subject = new \stdClass(); - $subject->marking = null; + $subject = new Subject(); $workflow = new Workflow($definition, new MultipleStateMarkingStore()); $marking = $workflow->getMarking($subject); $this->assertInstanceOf(Marking::class, $marking); $this->assertTrue($marking->has('a')); - $this->assertSame(['a' => 1], $subject->marking); + $this->assertSame(['a' => 1], $subject->getMarking()); } public function testGetMarkingWithExistingMarking() { $definition = $this->createComplexWorkflowDefinition(); - $subject = new \stdClass(); - $subject->marking = null; - $subject->marking = ['b' => 1, 'c' => 1]; + $subject = new Subject(); + $subject->setMarking(['b' => 1, 'c' => 1]); $workflow = new Workflow($definition, new MultipleStateMarkingStore()); $marking = $workflow->getMarking($subject); @@ -90,8 +87,7 @@ public function testGetMarkingWithExistingMarking() public function testCanWithUnexistingTransition() { $definition = $this->createComplexWorkflowDefinition(); - $subject = new \stdClass(); - $subject->marking = null; + $subject = new Subject(); $workflow = new Workflow($definition, new MultipleStateMarkingStore()); $this->assertFalse($workflow->can($subject, 'foobar')); @@ -100,26 +96,25 @@ public function testCanWithUnexistingTransition() public function testCan() { $definition = $this->createComplexWorkflowDefinition(); - $subject = new \stdClass(); - $subject->marking = null; + $subject = new Subject(); $workflow = new Workflow($definition, new MultipleStateMarkingStore()); $this->assertTrue($workflow->can($subject, 't1')); $this->assertFalse($workflow->can($subject, 't2')); - $subject->marking = ['b' => 1]; + $subject->setMarking(['b' => 1]); $this->assertFalse($workflow->can($subject, 't1')); // In a workflow net, all "from" places should contain a token to enable // the transition. $this->assertFalse($workflow->can($subject, 't2')); - $subject->marking = ['b' => 1, 'c' => 1]; + $subject->setMarking(['b' => 1, 'c' => 1]); $this->assertFalse($workflow->can($subject, 't1')); $this->assertTrue($workflow->can($subject, 't2')); - $subject->marking = ['f' => 1]; + $subject->setMarking(['f' => 1]); $this->assertFalse($workflow->can($subject, 't5')); $this->assertTrue($workflow->can($subject, 't6')); @@ -128,8 +123,7 @@ public function testCan() public function testCanWithGuard() { $definition = $this->createComplexWorkflowDefinition(); - $subject = new \stdClass(); - $subject->marking = null; + $subject = new Subject(); $eventDispatcher = new EventDispatcher(); $eventDispatcher->addListener('workflow.workflow_name.guard.t1', function (GuardEvent $event) { $event->setBlocked(true); @@ -142,8 +136,7 @@ public function testCanWithGuard() public function testCanDoesNotTriggerGuardEventsForNotEnabledTransitions() { $definition = $this->createComplexWorkflowDefinition(); - $subject = new \stdClass(); - $subject->marking = null; + $subject = new Subject(); $dispatchedEvents = []; $eventDispatcher = new EventDispatcher(); @@ -169,13 +162,12 @@ public function testCanWithSameNameTransition() $definition = $this->createWorkflowWithSameNameTransition(); $workflow = new Workflow($definition, new MultipleStateMarkingStore()); - $subject = new \stdClass(); - $subject->marking = null; + $subject = new Subject(); $this->assertTrue($workflow->can($subject, 'a_to_bc')); $this->assertFalse($workflow->can($subject, 'b_to_c')); $this->assertFalse($workflow->can($subject, 'to_a')); - $subject->marking = ['b' => 1]; + $subject->setMarking(['b' => 1]); $this->assertFalse($workflow->can($subject, 'a_to_bc')); $this->assertTrue($workflow->can($subject, 'b_to_c')); $this->assertTrue($workflow->can($subject, 'to_a')); @@ -188,9 +180,8 @@ public function testCanWithSameNameTransition() public function testBuildTransitionBlockerListReturnsUndefinedTransition() { $definition = $this->createSimpleWorkflowDefinition(); - $subject = new \stdClass(); - $subject->marking = null; - $workflow = new Workflow($definition); + $subject = new Subject(); + $workflow = new Workflow($definition, new MethodMarkingStore()); $workflow->buildTransitionBlockerList($subject, '404 Not Found'); } @@ -198,24 +189,23 @@ public function testBuildTransitionBlockerListReturnsUndefinedTransition() public function testBuildTransitionBlockerList() { $definition = $this->createComplexWorkflowDefinition(); - $subject = new \stdClass(); - $subject->marking = null; + $subject = new Subject(); $workflow = new Workflow($definition, new MultipleStateMarkingStore()); $this->assertTrue($workflow->buildTransitionBlockerList($subject, 't1')->isEmpty()); $this->assertFalse($workflow->buildTransitionBlockerList($subject, 't2')->isEmpty()); - $subject->marking = ['b' => 1]; + $subject->setMarking(['b' => 1]); $this->assertFalse($workflow->buildTransitionBlockerList($subject, 't1')->isEmpty()); $this->assertFalse($workflow->buildTransitionBlockerList($subject, 't2')->isEmpty()); - $subject->marking = ['b' => 1, 'c' => 1]; + $subject->setMarking(['b' => 1, 'c' => 1]); $this->assertFalse($workflow->buildTransitionBlockerList($subject, 't1')->isEmpty()); $this->assertTrue($workflow->buildTransitionBlockerList($subject, 't2')->isEmpty()); - $subject->marking = ['f' => 1]; + $subject->setMarking(['f' => 1]); $this->assertFalse($workflow->buildTransitionBlockerList($subject, 't5')->isEmpty()); $this->assertTrue($workflow->buildTransitionBlockerList($subject, 't6')->isEmpty()); @@ -224,8 +214,7 @@ public function testBuildTransitionBlockerList() public function testBuildTransitionBlockerListReturnsReasonsProvidedByMarking() { $definition = $this->createComplexWorkflowDefinition(); - $subject = new \stdClass(); - $subject->marking = null; + $subject = new Subject(); $workflow = new Workflow($definition, new MultipleStateMarkingStore()); $transitionBlockerList = $workflow->buildTransitionBlockerList($subject, 't2'); @@ -238,8 +227,7 @@ public function testBuildTransitionBlockerListReturnsReasonsProvidedByMarking() public function testBuildTransitionBlockerListReturnsReasonsProvidedInGuards() { $definition = $this->createSimpleWorkflowDefinition(); - $subject = new \stdClass(); - $subject->marking = null; + $subject = new Subject(); $dispatcher = new EventDispatcher(); $workflow = new Workflow($definition, new MultipleStateMarkingStore(), $dispatcher); @@ -274,8 +262,7 @@ public function testBuildTransitionBlockerListReturnsReasonsProvidedInGuards() public function testApplyWithNotExisingTransition() { $definition = $this->createComplexWorkflowDefinition(); - $subject = new \stdClass(); - $subject->marking = null; + $subject = new Subject(); $workflow = new Workflow($definition, new MultipleStateMarkingStore()); $workflow->apply($subject, '404 Not Found'); @@ -284,8 +271,7 @@ public function testApplyWithNotExisingTransition() public function testApplyWithNotEnabledTransition() { $definition = $this->createComplexWorkflowDefinition(); - $subject = new \stdClass(); - $subject->marking = null; + $subject = new Subject(); $workflow = new Workflow($definition, new MultipleStateMarkingStore()); try { @@ -306,8 +292,7 @@ public function testApplyWithNotEnabledTransition() public function testApply() { $definition = $this->createComplexWorkflowDefinition(); - $subject = new \stdClass(); - $subject->marking = null; + $subject = new Subject(); $workflow = new Workflow($definition, new MultipleStateMarkingStore()); $marking = $workflow->apply($subject, 't1'); @@ -320,8 +305,7 @@ public function testApply() public function testApplyWithSameNameTransition() { - $subject = new \stdClass(); - $subject->marking = null; + $subject = new Subject(); $definition = $this->createWorkflowWithSameNameTransition(); $workflow = new Workflow($definition, new MultipleStateMarkingStore()); @@ -353,8 +337,8 @@ public function testApplyWithSameNameTransition() public function testApplyWithSameNameTransition2() { - $subject = new \stdClass(); - $subject->marking = ['a' => 1, 'b' => 1]; + $subject = new Subject(); + $subject->setMarking(['a' => 1, 'b' => 1]); $places = range('a', 'd'); $transitions = []; @@ -373,8 +357,8 @@ public function testApplyWithSameNameTransition2() public function testApplyWithSameNameTransition3() { - $subject = new \stdClass(); - $subject->marking = ['a' => 1]; + $subject = new Subject(); + $subject->setMarking(['a' => 1]); $places = range('a', 'd'); $transitions = []; @@ -393,8 +377,7 @@ public function testApplyWithSameNameTransition3() public function testApplyWithEventDispatcher() { $definition = $this->createComplexWorkflowDefinition(); - $subject = new \stdClass(); - $subject->marking = null; + $subject = new Subject(); $eventDispatcher = new EventDispatcherMock(); $workflow = new Workflow($definition, new MultipleStateMarkingStore(), $eventDispatcher, 'workflow_name'); @@ -438,8 +421,7 @@ public function testApplyWithEventDispatcher() public function testEventName() { $definition = $this->createComplexWorkflowDefinition(); - $subject = new \stdClass(); - $subject->marking = null; + $subject = new Subject(); $dispatcher = new EventDispatcher(); $name = 'workflow_name'; $workflow = new Workflow($definition, new MultipleStateMarkingStore(), $dispatcher, $name); @@ -468,8 +450,8 @@ public function testMarkingStateOnApplyWithEventDispatcher() { $definition = new Definition(range('a', 'f'), [new Transition('t', range('a', 'c'), range('d', 'f'))]); - $subject = new \stdClass(); - $subject->marking = ['a' => 1, 'b' => 1, 'c' => 1]; + $subject = new Subject(); + $subject->setMarking(['a' => 1, 'b' => 1, 'c' => 1]); $dispatcher = new EventDispatcher(); @@ -502,8 +484,7 @@ public function testMarkingStateOnApplyWithEventDispatcher() public function testGetEnabledTransitions() { $definition = $this->createComplexWorkflowDefinition(); - $subject = new \stdClass(); - $subject->marking = null; + $subject = new Subject(); $eventDispatcher = new EventDispatcher(); $eventDispatcher->addListener('workflow.workflow_name.guard.t1', function (GuardEvent $event) { $event->setBlocked(true); @@ -512,13 +493,13 @@ public function testGetEnabledTransitions() $this->assertEmpty($workflow->getEnabledTransitions($subject)); - $subject->marking = ['d' => 1]; + $subject->setMarking(['d' => 1]); $transitions = $workflow->getEnabledTransitions($subject); $this->assertCount(2, $transitions); $this->assertSame('t3', $transitions[0]->getName()); $this->assertSame('t4', $transitions[1]->getName()); - $subject->marking = ['c' => 1, 'e' => 1]; + $subject->setMarking(['c' => 1, 'e' => 1]); $transitions = $workflow->getEnabledTransitions($subject); $this->assertCount(1, $transitions); $this->assertSame('t5', $transitions[0]->getName()); @@ -527,15 +508,14 @@ public function testGetEnabledTransitions() public function testGetEnabledTransitionsWithSameNameTransition() { $definition = $this->createWorkflowWithSameNameTransition(); - $subject = new \stdClass(); - $subject->marking = null; + $subject = new Subject(); $workflow = new Workflow($definition, new MultipleStateMarkingStore()); $transitions = $workflow->getEnabledTransitions($subject); $this->assertCount(1, $transitions); $this->assertSame('a_to_bc', $transitions[0]->getName()); - $subject->marking = ['b' => 1, 'c' => 1]; + $subject->setMarking(['b' => 1, 'c' => 1]); $transitions = $workflow->getEnabledTransitions($subject); $this->assertCount(3, $transitions); $this->assertSame('b_to_c', $transitions[0]->getName());