From 1ccbe0bae25f91efe40815bef469c04c227850ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Pineau?= Date: Fri, 19 May 2017 10:19:00 +0200 Subject: [PATCH 1/3] [Workflow] Removed class name support in `WorkflowRegistry::add()` as second parameter --- src/Symfony/Component/Workflow/CHANGELOG.md | 5 ++++ src/Symfony/Component/Workflow/Registry.php | 11 ++++----- .../Component/Workflow/Tests/RegistryTest.php | 23 ------------------- 3 files changed, 9 insertions(+), 30 deletions(-) diff --git a/src/Symfony/Component/Workflow/CHANGELOG.md b/src/Symfony/Component/Workflow/CHANGELOG.md index 51a52777dfa8..f423bb25b9c0 100644 --- a/src/Symfony/Component/Workflow/CHANGELOG.md +++ b/src/Symfony/Component/Workflow/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +4.0.0 +----- + + * Removed class name support in `WorkflowRegistry::add()` as second parameter. + 3.3.0 ----- diff --git a/src/Symfony/Component/Workflow/Registry.php b/src/Symfony/Component/Workflow/Registry.php index 4bc806d200ba..b10af2fbbc0a 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\ClassInstanceSupportStrategy; use Symfony\Component\Workflow\SupportStrategy\SupportStrategyInterface; /** @@ -24,15 +23,13 @@ class Registry private $workflows = array(); /** - * @param Workflow $workflow - * @param string|SupportStrategyInterface $supportStrategy + * @param Workflow $workflow + * @param SupportStrategyInterface $supportStrategy */ public function add(Workflow $workflow, $supportStrategy) { if (!$supportStrategy instanceof SupportStrategyInterface) { - @trigger_error('Support of class name string was deprecated after version 3.2 and won\'t work anymore in 4.0.', E_USER_DEPRECATED); - - $supportStrategy = new ClassInstanceSupportStrategy($supportStrategy); + throw new \InvalidArgumentException('The "supportStrategy" is not an instance of SupportStrategyInterface.'); } $this->workflows[] = array($workflow, $supportStrategy); @@ -64,7 +61,7 @@ public function get($subject, $workflowName = null) return $matched; } - private function supports(Workflow $workflow, $supportStrategy, $subject, $workflowName) + private function supports(Workflow $workflow, SupportStrategyInterface $supportStrategy, $subject, $workflowName) { if (null !== $workflowName && $workflowName !== $workflow->getName()) { return false; diff --git a/src/Symfony/Component/Workflow/Tests/RegistryTest.php b/src/Symfony/Component/Workflow/Tests/RegistryTest.php index 262e7cfe59dd..a85dd74a732f 100644 --- a/src/Symfony/Component/Workflow/Tests/RegistryTest.php +++ b/src/Symfony/Component/Workflow/Tests/RegistryTest.php @@ -65,29 +65,6 @@ public function testGetWithNoMatch() $this->assertSame('workflow1', $w1->getName()); } - /** - * @group legacy - */ - public function testGetWithSuccessLegacyStrategy() - { - $registry = new Registry(); - - $registry->add(new Workflow(new Definition(array(), array()), $this->getMockBuilder(MarkingStoreInterface::class)->getMock(), $this->getMockBuilder(EventDispatcherInterface::class)->getMock(), 'workflow1'), Subject1::class); - $registry->add(new Workflow(new Definition(array(), array()), $this->getMockBuilder(MarkingStoreInterface::class)->getMock(), $this->getMockBuilder(EventDispatcherInterface::class)->getMock(), 'workflow2'), Subject2::class); - - $workflow = $registry->get(new Subject1()); - $this->assertInstanceOf(Workflow::class, $workflow); - $this->assertSame('workflow1', $workflow->getName()); - - $workflow = $registry->get(new Subject1(), 'workflow1'); - $this->assertInstanceOf(Workflow::class, $workflow); - $this->assertSame('workflow1', $workflow->getName()); - - $workflow = $registry->get(new Subject2(), 'workflow2'); - $this->assertInstanceOf(Workflow::class, $workflow); - $this->assertSame('workflow2', $workflow->getName()); - } - private function createSupportStrategy($supportedClassName) { $strategy = $this->getMockBuilder(SupportStrategyInterface::class)->getMock(); From fd2577755d74338fb726b032c902f3f141896ac7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Pineau?= Date: Fri, 19 May 2017 10:27:02 +0200 Subject: [PATCH 2/3] [Workflow] Removed FrameworkBundle/DependencyInjection/Compiler/ValidateWorkflowsPass --- .../Bundle/FrameworkBundle/CHANGELOG.md | 7 +++++- .../Compiler/ValidateWorkflowsPass.php | 25 ------------------- 2 files changed, 6 insertions(+), 26 deletions(-) delete mode 100644 src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/ValidateWorkflowsPass.php diff --git a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md index df80163243c1..c96f475abcd1 100644 --- a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md +++ b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +4.0.0 +----- + +* Removed `ValidateWorkflowsPass` + 3.3.0 ----- @@ -47,7 +52,7 @@ CHANGELOG `Symfony\Component\Validator\DependencyInjection\AddValidatorInitializersPass` instead * Deprecated `AddConstraintValidatorsPass`, use `Symfony\Component\Validator\DependencyInjection\AddConstraintValidatorsPass` instead - * Deprecated `ValidateWorkflowsPass`, use + * Deprecated `ValidateWorkflowsPass`, use `Symfony\Component\Workflow\DependencyInjection\ValidateWorkflowsPass` instead 3.2.0 diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/ValidateWorkflowsPass.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/ValidateWorkflowsPass.php deleted file mode 100644 index 6599f1f1a030..000000000000 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/ValidateWorkflowsPass.php +++ /dev/null @@ -1,25 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler; - -use Symfony\Component\Workflow\DependencyInjection\ValidateWorkflowsPass as BaseValidateWorkflowsPass; - -@trigger_error(sprintf('The %s class is deprecated since version 3.3 and will be removed in 4.0. Use %s instead.', ValidateWorkflowsPass::class, BaseValidateWorkflowsPass::class), E_USER_DEPRECATED); - -/** - * @author Tobias Nyholm - * - * @deprecated since version 3.3, to be removed in 4.0. Use {@link BaseValidateWorkflowsPass} instead - */ -class ValidateWorkflowsPass extends BaseValidateWorkflowsPass -{ -} From 3bed8f61676c47a0e430c2346482a5d33c30b3e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Pineau?= Date: Fri, 19 May 2017 10:31:21 +0200 Subject: [PATCH 3/3] [Workflow] The `type` option of the `framework.workflows.*` configuration entries is `state_machine` --- .../Bundle/FrameworkBundle/CHANGELOG.md | 3 ++- .../DependencyInjection/Configuration.php | 1 + .../FrameworkExtension.php | 4 --- .../Fixtures/php/workflows.php | 1 - .../Fixtures/php/workflows_without_type.php | 26 ------------------- .../Fixtures/xml/workflows.xml | 2 +- .../Fixtures/xml/workflows_without_type.xml | 21 --------------- .../Fixtures/yml/workflows.yml | 1 - .../Fixtures/yml/workflows_without_type.yml | 7 ----- .../FrameworkExtensionTest.php | 19 +++++--------- 10 files changed, 10 insertions(+), 75 deletions(-) delete mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflows_without_type.php delete mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflows_without_type.xml delete mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflows_without_type.yml diff --git a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md index c96f475abcd1..fbc42260fb67 100644 --- a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md +++ b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md @@ -4,7 +4,8 @@ CHANGELOG 4.0.0 ----- -* Removed `ValidateWorkflowsPass` + * Removed `ValidateWorkflowsPass` + * The default `type` option of the `framework.workflows.*` configuration entries is `state_machine` 3.3.0 ----- diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index 87d722b91e4d..9d09599d811e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -230,6 +230,7 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode) ->end() ->enumNode('type') ->values(array('workflow', 'state_machine')) + ->defaultValue('state_machine') ->end() ->arrayNode('marking_store') ->fixXmlConfig('argument') diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index c65c1f8e740b..d9af9339e3d2 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -498,10 +498,6 @@ private function registerWorkflowConfiguration(array $workflows, ContainerBuilde $registryDefinition = $container->getDefinition('workflow.registry'); foreach ($workflows as $name => $workflow) { - if (!array_key_exists('type', $workflow)) { - $workflow['type'] = 'workflow'; - @trigger_error(sprintf('The "type" option of the "framework.workflows.%s" configuration entry must be defined since Symfony 3.3. The default value will be "state_machine" in Symfony 4.0.', $name), E_USER_DEPRECATED); - } $type = $workflow['type']; $transitions = array(); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflows.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflows.php index c527606561ee..3d3f4266b7eb 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflows.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflows.php @@ -41,7 +41,6 @@ ), ), 'pull_request' => array( - 'type' => 'state_machine', 'marking_store' => array( 'type' => 'single_state', ), diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflows_without_type.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflows_without_type.php deleted file mode 100644 index 63e83170fca5..000000000000 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflows_without_type.php +++ /dev/null @@ -1,26 +0,0 @@ -loadFromExtension('framework', array( - 'workflows' => array( - 'missing_type' => array( - 'marking_store' => array( - 'service' => 'workflow_service', - ), - 'supports' => array( - \stdClass::class, - ), - 'places' => array( - 'first', - 'last', - ), - 'transitions' => array( - 'go' => array( - 'from' => 'first', - 'to' => 'last', - ), - ), - ), - ), -)); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflows.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflows.xml index be065c455885..02f964bc3a43 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflows.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflows.xml @@ -39,7 +39,7 @@ - + Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest start diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflows_without_type.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflows_without_type.xml deleted file mode 100644 index 2e6ebad552b7..000000000000 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflows_without_type.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - stdClass - first - last - - first - last - - - - diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflows.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflows.yml index 36b84f71e458..8efb803c12ad 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflows.yml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflows.yml @@ -28,7 +28,6 @@ framework: from: [approved_by_journalist, approved_by_spellchecker] to: [published] pull_request: - type: state_machine marking_store: type: single_state supports: diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflows_without_type.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflows_without_type.yml deleted file mode 100644 index 41b81683ba44..000000000000 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflows_without_type.yml +++ /dev/null @@ -1,7 +0,0 @@ -framework: - workflows: - missing_type: - supports: stdClass - places: [ first, second ] - transitions: - go: {from: first, to: last } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index 4f86c85d4f8f..a6a201350214 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -154,8 +154,9 @@ public function testWorkflows() { $container = $this->createContainerFromFile('workflows'); - $this->assertTrue($container->hasDefinition('workflow.article', 'Workflow is registered as a service')); - $this->assertTrue($container->hasDefinition('workflow.article.definition', 'Workflow definition is registered as a service')); + $this->assertTrue($container->hasDefinition('workflow.article'), 'Workflow is registered as a service'); + $this->assertSame('workflow.abstract', $container->getDefinition('workflow.article')->getParent()); + $this->assertTrue($container->hasDefinition('workflow.article.definition'), 'Workflow definition is registered as a service'); $workflowDefinition = $container->getDefinition('workflow.article.definition'); @@ -173,8 +174,9 @@ public function testWorkflows() ); $this->assertSame(array('workflow.definition' => array(array('name' => 'article', 'type' => 'workflow', 'marking_store' => 'multiple_state'))), $workflowDefinition->getTags()); - $this->assertTrue($container->hasDefinition('state_machine.pull_request', 'State machine is registered as a service')); - $this->assertTrue($container->hasDefinition('state_machine.pull_request.definition', 'State machine definition is registered as a service')); + $this->assertTrue($container->hasDefinition('state_machine.pull_request'), 'State machine is registered as a service'); + $this->assertSame('state_machine.abstract', $container->getDefinition('state_machine.pull_request')->getParent()); + $this->assertTrue($container->hasDefinition('state_machine.pull_request.definition'), 'State machine definition is registered as a service'); $this->assertCount(4, $workflowDefinition->getArgument(1)); $this->assertSame('draft', $workflowDefinition->getArgument(2)); @@ -207,15 +209,6 @@ public function testWorkflows() $this->assertGreaterThan(0, count($registryDefinition->getMethodCalls())); } - /** - * @group legacy - * @expectedDeprecation The "type" option of the "framework.workflows.missing_type" configuration entry must be defined since Symfony 3.3. The default value will be "state_machine" in Symfony 4.0. - */ - public function testDeprecatedWorkflowMissingType() - { - $container = $this->createContainerFromFile('workflows_without_type'); - } - /** * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException * @expectedExceptionMessage "type" and "service" cannot be used together.