minor #30551 [Workflow] Deprecate MultipleStateMarkingStore and SingleStateMarkingStore in favor of MethodMarkingStore (lyrixx)
This PR was merged into the 4.3-dev branch.
Discussion
----------
[Workflow] Deprecate MultipleStateMarkingStore and SingleStateMarkingStore in favor of MethodMarkingStore
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | no
| BC breaks? | no
| Deprecations? | yes
| Tests pass? | yes
| Fixed tickets |
| License | MIT
| Doc PR |
Commits
-------
4d58beb7c8
[Workflow] Deprecate MultipleStateMarkingStore and SingleStateMarkingStore in favor of MethodMarkingStore
This commit is contained in:
commit
59f20ad8fd
@ -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
|
||||
```
|
||||
|
@ -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
|
||||
----
|
||||
|
@ -14,6 +14,7 @@ namespace Symfony\Bridge\Twig\Tests\Extension;
|
||||
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 @@ class WorkflowExtensionTest extends TestCase
|
||||
);
|
||||
}
|
||||
$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 @@ class WorkflowExtensionTest extends TestCase
|
||||
|
||||
public function testGetEnabledTransitions()
|
||||
{
|
||||
$subject = new \stdClass();
|
||||
$subject->marking = [];
|
||||
$subject = new Subject();
|
||||
|
||||
$transitions = $this->extension->getEnabledTransitions($subject);
|
||||
|
||||
@ -83,9 +82,7 @@ class WorkflowExtensionTest extends TestCase
|
||||
|
||||
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 @@ class WorkflowExtensionTest extends TestCase
|
||||
|
||||
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 @@ class WorkflowExtensionTest extends TestCase
|
||||
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 @@ class WorkflowExtensionTest extends TestCase
|
||||
$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;
|
||||
}
|
||||
}
|
||||
|
@ -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": "",
|
||||
|
@ -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
|
||||
-----
|
||||
|
@ -19,6 +19,12 @@ use Symfony\Component\Workflow\Marking;
|
||||
*
|
||||
* 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 <lyrixx@lyrixx.info>
|
||||
*/
|
||||
final class MethodMarkingStore implements MarkingStoreInterface
|
||||
|
@ -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 @@ use Symfony\Component\Workflow\Marking;
|
||||
* 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 <lyrixx@lyrixx.info>
|
||||
*/
|
||||
class MultipleStateMarkingStore implements MarkingStoreInterface
|
||||
|
@ -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 @@ use Symfony\Component\Workflow\Marking;
|
||||
* 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 <lyrixx@lyrixx.info>
|
||||
*/
|
||||
class SingleStateMarkingStore implements MarkingStoreInterface
|
||||
|
@ -6,7 +6,8 @@ use PHPUnit\Framework\TestCase;
|
||||
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 @@ class AuditTrailListenerTest extends TestCase
|
||||
{
|
||||
$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);
|
||||
|
@ -13,6 +13,7 @@ use Symfony\Component\Workflow\EventListener\ExpressionLanguage;
|
||||
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 @@ class GuardListenerTest extends TestCase
|
||||
|
||||
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)
|
||||
|
@ -5,6 +5,7 @@ namespace Symfony\Component\Workflow\Tests\MarkingStore;
|
||||
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 @@ class MethodMarkingStoreTest extends TestCase
|
||||
$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;
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Workflow\Marking;
|
||||
use Symfony\Component\Workflow\MarkingStore\MultipleStateMarkingStore;
|
||||
|
||||
/** @group legacy*/
|
||||
class MultipleStateMarkingStoreTest extends TestCase
|
||||
{
|
||||
public function testGetSetMarking()
|
||||
|
@ -6,6 +6,7 @@ use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Workflow\Marking;
|
||||
use Symfony\Component\Workflow\MarkingStore\SingleStateMarkingStore;
|
||||
|
||||
/** @group legacy*/
|
||||
class SingleStateMarkingStoreTest extends TestCase
|
||||
{
|
||||
public function testGetSetMarking()
|
||||
|
@ -17,15 +17,15 @@ class StateMachineTest extends TestCase
|
||||
$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 @@ class StateMachineTest extends TestCase
|
||||
$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 @@ class StateMachineTest extends TestCase
|
||||
$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 @@ class StateMachineTest extends TestCase
|
||||
$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 @@ class StateMachineTest extends TestCase
|
||||
$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 @@ class StateMachineTest extends TestCase
|
||||
|
||||
// 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 @@ class StateMachineTest extends TestCase
|
||||
|
||||
// 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);
|
||||
|
23
src/Symfony/Component/Workflow/Tests/Subject.php
Normal file
23
src/Symfony/Component/Workflow/Tests/Subject.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\Workflow\Tests;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
@ -10,6 +10,7 @@ use Symfony\Component\Workflow\Event\GuardEvent;
|
||||
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 @@ class WorkflowTest extends TestCase
|
||||
*/
|
||||
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 @@ class WorkflowTest extends TestCase
|
||||
*/
|
||||
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 @@ class WorkflowTest extends TestCase
|
||||
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 @@ class WorkflowTest extends TestCase
|
||||
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 @@ class WorkflowTest extends TestCase
|
||||
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 @@ class WorkflowTest extends TestCase
|
||||
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 @@ class WorkflowTest extends TestCase
|
||||
public function testCanDoesNotTriggerGuardEventsForNotEnabledTransitions()
|
||||
{
|
||||
$definition = $this->createComplexWorkflowDefinition();
|
||||
$subject = new \stdClass();
|
||||
$subject->marking = null;
|
||||
$subject = new Subject();
|
||||
|
||||
$dispatchedEvents = [];
|
||||
$eventDispatcher = new EventDispatcher();
|
||||
@ -169,13 +162,12 @@ class WorkflowTest extends TestCase
|
||||
$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 @@ class WorkflowTest extends TestCase
|
||||
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 @@ class WorkflowTest extends TestCase
|
||||
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 @@ class WorkflowTest extends TestCase
|
||||
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 @@ class WorkflowTest extends TestCase
|
||||
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 @@ class WorkflowTest extends TestCase
|
||||
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 @@ class WorkflowTest extends TestCase
|
||||
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 @@ class WorkflowTest extends TestCase
|
||||
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 @@ class WorkflowTest extends TestCase
|
||||
|
||||
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 @@ class WorkflowTest extends TestCase
|
||||
|
||||
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 @@ class WorkflowTest extends TestCase
|
||||
|
||||
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 @@ class WorkflowTest extends TestCase
|
||||
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 @@ class WorkflowTest extends TestCase
|
||||
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 @@ class WorkflowTest extends TestCase
|
||||
{
|
||||
$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 @@ class WorkflowTest extends TestCase
|
||||
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 @@ class WorkflowTest extends TestCase
|
||||
|
||||
$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 @@ class WorkflowTest extends TestCase
|
||||
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());
|
||||
|
Reference in New Issue
Block a user