From 08dc494294c55fcf7d8d43e0b8c5f72393c07e63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Pineau?= Date: Mon, 3 Jun 2019 17:59:18 +0200 Subject: [PATCH 1/2] [Workflow] Remove BC layers and deprecated codes --- src/Symfony/Component/Workflow/Definition.php | 16 ----- .../Component/Workflow/DefinitionBuilder.php | 12 ---- .../ValidateWorkflowsPass.php | 70 ------------------ .../Component/Workflow/Event/Event.php | 40 +---------- .../Workflow/EventListener/GuardListener.php | 8 +-- .../MultipleStateMarkingStore.php | 67 ----------------- .../MarkingStore/SingleStateMarkingStore.php | 72 ------------------- src/Symfony/Component/Workflow/Registry.php | 12 ---- .../Component/Workflow/StateMachine.php | 2 +- .../ClassInstanceSupportStrategy.php | 47 ------------ .../SupportStrategyInterface.php | 30 -------- .../Tests/EventListener/GuardListenerTest.php | 6 +- .../MultipleStateMarkingStoreTest.php | 34 --------- .../SingleStateMarkingStoreTest.php | 34 --------- .../Component/Workflow/Tests/RegistryTest.php | 32 --------- .../ClassInstanceSupportStrategyTest.php | 37 ---------- .../Component/Workflow/Tests/WorkflowTest.php | 49 +++++++------ 17 files changed, 33 insertions(+), 535 deletions(-) delete mode 100644 src/Symfony/Component/Workflow/DependencyInjection/ValidateWorkflowsPass.php delete mode 100644 src/Symfony/Component/Workflow/MarkingStore/MultipleStateMarkingStore.php delete mode 100644 src/Symfony/Component/Workflow/MarkingStore/SingleStateMarkingStore.php delete mode 100644 src/Symfony/Component/Workflow/SupportStrategy/ClassInstanceSupportStrategy.php delete mode 100644 src/Symfony/Component/Workflow/SupportStrategy/SupportStrategyInterface.php delete mode 100644 src/Symfony/Component/Workflow/Tests/MarkingStore/MultipleStateMarkingStoreTest.php delete mode 100644 src/Symfony/Component/Workflow/Tests/MarkingStore/SingleStateMarkingStoreTest.php delete mode 100644 src/Symfony/Component/Workflow/Tests/SupportStrategy/ClassInstanceSupportStrategyTest.php diff --git a/src/Symfony/Component/Workflow/Definition.php b/src/Symfony/Component/Workflow/Definition.php index 1ecbc0dfb5..210e756957 100644 --- a/src/Symfony/Component/Workflow/Definition.php +++ b/src/Symfony/Component/Workflow/Definition.php @@ -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[] */ diff --git a/src/Symfony/Component/Workflow/DefinitionBuilder.php b/src/Symfony/Component/Workflow/DefinitionBuilder.php index 8fa90471dd..d8ca4ea298 100644 --- a/src/Symfony/Component/Workflow/DefinitionBuilder.php +++ b/src/Symfony/Component/Workflow/DefinitionBuilder.php @@ -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(); - } } diff --git a/src/Symfony/Component/Workflow/DependencyInjection/ValidateWorkflowsPass.php b/src/Symfony/Component/Workflow/DependencyInjection/ValidateWorkflowsPass.php deleted file mode 100644 index 3ef4af2580..0000000000 --- a/src/Symfony/Component/Workflow/DependencyInjection/ValidateWorkflowsPass.php +++ /dev/null @@ -1,70 +0,0 @@ - - * - * 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 - * - * @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); - } -} diff --git a/src/Symfony/Component/Workflow/Event/Event.php b/src/Symfony/Component/Workflow/Event/Event.php index c741d7aab7..65b4533c6f 100644 --- a/src/Symfony/Component/Workflow/Event/Event.php +++ b/src/Symfony/Component/Workflow/Event/Event.php @@ -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); } } diff --git a/src/Symfony/Component/Workflow/EventListener/GuardListener.php b/src/Symfony/Component/Workflow/EventListener/GuardListener.php index cb322554ad..25aa67ae1b 100644 --- a/src/Symfony/Component/Workflow/EventListener/GuardListener.php +++ b/src/Symfony/Component/Workflow/EventListener/GuardListener.php @@ -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 diff --git a/src/Symfony/Component/Workflow/MarkingStore/MultipleStateMarkingStore.php b/src/Symfony/Component/Workflow/MarkingStore/MultipleStateMarkingStore.php deleted file mode 100644 index af37ae313a..0000000000 --- a/src/Symfony/Component/Workflow/MarkingStore/MultipleStateMarkingStore.php +++ /dev/null @@ -1,67 +0,0 @@ - - * - * 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 - */ -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; - } -} diff --git a/src/Symfony/Component/Workflow/MarkingStore/SingleStateMarkingStore.php b/src/Symfony/Component/Workflow/MarkingStore/SingleStateMarkingStore.php deleted file mode 100644 index eca8a5d2a1..0000000000 --- a/src/Symfony/Component/Workflow/MarkingStore/SingleStateMarkingStore.php +++ /dev/null @@ -1,72 +0,0 @@ - - * - * 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 - */ -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; - } -} diff --git a/src/Symfony/Component/Workflow/Registry.php b/src/Symfony/Component/Workflow/Registry.php index f1a2df98e6..0711f1663b 100644 --- a/src/Symfony/Component/Workflow/Registry.php +++ b/src/Symfony/Component/Workflow/Registry.php @@ -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]; diff --git a/src/Symfony/Component/Workflow/StateMachine.php b/src/Symfony/Component/Workflow/StateMachine.php index 05f4c291da..aa4f024b90 100644 --- a/src/Symfony/Component/Workflow/StateMachine.php +++ b/src/Symfony/Component/Workflow/StateMachine.php @@ -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); } } diff --git a/src/Symfony/Component/Workflow/SupportStrategy/ClassInstanceSupportStrategy.php b/src/Symfony/Component/Workflow/SupportStrategy/ClassInstanceSupportStrategy.php deleted file mode 100644 index fb08b2c278..0000000000 --- a/src/Symfony/Component/Workflow/SupportStrategy/ClassInstanceSupportStrategy.php +++ /dev/null @@ -1,47 +0,0 @@ - - * - * 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 - * - * @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; - } -} diff --git a/src/Symfony/Component/Workflow/SupportStrategy/SupportStrategyInterface.php b/src/Symfony/Component/Workflow/SupportStrategy/SupportStrategyInterface.php deleted file mode 100644 index 3627591fac..0000000000 --- a/src/Symfony/Component/Workflow/SupportStrategy/SupportStrategyInterface.php +++ /dev/null @@ -1,30 +0,0 @@ - - * - * 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 - * - * @deprecated since Symfony 4.1, use WorkflowSupportStrategyInterface instead - */ -interface SupportStrategyInterface -{ - /** - * @param Workflow $workflow - * @param object $subject - * - * @return bool - */ - public function supports(Workflow $workflow, $subject); -} diff --git a/src/Symfony/Component/Workflow/Tests/EventListener/GuardListenerTest.php b/src/Symfony/Component/Workflow/Tests/EventListener/GuardListenerTest.php index 805b626246..eb47e61b84 100644 --- a/src/Symfony/Component/Workflow/Tests/EventListener/GuardListenerTest.php +++ b/src/Symfony/Component/Workflow/Tests/EventListener/GuardListenerTest.php @@ -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() diff --git a/src/Symfony/Component/Workflow/Tests/MarkingStore/MultipleStateMarkingStoreTest.php b/src/Symfony/Component/Workflow/Tests/MarkingStore/MultipleStateMarkingStoreTest.php deleted file mode 100644 index 4ca81e1cd7..0000000000 --- a/src/Symfony/Component/Workflow/Tests/MarkingStore/MultipleStateMarkingStoreTest.php +++ /dev/null @@ -1,34 +0,0 @@ -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); - } -} diff --git a/src/Symfony/Component/Workflow/Tests/MarkingStore/SingleStateMarkingStoreTest.php b/src/Symfony/Component/Workflow/Tests/MarkingStore/SingleStateMarkingStoreTest.php deleted file mode 100644 index 7b640559ff..0000000000 --- a/src/Symfony/Component/Workflow/Tests/MarkingStore/SingleStateMarkingStoreTest.php +++ /dev/null @@ -1,34 +0,0 @@ -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); - } -} diff --git a/src/Symfony/Component/Workflow/Tests/RegistryTest.php b/src/Symfony/Component/Workflow/Tests/RegistryTest.php index c506186621..0fb24f2fa7 100644 --- a/src/Symfony/Component/Workflow/Tests/RegistryTest.php +++ b/src/Symfony/Component/Workflow/Tests/RegistryTest.php @@ -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(); diff --git a/src/Symfony/Component/Workflow/Tests/SupportStrategy/ClassInstanceSupportStrategyTest.php b/src/Symfony/Component/Workflow/Tests/SupportStrategy/ClassInstanceSupportStrategyTest.php deleted file mode 100644 index e79a8a1f3f..0000000000 --- a/src/Symfony/Component/Workflow/Tests/SupportStrategy/ClassInstanceSupportStrategyTest.php +++ /dev/null @@ -1,37 +0,0 @@ -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(); - } -} diff --git a/src/Symfony/Component/Workflow/Tests/WorkflowTest.php b/src/Symfony/Component/Workflow/Tests/WorkflowTest.php index 6579921d9e..9a8f97d94a 100644 --- a/src/Symfony/Component/Workflow/Tests/WorkflowTest.php +++ b/src/Symfony/Component/Workflow/Tests/WorkflowTest.php @@ -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); From cbb8b2275300e4cf90a1963219d8f1fcb6c7513a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Pineau?= Date: Tue, 4 Jun 2019 14:35:32 +0200 Subject: [PATCH 2/2] [FrameworkBundle][Workflow] Remove BC layers and deprecated codes --- .../DependencyInjection/Configuration.php | 52 +-------- .../FrameworkExtension.php | 52 +++------ .../Resources/config/workflow.xml | 2 - .../Fixtures/php/workflow-legacy.php | 29 ----- ...flow_legacy_with_arguments_and_service.php | 31 ----- .../workflow_legacy_with_type_and_service.php | 31 ----- .../php/workflows_explicitly_enabled.php | 4 +- ...ows_explicitly_enabled_named_workflows.php | 4 +- .../Fixtures/xml/workflow-legacy.xml | 23 ---- ...flow_legacy_with_arguments_and_service.xml | 24 ---- .../workflow_legacy_with_type_and_service.xml | 21 ---- .../xml/workflows_explicitly_enabled.xml | 2 +- .../Fixtures/yml/workflow-legacy.yml | 18 --- ...flow_legacy_with_arguments_and_service.yml | 19 --- .../workflow_legacy_with_type_and_service.yml | 17 --- .../yml/workflows_explicitly_enabled.yml | 2 +- ...ows_explicitly_enabled_named_workflows.yml | 4 +- .../FrameworkExtensionTest.php | 48 +------- .../PhpFrameworkExtensionTest.php | 108 ------------------ src/Symfony/Component/Workflow/Registry.php | 1 - .../Tests/Validator/WorkflowValidatorTest.php | 35 ------ 21 files changed, 29 insertions(+), 498 deletions(-) delete mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow-legacy.php delete mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow_legacy_with_arguments_and_service.php delete mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow_legacy_with_type_and_service.php delete mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow-legacy.xml delete mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_legacy_with_arguments_and_service.xml delete mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_legacy_with_type_and_service.xml delete mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflow-legacy.yml delete mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflow_legacy_with_arguments_and_service.yml delete mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflow_legacy_with_type_and_service.yml diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index 7436e4d277..dd8cd93fee 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -256,15 +256,6 @@ class Configuration implements ConfigurationInterface ->arrayNode('workflows') ->useAttributeAsKey('name') ->prototype('array') - ->beforeNormalization() - ->always(function ($v) { - if (isset($v['initial_place'])) { - $v['initial_marking'] = [$v['initial_place']]; - } - - return $v; - }) - ->end() ->fixXmlConfig('support') ->fixXmlConfig('place') ->fixXmlConfig('transition') @@ -277,28 +268,9 @@ class Configuration implements ConfigurationInterface ->defaultValue('state_machine') ->end() ->arrayNode('marking_store') - ->fixXmlConfig('argument') ->children() ->enumNode('type') - ->values(['multiple_state', 'single_state', 'method']) - ->validate() - ->ifTrue(function ($v) { return 'method' !== $v; }) - ->then(function ($v) { - @trigger_error('Passing something else than "method" has been deprecated in Symfony 4.3.', E_USER_DEPRECATED); - - return $v; - }) - ->end() - ->end() - ->arrayNode('arguments') - ->setDeprecated('The "%path%.%node%" configuration key has been deprecated in Symfony 4.3. Use "property" instead.') - ->beforeNormalization() - ->ifString() - ->then(function ($v) { return [$v]; }) - ->end() - ->requiresAtLeastOneElement() - ->prototype('scalar') - ->end() + ->values(['method']) ->end() ->scalarNode('property') ->defaultValue('marking') @@ -307,14 +279,6 @@ class Configuration implements ConfigurationInterface ->cannotBeEmpty() ->end() ->end() - ->validate() - ->ifTrue(function ($v) { return isset($v['type']) && isset($v['service']); }) - ->thenInvalid('"type" and "service" cannot be used together.') - ->end() - ->validate() - ->ifTrue(function ($v) { return !empty($v['arguments']) && isset($v['service']); }) - ->thenInvalid('"arguments" and "service" cannot be used together.') - ->end() ->end() ->arrayNode('supports') ->beforeNormalization() @@ -332,10 +296,6 @@ class Configuration implements ConfigurationInterface ->scalarNode('support_strategy') ->cannotBeEmpty() ->end() - ->scalarNode('initial_place') - ->setDeprecated('The "%path%.%node%" configuration key has been deprecated in Symfony 4.3, use the "initial_marking" configuration key instead.') - ->defaultNull() - ->end() ->arrayNode('initial_marking') ->beforeNormalization() ->ifTrue(function ($v) { return !\is_array($v); }) @@ -472,16 +432,6 @@ class Configuration implements ConfigurationInterface }) ->thenInvalid('"supports" or "support_strategy" should be configured.') ->end() - ->validate() - ->ifTrue(function ($v) { - return 'workflow' === $v['type'] && 'single_state' === ($v['marking_store']['type'] ?? false); - }) - ->then(function ($v) { - @trigger_error('Using a workflow with type=workflow and a marking_store=single_state is deprecated since Symfony 4.3. Use type=state_machine instead.', E_USER_DEPRECATED); - - return $v; - }) - ->end() ->end() ->end() ->end() diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index bbe5fced15..48e40eed0a 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -627,7 +627,7 @@ class FrameworkExtension extends Extension // Create places $places = array_column($workflow['places'], 'name'); - $initialMarking = $workflow['initial_marking'] ?? $workflow['initial_place'] ?? []; + $initialMarking = $workflow['initial_marking'] ?? []; // Create a Definition $definitionDefinition = new Definition(Workflow\Definition::class); @@ -639,17 +639,11 @@ class FrameworkExtension extends Extension // Create MarkingStore if (isset($workflow['marking_store']['type'])) { - $markingStoreDefinition = new ChildDefinition('workflow.marking_store.'.$workflow['marking_store']['type']); - if ('method' === $workflow['marking_store']['type']) { - $markingStoreDefinition->setArguments([ - 'state_machine' === $type, //single state - $workflow['marking_store']['property'], - ]); - } else { - foreach ($workflow['marking_store']['arguments'] as $argument) { - $markingStoreDefinition->addArgument($argument); - } - } + $markingStoreDefinition = new ChildDefinition('workflow.marking_store.method'); + $markingStoreDefinition->setArguments([ + 'state_machine' === $type, //single state + $workflow['marking_store']['property'], + ]); } elseif (isset($workflow['marking_store']['service'])) { $markingStoreDefinition = new Reference($workflow['marking_store']['service']); } @@ -668,29 +662,19 @@ class FrameworkExtension extends Extension $container->registerAliasForArgument($workflowId, WorkflowInterface::class, $name.'.'.$type); // Validate Workflow - $validator = null; - switch (true) { - case 'state_machine' === $workflow['type']: - $validator = new Workflow\Validator\StateMachineValidator(); - break; - case 'single_state' === ($workflow['marking_store']['type'] ?? null): - $validator = new Workflow\Validator\WorkflowValidator(true); - break; - case 'multiple_state' === ($workflow['marking_store']['type'] ?? false): - $validator = new Workflow\Validator\WorkflowValidator(false); - break; - } - - if ($validator) { - $realDefinition = (new Workflow\DefinitionBuilder($places)) - ->addTransitions(array_map(function (Reference $ref) use ($container): Workflow\Transition { - return $container->get((string) $ref); - }, $transitions)) - ->setInitialPlace($initialMarking) - ->build() - ; - $validator->validate($realDefinition, $name); + $realDefinition = (new Workflow\DefinitionBuilder($places)) + ->addTransitions(array_map(function (Reference $ref) use ($container): Workflow\Transition { + return $container->get((string) $ref); + }, $transitions)) + ->setInitialPlace($initialMarking) + ->build() + ; + if ('state_machine' === $workflow['type']) { + $validator = new Workflow\Validator\StateMachineValidator(); + } else { + $validator = new Workflow\Validator\WorkflowValidator(); } + $validator->validate($realDefinition, $name); // Add workflow to Registry if ($workflow['supports']) { diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/workflow.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/workflow.xml index 0bba153b10..78741deb8e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/workflow.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/workflow.xml @@ -20,8 +20,6 @@ - - diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow-legacy.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow-legacy.php deleted file mode 100644 index cad94fc773..0000000000 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow-legacy.php +++ /dev/null @@ -1,29 +0,0 @@ -loadFromExtension('framework', [ - 'workflows' => [ - 'legacy' => [ - 'type' => 'state_machine', - 'marking_store' => [ - 'type' => 'single_state', - 'arguments' => [ - 'state', - ], - ], - 'supports' => [ - stdClass::class, - ], - 'initial_place' => 'draft', - 'places' => [ - 'draft', - 'published', - ], - 'transitions' => [ - 'publish' => [ - 'from' => 'draft', - 'to' => 'published', - ], - ], - ], - ], -]); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow_legacy_with_arguments_and_service.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow_legacy_with_arguments_and_service.php deleted file mode 100644 index 003b99f210..0000000000 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow_legacy_with_arguments_and_service.php +++ /dev/null @@ -1,31 +0,0 @@ -loadFromExtension('framework', [ - 'workflows' => [ - 'my_workflow' => [ - 'marking_store' => [ - 'arguments' => ['a', 'b'], - 'service' => 'workflow_service', - ], - 'supports' => [ - FrameworkExtensionTest::class, - ], - 'places' => [ - 'first', - 'last', - ], - 'transitions' => [ - 'go' => [ - 'from' => [ - 'first', - ], - 'to' => [ - 'last', - ], - ], - ], - ], - ], -]); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow_legacy_with_type_and_service.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow_legacy_with_type_and_service.php deleted file mode 100644 index 15189349bd..0000000000 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow_legacy_with_type_and_service.php +++ /dev/null @@ -1,31 +0,0 @@ -loadFromExtension('framework', [ - 'workflows' => [ - 'my_workflow' => [ - 'marking_store' => [ - 'type' => 'method', - 'service' => 'workflow_service', - ], - 'supports' => [ - FrameworkExtensionTest::class, - ], - 'places' => [ - 'first', - 'last', - ], - 'transitions' => [ - 'go' => [ - 'from' => [ - 'first', - ], - 'to' => [ - 'last', - ], - ], - ], - ], - ], -]); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflows_explicitly_enabled.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflows_explicitly_enabled.php index e6f261f8f2..f048de1ceb 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflows_explicitly_enabled.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflows_explicitly_enabled.php @@ -10,8 +10,8 @@ $container->loadFromExtension('framework', [ 'places' => ['bar', 'baz'], 'transitions' => [ 'bar_baz' => [ - 'from' => ['foo'], - 'to' => ['bar'], + 'from' => ['bar'], + 'to' => ['baz'], ], ], ], diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflows_explicitly_enabled_named_workflows.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflows_explicitly_enabled_named_workflows.php index e4bc05a66f..f79a2d10e9 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflows_explicitly_enabled_named_workflows.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflows_explicitly_enabled_named_workflows.php @@ -10,8 +10,8 @@ $container->loadFromExtension('framework', [ 'places' => ['bar', 'baz'], 'transitions' => [ 'bar_baz' => [ - 'from' => ['foo'], - 'to' => ['bar'], + 'from' => ['bar'], + 'to' => ['baz'], ], ], ], diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow-legacy.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow-legacy.xml deleted file mode 100644 index 5a46d24d0d..0000000000 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow-legacy.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - state - - stdClass - - - - draft - published - - - - diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_legacy_with_arguments_and_service.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_legacy_with_arguments_and_service.xml deleted file mode 100644 index cdb2f99735..0000000000 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_legacy_with_arguments_and_service.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - a - a - - Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest - - - - a - a - - - - diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_legacy_with_type_and_service.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_legacy_with_type_and_service.xml deleted file mode 100644 index e137f9b4b0..0000000000 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_legacy_with_type_and_service.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest - - - - a - a - - - - diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflows_explicitly_enabled.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflows_explicitly_enabled.xml index bb544d8979..af93d44e18 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflows_explicitly_enabled.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflows_explicitly_enabled.xml @@ -6,7 +6,7 @@ http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd"> - + Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest bar baz diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflow-legacy.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflow-legacy.yml deleted file mode 100644 index 19f51dc9f4..0000000000 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflow-legacy.yml +++ /dev/null @@ -1,18 +0,0 @@ -framework: - workflows: - legacy: - type: state_machine - marking_store: - type: single_state - arguments: - - state - initial_place: draft - supports: - - stdClass - places: - - draft - - published - transitions: - publish: - from: draft - to: published diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflow_legacy_with_arguments_and_service.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflow_legacy_with_arguments_and_service.yml deleted file mode 100644 index a46d4b67e6..0000000000 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflow_legacy_with_arguments_and_service.yml +++ /dev/null @@ -1,19 +0,0 @@ -framework: - workflows: - my_workflow: - marking_store: - arguments: - - a - - b - service: workflow_service - supports: - - Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest - places: - - first - - last - transitions: - go: - from: - - first - to: - - last diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflow_legacy_with_type_and_service.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflow_legacy_with_type_and_service.yml deleted file mode 100644 index 33ee68b1bc..0000000000 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflow_legacy_with_type_and_service.yml +++ /dev/null @@ -1,17 +0,0 @@ -framework: - workflows: - my_workflow: - marking_store: - type: method - service: workflow_service - supports: - - Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest - places: - - first - - last - transitions: - go: - from: - - first - to: - - last diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflows_explicitly_enabled.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflows_explicitly_enabled.yml index bee231736b..bbecf4bfc4 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflows_explicitly_enabled.yml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflows_explicitly_enabled.yml @@ -12,5 +12,5 @@ framework: - baz transitions: bar_baz: - from: [foo] + from: [bar] to: [bar] diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflows_explicitly_enabled_named_workflows.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflows_explicitly_enabled_named_workflows.yml index c0462c9ab8..786e3bcad2 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflows_explicitly_enabled_named_workflows.yml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflows_explicitly_enabled_named_workflows.yml @@ -11,5 +11,5 @@ framework: - baz transitions: bar_baz: - from: [foo] - to: [bar] + from: [bar] + to: [baz] diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index afffc07aab..067a9fc977 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -278,31 +278,6 @@ abstract class FrameworkExtensionTest extends TestCase $this->assertGreaterThan(0, \count($registryDefinition->getMethodCalls())); } - /** - * @group legacy - */ - public function testWorkflowLegacy() - { - $container = $this->createContainerFromFile('workflow-legacy'); - - $this->assertTrue($container->hasDefinition('state_machine.legacy'), 'Workflow is registered as a service'); - $this->assertSame('state_machine.abstract', $container->getDefinition('state_machine.legacy')->getParent()); - $this->assertTrue($container->hasDefinition('state_machine.legacy.definition'), 'Workflow definition is registered as a service'); - - $workflowDefinition = $container->getDefinition('state_machine.legacy.definition'); - - $this->assertSame(['draft'], $workflowDefinition->getArgument(2)); - - $this->assertSame( - [ - 'draft', - 'published', - ], - $workflowDefinition->getArgument(0), - 'Places are passed to the workflow definition' - ); - } - /** * @expectedException \Symfony\Component\Workflow\Exception\InvalidDefinitionException * @expectedExceptionMessage A transition from a place/state must have an unique name. Multiple transitions named "go" from place/state "first" where found on StateMachine "my_workflow". @@ -312,15 +287,6 @@ abstract class FrameworkExtensionTest extends TestCase $this->createContainerFromFile('workflow_not_valid'); } - /** - * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException - * @expectedExceptionMessage "type" and "service" cannot be used together. - */ - public function testWorkflowCannotHaveBothTypeAndService() - { - $this->createContainerFromFile('workflow_legacy_with_type_and_service'); - } - /** * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException * @expectedExceptionMessage "supports" and "support_strategy" cannot be used together. @@ -339,16 +305,6 @@ abstract class FrameworkExtensionTest extends TestCase $this->createContainerFromFile('workflow_without_support_and_support_strategy'); } - /** - * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException - * @expectedExceptionMessage "arguments" and "service" cannot be used together. - * @group legacy - */ - public function testWorkflowCannotHaveBothArgumentsAndService() - { - $this->createContainerFromFile('workflow_legacy_with_arguments_and_service'); - } - public function testWorkflowMultipleTransitionsWithSameName() { $container = $this->createContainerFromFile('workflow_with_multiple_transitions_with_same_name'); @@ -450,14 +406,14 @@ abstract class FrameworkExtensionTest extends TestCase $this->assertTrue($container->hasDefinition('console.command.workflow_dump')); } - public function testExplicitlyEnabledWorkflows() + public function testWorkflowsExplicitlyEnabled() { $container = $this->createContainerFromFile('workflows_explicitly_enabled'); $this->assertTrue($container->hasDefinition('workflow.foo.definition')); } - public function testExplicitlyEnabledWorkflowNamedWorkflows() + public function testWorkflowsNamedExplicitlyEnabled() { $container = $this->createContainerFromFile('workflows_explicitly_enabled_named_workflows'); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/PhpFrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/PhpFrameworkExtensionTest.php index a67a358447..94c5cab184 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/PhpFrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/PhpFrameworkExtensionTest.php @@ -87,112 +87,4 @@ class PhpFrameworkExtensionTest extends FrameworkExtensionTest ]); }); } - - /** - * @group legacy - * @expectedDeprecation Using a workflow with type=workflow and a marking_store=single_state is deprecated since Symfony 4.3. Use type=state_machine instead. - */ - public function testWorkflowDeprecateWorkflowSingleState() - { - $this->createContainerFromClosure(function ($container) { - $container->loadFromExtension('framework', [ - 'workflows' => [ - 'article' => [ - 'type' => 'workflow', - 'marking_store' => [ - 'type' => 'single_state', - ], - 'supports' => [ - __CLASS__, - ], - 'places' => [ - 'a', - 'b', - 'c', - ], - 'transitions' => [ - 'a_to_b' => [ - 'from' => ['a'], - 'to' => ['b'], - ], - ], - ], - ], - ]); - }); - } - - /** - * @group legacy - */ - public function testWorkflowValidationMultipleState() - { - $this->createContainerFromClosure(function ($container) { - $container->loadFromExtension('framework', [ - 'workflows' => [ - 'article' => [ - 'type' => 'workflow', - 'marking_store' => [ - 'type' => 'multiple_state', - ], - 'supports' => [ - __CLASS__, - ], - 'places' => [ - 'a', - 'b', - 'c', - ], - 'transitions' => [ - 'a_to_b' => [ - 'from' => ['a'], - 'to' => ['b', 'c'], - ], - ], - ], - ], - ]); - }); - - // the test ensures that the validation does not fail (i.e. it does not throw any exceptions) - $this->addToAssertionCount(1); - } - - /** - * @expectedException \Symfony\Component\Workflow\Exception\InvalidDefinitionException - * @expectedExceptionMessage The marking store of workflow "article" can not store many places. But the transition "a_to_b" has too many output (2). Only one is accepted. - * @group legacy - */ - public function testWorkflowValidationSingleState() - { - $this->createContainerFromClosure(function ($container) { - $container->loadFromExtension('framework', [ - 'workflows' => [ - 'article' => [ - 'type' => 'workflow', - 'marking_store' => [ - 'type' => 'single_state', - ], - 'supports' => [ - __CLASS__, - ], - 'places' => [ - 'a', - 'b', - 'c', - ], - 'transitions' => [ - 'a_to_b' => [ - 'from' => ['a'], - 'to' => ['b', 'c'], - ], - ], - ], - ], - ]); - }); - - // the test ensures that the validation does not fail (i.e. it does not throw any exceptions) - $this->addToAssertionCount(1); - } } diff --git a/src/Symfony/Component/Workflow/Registry.php b/src/Symfony/Component/Workflow/Registry.php index 0711f1663b..ffb0732fcb 100644 --- a/src/Symfony/Component/Workflow/Registry.php +++ b/src/Symfony/Component/Workflow/Registry.php @@ -12,7 +12,6 @@ namespace Symfony\Component\Workflow; use Symfony\Component\Workflow\Exception\InvalidArgumentException; -use Symfony\Component\Workflow\SupportStrategy\SupportStrategyInterface; use Symfony\Component\Workflow\SupportStrategy\WorkflowSupportStrategyInterface; /** diff --git a/src/Symfony/Component/Workflow/Tests/Validator/WorkflowValidatorTest.php b/src/Symfony/Component/Workflow/Tests/Validator/WorkflowValidatorTest.php index 5aa020fea4..2877947a91 100644 --- a/src/Symfony/Component/Workflow/Tests/Validator/WorkflowValidatorTest.php +++ b/src/Symfony/Component/Workflow/Tests/Validator/WorkflowValidatorTest.php @@ -12,27 +12,6 @@ class WorkflowValidatorTest extends TestCase { use WorkflowBuilderTrait; - /** - * @expectedException \Symfony\Component\Workflow\Exception\InvalidDefinitionException - * @expectedExceptionMessage The marking store of workflow "foo" can not store many places. - */ - public function testSinglePlaceWorkflowValidatorAndComplexWorkflow() - { - $definition = $this->createComplexWorkflowDefinition(); - - (new WorkflowValidator(true))->validate($definition, 'foo'); - } - - public function testSinglePlaceWorkflowValidatorAndSimpleWorkflow() - { - $definition = $this->createSimpleWorkflowDefinition(); - - (new WorkflowValidator(true))->validate($definition, 'foo'); - - // the test ensures that the validation does not fail (i.e. it does not throw any exceptions) - $this->addToAssertionCount(1); - } - /** * @expectedException \Symfony\Component\Workflow\Exception\InvalidDefinitionException * @expectedExceptionMessage All transitions for a place must have an unique name. Multiple transitions named "t1" where found for place "a" in workflow "foo". @@ -51,20 +30,6 @@ class WorkflowValidatorTest extends TestCase (new WorkflowValidator())->validate($definition, 'foo'); } - /** - * @expectedException \Symfony\Component\Workflow\Exception\InvalidDefinitionException - * @expectedExceptionMessage The marking store of workflow "foo" can not store many places. But the definition has 2 initial places. Only one is supported. - */ - public function testWithTooManyInitialPlaces() - { - $places = range('a', 'c'); - $transitions = []; - - $definition = new Definition($places, $transitions, ['a', 'b']); - - (new WorkflowValidator(true))->validate($definition, 'foo'); - } - public function testSameTransitionNameButNotSamePlace() { $places = range('a', 'd');