[Workflow] Remove BC layers and deprecated codes
This commit is contained in:
parent
1177a2aeed
commit
08dc494294
@ -47,22 +47,6 @@ final class Definition
|
||||
$this->metadataStore = $metadataStore ?: new InMemoryMetadataStore();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated since Symfony 4.3. Use the getInitialPlaces() instead.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getInitialPlace()
|
||||
{
|
||||
@trigger_error(sprintf('Calling %s::getInitialPlace() is deprecated. Call %s::getInitialPlaces() instead.', __CLASS__, __CLASS__));
|
||||
|
||||
if (!$this->initialPlaces) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return reset($this->initialPlaces);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
|
@ -135,16 +135,4 @@ class DefinitionBuilder
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated since Symfony 4.1, use the clear() method instead.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function reset()
|
||||
{
|
||||
@trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.1, use the "clear()" method instead.', __METHOD__), E_USER_DEPRECATED);
|
||||
|
||||
return $this->clear();
|
||||
}
|
||||
}
|
||||
|
@ -1,70 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Workflow\DependencyInjection;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
||||
use Symfony\Component\Workflow\Validator\StateMachineValidator;
|
||||
use Symfony\Component\Workflow\Validator\WorkflowValidator;
|
||||
|
||||
/**
|
||||
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
|
||||
*
|
||||
* @deprecated since Symfony 4.3
|
||||
*/
|
||||
class ValidateWorkflowsPass implements CompilerPassInterface
|
||||
{
|
||||
private $definitionTag;
|
||||
|
||||
public function __construct(string $definitionTag = 'workflow.definition')
|
||||
{
|
||||
$this->definitionTag = $definitionTag;
|
||||
}
|
||||
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
$taggedServices = $container->findTaggedServiceIds($this->definitionTag, true);
|
||||
foreach ($taggedServices as $id => $tags) {
|
||||
foreach ($tags as $tag) {
|
||||
if (!\array_key_exists('name', $tag)) {
|
||||
throw new RuntimeException(sprintf('The "name" for the tag "%s" of service "%s" must be set.', $this->definitionTag, $id));
|
||||
}
|
||||
if (!\array_key_exists('type', $tag)) {
|
||||
throw new RuntimeException(sprintf('The "type" for the tag "%s" of service "%s" must be set.', $this->definitionTag, $id));
|
||||
}
|
||||
if (!\array_key_exists('marking_store', $tag)) {
|
||||
throw new RuntimeException(sprintf('The "marking_store" for the tag "%s" of service "%s" must be set.', $this->definitionTag, $id));
|
||||
}
|
||||
|
||||
$this->createValidator($tag)->validate($container->get($id), $tag['name']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function createValidator($tag)
|
||||
{
|
||||
if ('state_machine' === $tag['type']) {
|
||||
return new StateMachineValidator();
|
||||
}
|
||||
|
||||
if ('single_state' === $tag['marking_store']) {
|
||||
return new WorkflowValidator(true);
|
||||
}
|
||||
|
||||
if ('multiple_state' === $tag['marking_store']) {
|
||||
return new WorkflowValidator(false);
|
||||
}
|
||||
|
||||
return new WorkflowValidator($tag['single_state'] ?? false);
|
||||
}
|
||||
}
|
@ -26,30 +26,16 @@ class Event extends BaseEvent
|
||||
private $marking;
|
||||
private $transition;
|
||||
private $workflow;
|
||||
private $workflowName;
|
||||
|
||||
/**
|
||||
* @param object $subject
|
||||
* @param Marking $marking
|
||||
* @param Transition $transition
|
||||
* @param WorkflowInterface $workflow
|
||||
* @param object $subject
|
||||
*/
|
||||
public function __construct($subject, Marking $marking, Transition $transition = null, $workflow = null)
|
||||
public function __construct($subject, Marking $marking, Transition $transition = null, WorkflowInterface $workflow = null)
|
||||
{
|
||||
$this->subject = $subject;
|
||||
$this->marking = $marking;
|
||||
$this->transition = $transition;
|
||||
if (null === $workflow) {
|
||||
@trigger_error(sprintf('Passing only three parameters to "%s" is deprecated since Symfony 4.1. Pass a %s instance as fourth parameter instead.', __METHOD__, WorkflowInterface::class), E_USER_DEPRECATED);
|
||||
$this->workflowName = 'unnamed';
|
||||
} elseif (\is_string($workflow)) {
|
||||
@trigger_error(sprintf('Passing a string as the 4th parameter of "%s()" is deprecated since Symfony 4.1. Pass a %s instance instead.', __METHOD__, WorkflowInterface::class), E_USER_DEPRECATED);
|
||||
$this->workflowName = $workflow;
|
||||
} elseif ($workflow instanceof WorkflowInterface) {
|
||||
$this->workflow = $workflow;
|
||||
} else {
|
||||
throw new \TypeError(sprintf('The 4th parameter of "%s" should be a "%s" instance instead.', __METHOD__, WorkflowInterface::class));
|
||||
}
|
||||
$this->workflow = $workflow;
|
||||
}
|
||||
|
||||
public function getMarking()
|
||||
@ -69,36 +55,16 @@ class Event extends BaseEvent
|
||||
|
||||
public function getWorkflow(): WorkflowInterface
|
||||
{
|
||||
// BC layer
|
||||
if (!$this->workflow instanceof WorkflowInterface) {
|
||||
throw new \RuntimeException(sprintf('The 4th parameter of "%s"::__construct() should be a "%s" instance.', __CLASS__, WorkflowInterface::class));
|
||||
}
|
||||
|
||||
return $this->workflow;
|
||||
}
|
||||
|
||||
public function getWorkflowName()
|
||||
{
|
||||
// BC layer
|
||||
if ($this->workflowName) {
|
||||
return $this->workflowName;
|
||||
}
|
||||
|
||||
// BC layer
|
||||
if (!$this->workflow instanceof WorkflowInterface) {
|
||||
throw new \RuntimeException(sprintf('The 4th parameter of "%s"::__construct() should be a "%s" instance.', __CLASS__, WorkflowInterface::class));
|
||||
}
|
||||
|
||||
return $this->workflow->getName();
|
||||
}
|
||||
|
||||
public function getMetadata(string $key, $subject)
|
||||
{
|
||||
// BC layer
|
||||
if (!$this->workflow instanceof WorkflowInterface) {
|
||||
throw new \RuntimeException(sprintf('The 4th parameter of "%s"::__construct() should be a "%s" instance.', __CLASS__, WorkflowInterface::class));
|
||||
}
|
||||
|
||||
return $this->workflow->getMetadataStore()->getMetadata($key, $subject);
|
||||
}
|
||||
}
|
||||
|
@ -80,17 +80,11 @@ class GuardListener
|
||||
throw new InvalidTokenConfigurationException(sprintf('There are no tokens available for workflow %s.', $event->getWorkflowName()));
|
||||
}
|
||||
|
||||
$roleNames = $token->getRoleNames();
|
||||
|
||||
if (null !== $this->roleHierarchy) {
|
||||
$roleNames = $this->roleHierarchy->getReachableRoleNames($roleNames);
|
||||
}
|
||||
|
||||
$variables = [
|
||||
'token' => $token,
|
||||
'user' => $token->getUser(),
|
||||
'subject' => $event->getSubject(),
|
||||
'role_names' => $roleNames,
|
||||
'role_names' => $this->roleHierarchy->getReachableRoleNames($token->getRoleNames()),
|
||||
// needed for the is_granted expression function
|
||||
'auth_checker' => $this->authorizationChecker,
|
||||
// needed for the is_* expression function
|
||||
|
@ -1,67 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* MultipleStateMarkingStore stores the marking into a property of the
|
||||
* subject.
|
||||
*
|
||||
* 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
|
||||
{
|
||||
private $property;
|
||||
private $propertyAccessor;
|
||||
|
||||
public function __construct(string $property = 'marking', PropertyAccessorInterface $propertyAccessor = null)
|
||||
{
|
||||
$this->property = $property;
|
||||
$this->propertyAccessor = $propertyAccessor ?: PropertyAccess::createPropertyAccessor();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getMarking($subject)
|
||||
{
|
||||
return new Marking($this->propertyAccessor->getValue($subject, $this->property) ?: []);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @param array $context Some context
|
||||
*/
|
||||
public function setMarking($subject, Marking $marking/*, array $context = []*/)
|
||||
{
|
||||
$this->propertyAccessor->setValue($subject, $this->property, $marking->getPlaces());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getProperty()
|
||||
{
|
||||
return $this->property;
|
||||
}
|
||||
}
|
@ -1,72 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* SingleStateMarkingStore stores the marking into a property of the subject.
|
||||
*
|
||||
* 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
|
||||
{
|
||||
private $property;
|
||||
private $propertyAccessor;
|
||||
|
||||
public function __construct(string $property = 'marking', PropertyAccessorInterface $propertyAccessor = null)
|
||||
{
|
||||
$this->property = $property;
|
||||
$this->propertyAccessor = $propertyAccessor ?: PropertyAccess::createPropertyAccessor();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getMarking($subject)
|
||||
{
|
||||
$placeName = $this->propertyAccessor->getValue($subject, $this->property);
|
||||
|
||||
if (!$placeName) {
|
||||
return new Marking();
|
||||
}
|
||||
|
||||
return new Marking([$placeName => 1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @param array $context Some context
|
||||
*/
|
||||
public function setMarking($subject, Marking $marking/*, array $context = []*/)
|
||||
{
|
||||
$this->propertyAccessor->setValue($subject, $this->property, key($marking->getPlaces()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getProperty()
|
||||
{
|
||||
return $this->property;
|
||||
}
|
||||
}
|
@ -23,18 +23,6 @@ class Registry
|
||||
{
|
||||
private $workflows = [];
|
||||
|
||||
/**
|
||||
* @param Workflow $workflow
|
||||
* @param SupportStrategyInterface $supportStrategy
|
||||
*
|
||||
* @deprecated since Symfony 4.1, use addWorkflow() instead
|
||||
*/
|
||||
public function add(Workflow $workflow, $supportStrategy)
|
||||
{
|
||||
@trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.1. Use addWorkflow() instead.', __METHOD__), E_USER_DEPRECATED);
|
||||
$this->workflows[] = [$workflow, $supportStrategy];
|
||||
}
|
||||
|
||||
public function addWorkflow(WorkflowInterface $workflow, WorkflowSupportStrategyInterface $supportStrategy)
|
||||
{
|
||||
$this->workflows[] = [$workflow, $supportStrategy];
|
||||
|
@ -22,6 +22,6 @@ class StateMachine extends Workflow
|
||||
{
|
||||
public function __construct(Definition $definition, MarkingStoreInterface $markingStore = null, EventDispatcherInterface $dispatcher = null, string $name = 'unnamed')
|
||||
{
|
||||
parent::__construct($definition, $markingStore ?: new MethodMarkingStore(true, 'marking'), $dispatcher, $name);
|
||||
parent::__construct($definition, $markingStore ?: new MethodMarkingStore(true), $dispatcher, $name);
|
||||
}
|
||||
}
|
||||
|
@ -1,47 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Workflow\SupportStrategy;
|
||||
|
||||
@trigger_error(sprintf('"%s" is deprecated since Symfony 4.1. Use "%s" instead.', ClassInstanceSupportStrategy::class, InstanceOfSupportStrategy::class), E_USER_DEPRECATED);
|
||||
|
||||
use Symfony\Component\Workflow\Workflow;
|
||||
|
||||
/**
|
||||
* @author Andreas Kleemann <akleemann@inviqa.com>
|
||||
*
|
||||
* @deprecated since Symfony 4.1, use InstanceOfSupportStrategy instead
|
||||
*/
|
||||
final class ClassInstanceSupportStrategy implements SupportStrategyInterface
|
||||
{
|
||||
private $className;
|
||||
|
||||
public function __construct(string $className)
|
||||
{
|
||||
$this->className = $className;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function supports(Workflow $workflow, $subject)
|
||||
{
|
||||
return $subject instanceof $this->className;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getClassName()
|
||||
{
|
||||
return $this->className;
|
||||
}
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Workflow\SupportStrategy;
|
||||
|
||||
use Symfony\Component\Workflow\Workflow;
|
||||
|
||||
/**
|
||||
* @author Andreas Kleemann <akleemann@inviqa.com>
|
||||
*
|
||||
* @deprecated since Symfony 4.1, use WorkflowSupportStrategyInterface instead
|
||||
*/
|
||||
interface SupportStrategyInterface
|
||||
{
|
||||
/**
|
||||
* @param Workflow $workflow
|
||||
* @param object $subject
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function supports(Workflow $workflow, $subject);
|
||||
}
|
@ -7,11 +7,12 @@ use Symfony\Component\Security\Core\Authentication\AuthenticationTrustResolverIn
|
||||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
|
||||
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
|
||||
use Symfony\Component\Security\Core\Role\RoleHierarchy;
|
||||
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||
use Symfony\Component\Workflow\Event\GuardEvent;
|
||||
use Symfony\Component\Workflow\EventListener\ExpressionLanguage;
|
||||
use Symfony\Component\Workflow\EventListener\GuardExpression;
|
||||
use Symfony\Component\Workflow\EventListener\GuardListener;
|
||||
use Symfony\Component\Workflow\Event\GuardEvent;
|
||||
use Symfony\Component\Workflow\Marking;
|
||||
use Symfony\Component\Workflow\Tests\Subject;
|
||||
use Symfony\Component\Workflow\Transition;
|
||||
@ -41,7 +42,8 @@ class GuardListenerTest extends TestCase
|
||||
$this->authenticationChecker = $this->getMockBuilder(AuthorizationCheckerInterface::class)->getMock();
|
||||
$trustResolver = $this->getMockBuilder(AuthenticationTrustResolverInterface::class)->getMock();
|
||||
$this->validator = $this->getMockBuilder(ValidatorInterface::class)->getMock();
|
||||
$this->listener = new GuardListener($this->configuration, $expressionLanguage, $tokenStorage, $this->authenticationChecker, $trustResolver, null, $this->validator);
|
||||
$roleHierarchy = new RoleHierarchy([]);
|
||||
$this->listener = new GuardListener($this->configuration, $expressionLanguage, $tokenStorage, $this->authenticationChecker, $trustResolver, $roleHierarchy, $this->validator);
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
|
@ -1,34 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\Workflow\Tests\MarkingStore;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Workflow\Marking;
|
||||
use Symfony\Component\Workflow\MarkingStore\MultipleStateMarkingStore;
|
||||
|
||||
/** @group legacy*/
|
||||
class MultipleStateMarkingStoreTest extends TestCase
|
||||
{
|
||||
public function testGetSetMarking()
|
||||
{
|
||||
$subject = new \stdClass();
|
||||
$subject->myMarks = null;
|
||||
|
||||
$markingStore = new MultipleStateMarkingStore('myMarks');
|
||||
|
||||
$marking = $markingStore->getMarking($subject);
|
||||
|
||||
$this->assertInstanceOf(Marking::class, $marking);
|
||||
$this->assertCount(0, $marking->getPlaces());
|
||||
|
||||
$marking->mark('first_place');
|
||||
|
||||
$markingStore->setMarking($subject, $marking);
|
||||
|
||||
$this->assertSame(['first_place' => 1], $subject->myMarks);
|
||||
|
||||
$marking2 = $markingStore->getMarking($subject);
|
||||
|
||||
$this->assertEquals($marking, $marking2);
|
||||
}
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\Workflow\Tests\MarkingStore;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Workflow\Marking;
|
||||
use Symfony\Component\Workflow\MarkingStore\SingleStateMarkingStore;
|
||||
|
||||
/** @group legacy*/
|
||||
class SingleStateMarkingStoreTest extends TestCase
|
||||
{
|
||||
public function testGetSetMarking()
|
||||
{
|
||||
$subject = new \stdClass();
|
||||
$subject->myMarks = null;
|
||||
|
||||
$markingStore = new SingleStateMarkingStore('myMarks');
|
||||
|
||||
$marking = $markingStore->getMarking($subject);
|
||||
|
||||
$this->assertInstanceOf(Marking::class, $marking);
|
||||
$this->assertCount(0, $marking->getPlaces());
|
||||
|
||||
$marking->mark('first_place');
|
||||
|
||||
$markingStore->setMarking($subject, $marking);
|
||||
|
||||
$this->assertSame('first_place', $subject->myMarks);
|
||||
|
||||
$marking2 = $markingStore->getMarking($subject);
|
||||
|
||||
$this->assertEquals($marking, $marking2);
|
||||
}
|
||||
}
|
@ -29,21 +29,6 @@ class RegistryTest extends TestCase
|
||||
$this->registry = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedDeprecation The "Symfony\Component\Workflow\Registry::add()" method is deprecated since Symfony 4.1. Use addWorkflow() instead.
|
||||
*/
|
||||
public function testAddIsDeprecated()
|
||||
{
|
||||
$registry = new Registry();
|
||||
|
||||
$registry->add($w = new Workflow(new Definition([], []), $this->getMockBuilder(MarkingStoreInterface::class)->getMock(), $this->getMockBuilder(EventDispatcherInterface::class)->getMock(), 'workflow1'), $this->createSupportStrategy(Subject1::class));
|
||||
|
||||
$workflow = $registry->get(new Subject1());
|
||||
$this->assertInstanceOf(Workflow::class, $workflow);
|
||||
$this->assertSame('workflow1', $workflow->getName());
|
||||
}
|
||||
|
||||
public function testGetWithSuccess()
|
||||
{
|
||||
$workflow = $this->registry->get(new Subject1());
|
||||
@ -108,23 +93,6 @@ class RegistryTest extends TestCase
|
||||
$this->assertCount(0, $workflows);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
private function createSupportStrategy($supportedClassName)
|
||||
{
|
||||
$strategy = $this->getMockBuilder(SupportStrategyInterface::class)->getMock();
|
||||
$strategy->expects($this->any())->method('supports')
|
||||
->willReturnCallback(function ($workflow, $subject) use ($supportedClassName) {
|
||||
return $subject instanceof $supportedClassName;
|
||||
});
|
||||
|
||||
return $strategy;
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
private function createWorkflowSupportStrategy($supportedClassName)
|
||||
{
|
||||
$strategy = $this->getMockBuilder(WorkflowSupportStrategyInterface::class)->getMock();
|
||||
|
@ -1,37 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\Workflow\Tests\SupportStrategy;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Workflow\SupportStrategy\ClassInstanceSupportStrategy;
|
||||
use Symfony\Component\Workflow\Workflow;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class ClassInstanceSupportStrategyTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @expectedDeprecation "Symfony\Component\Workflow\SupportStrategy\ClassInstanceSupportStrategy" is deprecated since Symfony 4.1. Use "Symfony\Component\Workflow\SupportStrategy\InstanceOfSupportStrategy" instead.
|
||||
*/
|
||||
public function testSupportsIfClassInstance()
|
||||
{
|
||||
$strategy = new ClassInstanceSupportStrategy('Symfony\Component\Workflow\Tests\SupportStrategy\Subject1');
|
||||
|
||||
$this->assertTrue($strategy->supports($this->createWorkflow(), new Subject1()));
|
||||
}
|
||||
|
||||
public function testSupportsIfNotClassInstance()
|
||||
{
|
||||
$strategy = new ClassInstanceSupportStrategy('Symfony\Component\Workflow\Tests\SupportStrategy\Subject2');
|
||||
|
||||
$this->assertFalse($strategy->supports($this->createWorkflow(), new Subject1()));
|
||||
}
|
||||
|
||||
private function createWorkflow()
|
||||
{
|
||||
return $this->getMockBuilder(Workflow::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
}
|
||||
}
|
@ -12,7 +12,6 @@ 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;
|
||||
use Symfony\Component\Workflow\Workflow;
|
||||
@ -40,7 +39,7 @@ class WorkflowTest extends TestCase
|
||||
public function testGetMarkingWithEmptyDefinition()
|
||||
{
|
||||
$subject = new Subject();
|
||||
$workflow = new Workflow(new Definition([], []), new MultipleStateMarkingStore());
|
||||
$workflow = new Workflow(new Definition([], []), new MethodMarkingStore());
|
||||
|
||||
$workflow->getMarking($subject);
|
||||
}
|
||||
@ -53,7 +52,7 @@ class WorkflowTest extends TestCase
|
||||
{
|
||||
$subject = new Subject();
|
||||
$subject->setMarking(['nope' => 1]);
|
||||
$workflow = new Workflow(new Definition([], []), new MultipleStateMarkingStore());
|
||||
$workflow = new Workflow(new Definition([], []), new MethodMarkingStore());
|
||||
|
||||
$workflow->getMarking($subject);
|
||||
}
|
||||
@ -62,7 +61,7 @@ class WorkflowTest extends TestCase
|
||||
{
|
||||
$definition = $this->createComplexWorkflowDefinition();
|
||||
$subject = new Subject();
|
||||
$workflow = new Workflow($definition, new MultipleStateMarkingStore());
|
||||
$workflow = new Workflow($definition, new MethodMarkingStore());
|
||||
|
||||
$marking = $workflow->getMarking($subject);
|
||||
|
||||
@ -76,7 +75,7 @@ class WorkflowTest extends TestCase
|
||||
$definition = $this->createComplexWorkflowDefinition();
|
||||
$subject = new Subject();
|
||||
$subject->setMarking(['b' => 1, 'c' => 1]);
|
||||
$workflow = new Workflow($definition, new MultipleStateMarkingStore());
|
||||
$workflow = new Workflow($definition, new MethodMarkingStore());
|
||||
|
||||
$marking = $workflow->getMarking($subject);
|
||||
|
||||
@ -89,7 +88,7 @@ class WorkflowTest extends TestCase
|
||||
{
|
||||
$definition = $this->createComplexWorkflowDefinition();
|
||||
$subject = new Subject();
|
||||
$workflow = new Workflow($definition, new MultipleStateMarkingStore());
|
||||
$workflow = new Workflow($definition, new MethodMarkingStore());
|
||||
|
||||
$this->assertFalse($workflow->can($subject, 'foobar'));
|
||||
}
|
||||
@ -98,7 +97,7 @@ class WorkflowTest extends TestCase
|
||||
{
|
||||
$definition = $this->createComplexWorkflowDefinition();
|
||||
$subject = new Subject();
|
||||
$workflow = new Workflow($definition, new MultipleStateMarkingStore());
|
||||
$workflow = new Workflow($definition, new MethodMarkingStore());
|
||||
|
||||
$this->assertTrue($workflow->can($subject, 't1'));
|
||||
$this->assertFalse($workflow->can($subject, 't2'));
|
||||
@ -129,7 +128,7 @@ class WorkflowTest extends TestCase
|
||||
$eventDispatcher->addListener('workflow.workflow_name.guard.t1', function (GuardEvent $event) {
|
||||
$event->setBlocked(true);
|
||||
});
|
||||
$workflow = new Workflow($definition, new MultipleStateMarkingStore(), $eventDispatcher, 'workflow_name');
|
||||
$workflow = new Workflow($definition, new MethodMarkingStore(), $eventDispatcher, 'workflow_name');
|
||||
|
||||
$this->assertFalse($workflow->can($subject, 't1'));
|
||||
}
|
||||
@ -142,7 +141,7 @@ class WorkflowTest extends TestCase
|
||||
$dispatchedEvents = [];
|
||||
$eventDispatcher = new EventDispatcher();
|
||||
|
||||
$workflow = new Workflow($definition, new MultipleStateMarkingStore(), $eventDispatcher, 'workflow_name');
|
||||
$workflow = new Workflow($definition, new MethodMarkingStore(), $eventDispatcher, 'workflow_name');
|
||||
$workflow->apply($subject, 't1');
|
||||
$workflow->apply($subject, 't2');
|
||||
|
||||
@ -161,7 +160,7 @@ class WorkflowTest extends TestCase
|
||||
public function testCanWithSameNameTransition()
|
||||
{
|
||||
$definition = $this->createWorkflowWithSameNameTransition();
|
||||
$workflow = new Workflow($definition, new MultipleStateMarkingStore());
|
||||
$workflow = new Workflow($definition, new MethodMarkingStore());
|
||||
|
||||
$subject = new Subject();
|
||||
$this->assertTrue($workflow->can($subject, 'a_to_bc'));
|
||||
@ -191,7 +190,7 @@ class WorkflowTest extends TestCase
|
||||
{
|
||||
$definition = $this->createComplexWorkflowDefinition();
|
||||
$subject = new Subject();
|
||||
$workflow = new Workflow($definition, new MultipleStateMarkingStore());
|
||||
$workflow = new Workflow($definition, new MethodMarkingStore());
|
||||
|
||||
$this->assertTrue($workflow->buildTransitionBlockerList($subject, 't1')->isEmpty());
|
||||
$this->assertFalse($workflow->buildTransitionBlockerList($subject, 't2')->isEmpty());
|
||||
@ -216,7 +215,7 @@ class WorkflowTest extends TestCase
|
||||
{
|
||||
$definition = $this->createComplexWorkflowDefinition();
|
||||
$subject = new Subject();
|
||||
$workflow = new Workflow($definition, new MultipleStateMarkingStore());
|
||||
$workflow = new Workflow($definition, new MethodMarkingStore());
|
||||
|
||||
$transitionBlockerList = $workflow->buildTransitionBlockerList($subject, 't2');
|
||||
$this->assertCount(1, $transitionBlockerList);
|
||||
@ -230,7 +229,7 @@ class WorkflowTest extends TestCase
|
||||
$definition = $this->createSimpleWorkflowDefinition();
|
||||
$subject = new Subject();
|
||||
$dispatcher = new EventDispatcher();
|
||||
$workflow = new Workflow($definition, new MultipleStateMarkingStore(), $dispatcher);
|
||||
$workflow = new Workflow($definition, new MethodMarkingStore(), $dispatcher);
|
||||
|
||||
$dispatcher->addListener('workflow.guard', function (GuardEvent $event) {
|
||||
$event->addTransitionBlocker(new TransitionBlocker('Transition blocker 1', 'blocker_1'));
|
||||
@ -264,7 +263,7 @@ class WorkflowTest extends TestCase
|
||||
{
|
||||
$definition = $this->createComplexWorkflowDefinition();
|
||||
$subject = new Subject();
|
||||
$workflow = new Workflow($definition, new MultipleStateMarkingStore());
|
||||
$workflow = new Workflow($definition, new MethodMarkingStore());
|
||||
|
||||
$workflow->apply($subject, '404 Not Found');
|
||||
}
|
||||
@ -273,7 +272,7 @@ class WorkflowTest extends TestCase
|
||||
{
|
||||
$definition = $this->createComplexWorkflowDefinition();
|
||||
$subject = new Subject();
|
||||
$workflow = new Workflow($definition, new MultipleStateMarkingStore());
|
||||
$workflow = new Workflow($definition, new MethodMarkingStore());
|
||||
|
||||
try {
|
||||
$workflow->apply($subject, 't2');
|
||||
@ -294,7 +293,7 @@ class WorkflowTest extends TestCase
|
||||
{
|
||||
$definition = $this->createComplexWorkflowDefinition();
|
||||
$subject = new Subject();
|
||||
$workflow = new Workflow($definition, new MultipleStateMarkingStore());
|
||||
$workflow = new Workflow($definition, new MethodMarkingStore());
|
||||
|
||||
$marking = $workflow->apply($subject, 't1');
|
||||
|
||||
@ -308,7 +307,7 @@ class WorkflowTest extends TestCase
|
||||
{
|
||||
$subject = new Subject();
|
||||
$definition = $this->createWorkflowWithSameNameTransition();
|
||||
$workflow = new Workflow($definition, new MultipleStateMarkingStore());
|
||||
$workflow = new Workflow($definition, new MethodMarkingStore());
|
||||
|
||||
$marking = $workflow->apply($subject, 'a_to_bc');
|
||||
|
||||
@ -346,7 +345,7 @@ class WorkflowTest extends TestCase
|
||||
$transitions[] = new Transition('t', 'a', 'c');
|
||||
$transitions[] = new Transition('t', 'b', 'd');
|
||||
$definition = new Definition($places, $transitions);
|
||||
$workflow = new Workflow($definition, new MultipleStateMarkingStore());
|
||||
$workflow = new Workflow($definition, new MethodMarkingStore());
|
||||
|
||||
$marking = $workflow->apply($subject, 't');
|
||||
|
||||
@ -367,7 +366,7 @@ class WorkflowTest extends TestCase
|
||||
$transitions[] = new Transition('t', 'b', 'c');
|
||||
$transitions[] = new Transition('t', 'c', 'd');
|
||||
$definition = new Definition($places, $transitions);
|
||||
$workflow = new Workflow($definition, new MultipleStateMarkingStore());
|
||||
$workflow = new Workflow($definition, new MethodMarkingStore());
|
||||
|
||||
$marking = $workflow->apply($subject, 't');
|
||||
// We want to make sure we do not end up in "d"
|
||||
@ -380,7 +379,7 @@ class WorkflowTest extends TestCase
|
||||
$definition = $this->createComplexWorkflowDefinition();
|
||||
$subject = new Subject();
|
||||
$eventDispatcher = new EventDispatcherMock();
|
||||
$workflow = new Workflow($definition, new MultipleStateMarkingStore(), $eventDispatcher, 'workflow_name');
|
||||
$workflow = new Workflow($definition, new MethodMarkingStore(), $eventDispatcher, 'workflow_name');
|
||||
|
||||
$eventNameExpected = [
|
||||
'workflow.entered',
|
||||
@ -427,7 +426,7 @@ class WorkflowTest extends TestCase
|
||||
|
||||
$subject = new Subject();
|
||||
$eventDispatcher = new EventDispatcherMock();
|
||||
$workflow = new Workflow($definition, new MultipleStateMarkingStore(), $eventDispatcher, 'workflow_name');
|
||||
$workflow = new Workflow($definition, new MethodMarkingStore(), $eventDispatcher, 'workflow_name');
|
||||
|
||||
$eventNameExpected = [
|
||||
'workflow.entered',
|
||||
@ -480,7 +479,7 @@ class WorkflowTest extends TestCase
|
||||
$subject = new Subject();
|
||||
$dispatcher = new EventDispatcher();
|
||||
$name = 'workflow_name';
|
||||
$workflow = new Workflow($definition, new MultipleStateMarkingStore(), $dispatcher, $name);
|
||||
$workflow = new Workflow($definition, new MethodMarkingStore(), $dispatcher, $name);
|
||||
|
||||
$assertWorkflowName = function (Event $event) use ($name) {
|
||||
$this->assertEquals($name, $event->getWorkflowName());
|
||||
@ -511,7 +510,7 @@ class WorkflowTest extends TestCase
|
||||
|
||||
$dispatcher = new EventDispatcher();
|
||||
|
||||
$workflow = new Workflow($definition, new MultipleStateMarkingStore(), $dispatcher, 'test');
|
||||
$workflow = new Workflow($definition, new MethodMarkingStore(), $dispatcher, 'test');
|
||||
|
||||
$assertInitialState = function (Event $event) {
|
||||
$this->assertEquals(new Marking(['a' => 1, 'b' => 1, 'c' => 1]), $event->getMarking());
|
||||
@ -545,7 +544,7 @@ class WorkflowTest extends TestCase
|
||||
$eventDispatcher->addListener('workflow.workflow_name.guard.t1', function (GuardEvent $event) {
|
||||
$event->setBlocked(true);
|
||||
});
|
||||
$workflow = new Workflow($definition, new MultipleStateMarkingStore(), $eventDispatcher, 'workflow_name');
|
||||
$workflow = new Workflow($definition, new MethodMarkingStore(), $eventDispatcher, 'workflow_name');
|
||||
|
||||
$this->assertEmpty($workflow->getEnabledTransitions($subject));
|
||||
|
||||
@ -565,7 +564,7 @@ class WorkflowTest extends TestCase
|
||||
{
|
||||
$definition = $this->createWorkflowWithSameNameTransition();
|
||||
$subject = new Subject();
|
||||
$workflow = new Workflow($definition, new MultipleStateMarkingStore());
|
||||
$workflow = new Workflow($definition, new MethodMarkingStore());
|
||||
|
||||
$transitions = $workflow->getEnabledTransitions($subject);
|
||||
$this->assertCount(1, $transitions);
|
||||
|
Reference in New Issue
Block a user