From 847d9cdbc84ddb3dd581ed41816d48dac13f0dee Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 2 Jun 2025 16:08:14 +0200 Subject: [PATCH 01/11] Allow Symfony ^8.0 --- composer.json | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/composer.json b/composer.json index 3e2c50a..ff8561c 100644 --- a/composer.json +++ b/composer.json @@ -25,15 +25,15 @@ }, "require-dev": { "psr/log": "^1|^2|^3", - "symfony/config": "^6.4|^7.0", - "symfony/dependency-injection": "^6.4|^7.0", - "symfony/error-handler": "^6.4|^7.0", - "symfony/event-dispatcher": "^6.4|^7.0", - "symfony/expression-language": "^6.4|^7.0", - "symfony/http-kernel": "^6.4|^7.0", - "symfony/security-core": "^6.4|^7.0", - "symfony/stopwatch": "^6.4|^7.0", - "symfony/validator": "^6.4|^7.0" + "symfony/config": "^6.4|^7.0|^8.0", + "symfony/dependency-injection": "^6.4|^7.0|^8.0", + "symfony/error-handler": "^6.4|^7.0|^8.0", + "symfony/event-dispatcher": "^6.4|^7.0|^8.0", + "symfony/expression-language": "^6.4|^7.0|^8.0", + "symfony/http-kernel": "^6.4|^7.0|^8.0", + "symfony/security-core": "^6.4|^7.0|^8.0", + "symfony/stopwatch": "^6.4|^7.0|^8.0", + "symfony/validator": "^6.4|^7.0|^8.0" }, "conflict": { "symfony/event-dispatcher": "<6.4" From 039038a4c493c852cec96d7c535d3b5d6bd447c1 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 2 Jun 2025 17:50:55 +0200 Subject: [PATCH 02/11] Bump Symfony 8 to PHP >= 8.4 --- composer.json | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/composer.json b/composer.json index ff8561c..6de6506 100644 --- a/composer.json +++ b/composer.json @@ -20,23 +20,20 @@ } ], "require": { - "php": ">=8.2", + "php": ">=8.4", "symfony/deprecation-contracts": "2.5|^3" }, "require-dev": { "psr/log": "^1|^2|^3", - "symfony/config": "^6.4|^7.0|^8.0", - "symfony/dependency-injection": "^6.4|^7.0|^8.0", - "symfony/error-handler": "^6.4|^7.0|^8.0", - "symfony/event-dispatcher": "^6.4|^7.0|^8.0", - "symfony/expression-language": "^6.4|^7.0|^8.0", - "symfony/http-kernel": "^6.4|^7.0|^8.0", - "symfony/security-core": "^6.4|^7.0|^8.0", - "symfony/stopwatch": "^6.4|^7.0|^8.0", - "symfony/validator": "^6.4|^7.0|^8.0" - }, - "conflict": { - "symfony/event-dispatcher": "<6.4" + "symfony/config": "^7.4|^8.0", + "symfony/dependency-injection": "^7.4|^8.0", + "symfony/error-handler": "^7.4|^8.0", + "symfony/event-dispatcher": "^7.4|^8.0", + "symfony/expression-language": "^7.4|^8.0", + "symfony/http-kernel": "^7.4|^8.0", + "symfony/security-core": "^7.4|^8.0", + "symfony/stopwatch": "^7.4|^8.0", + "symfony/validator": "^7.4|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Workflow\\": "" }, From d351e885540e9210e55e5d7ae82d741942f9b198 Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Mon, 30 Jun 2025 19:52:36 +0200 Subject: [PATCH 03/11] [Workflow] Remove deprecated `Event::getWorkflow()` --- CHANGELOG.md | 72 +++++++++++++++++++++++++++++++++++++++++++++++++ Event/Event.php | 10 ------- composer.json | 3 +-- 3 files changed, 73 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a37ead..b6e1777 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,78 @@ CHANGELOG ========= +8.0 +--- + + * Remove `Event::getWorkflow()` method + + *Before* + ```php + use Symfony\Component\Workflow\Attribute\AsCompletedListener; + use Symfony\Component\Workflow\Event\CompletedEvent; + + class MyListener + { + #[AsCompletedListener('my_workflow', 'to_state2')] + public function terminateOrder(CompletedEvent $event): void + { + $subject = $event->getSubject(); + if ($event->getWorkflow()->can($subject, 'to_state3')) { + $event->getWorkflow()->apply($subject, 'to_state3'); + } + } + } + ``` + + *After* + ```php + use Symfony\Component\DependencyInjection\Attribute\Target; + use Symfony\Component\Workflow\Attribute\AsCompletedListener; + use Symfony\Component\Workflow\Event\CompletedEvent; + use Symfony\Component\Workflow\WorkflowInterface; + + class MyListener + { + public function __construct( + #[Target('my_workflow')] + private readonly WorkflowInterface $workflow, + ) { + } + + #[AsCompletedListener('my_workflow', 'to_state2')] + public function terminateOrder(CompletedEvent $event): void + { + $subject = $event->getSubject(); + if ($this->workflow->can($subject, 'to_state3')) { + $this->workflow->apply($subject, 'to_state3'); + } + } + } + ``` + + *Or* + ```php + use Symfony\Component\DependencyInjection\ServiceLocator; + use Symfony\Component\DependencyInjection\Attribute\AutowireLocator; + use Symfony\Component\Workflow\Attribute\AsTransitionListener; + use Symfony\Component\Workflow\Event\TransitionEvent; + + class GenericListener + { + public function __construct( + #[AutowireLocator('workflow', 'name')] + private ServiceLocator $workflows + ) { + } + + #[AsTransitionListener] + public function doSomething(TransitionEvent $event): void + { + $workflow = $this->workflows->get($event->getWorkflowName()); + } + } + ``` + 7.3 --- diff --git a/Event/Event.php b/Event/Event.php index c13818b..3550246 100644 --- a/Event/Event.php +++ b/Event/Event.php @@ -46,16 +46,6 @@ public function getTransition(): ?Transition return $this->transition; } - /** - * @deprecated since Symfony 7.3, inject the workflow in the constructor where you need it - */ - public function getWorkflow(): WorkflowInterface - { - trigger_deprecation('symfony/workflow', '7.3', 'The "%s()" method is deprecated, inject the workflow in the constructor where you need it.', __METHOD__); - - return $this->workflow; - } - public function getWorkflowName(): string { return $this->workflow->getName(); diff --git a/composer.json b/composer.json index 6de6506..e10e995 100644 --- a/composer.json +++ b/composer.json @@ -20,8 +20,7 @@ } ], "require": { - "php": ">=8.4", - "symfony/deprecation-contracts": "2.5|^3" + "php": ">=8.4" }, "require-dev": { "psr/log": "^1|^2|^3", From cc9995ebafc6b05f9b964611c910f5969d3433c9 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 8 Jul 2025 11:08:29 +0200 Subject: [PATCH 04/11] Various CS fixes --- DataCollector/WorkflowDataCollector.php | 2 +- DependencyInjection/WorkflowValidatorPass.php | 1 - Tests/Dumper/MermaidDumperTest.php | 12 ++++++------ 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/DataCollector/WorkflowDataCollector.php b/DataCollector/WorkflowDataCollector.php index 0cb7e20..6ce732b 100644 --- a/DataCollector/WorkflowDataCollector.php +++ b/DataCollector/WorkflowDataCollector.php @@ -101,7 +101,7 @@ public function buildMermaidLiveLink(string $name): string 'autoSync' => false, ]; - $compressed = zlib_encode(json_encode($payload), ZLIB_ENCODING_DEFLATE); + $compressed = zlib_encode(json_encode($payload), \ZLIB_ENCODING_DEFLATE); $suffix = rtrim(strtr(base64_encode($compressed), '+/', '-_'), '='); diff --git a/DependencyInjection/WorkflowValidatorPass.php b/DependencyInjection/WorkflowValidatorPass.php index 60072ef..d1e4622 100644 --- a/DependencyInjection/WorkflowValidatorPass.php +++ b/DependencyInjection/WorkflowValidatorPass.php @@ -14,7 +14,6 @@ use Symfony\Component\Config\Resource\FileResource; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Exception\LogicException; /** * @author Grégoire Pineau diff --git a/Tests/Dumper/MermaidDumperTest.php b/Tests/Dumper/MermaidDumperTest.php index 3a29da6..a8d1978 100644 --- a/Tests/Dumper/MermaidDumperTest.php +++ b/Tests/Dumper/MermaidDumperTest.php @@ -104,7 +104,7 @@ public static function provideWorkflowDefinitionWithoutMarking(): iterable ."transition4-->place6\n" ."transition5[\"t6\"]\n" ."place5-->transition5\n" - ."transition5-->place6", + .'transition5-->place6', ]; yield [ self::createWorkflowWithSameNameTransition(), @@ -124,7 +124,7 @@ public static function provideWorkflowDefinitionWithoutMarking(): iterable ."transition2-->place0\n" ."transition3[\"to_a\"]\n" ."place2-->transition3\n" - ."transition3-->place0", + .'transition3-->place0', ]; yield [ self::createSimpleWorkflowDefinition(), @@ -140,7 +140,7 @@ public static function provideWorkflowDefinitionWithoutMarking(): iterable ."linkStyle 1 stroke:Grey\n" ."transition1[\"t2\"]\n" ."place1-->transition1\n" - ."transition1-->place2", + .'transition1-->place2', ]; } @@ -169,7 +169,7 @@ public static function provideWorkflowWithReservedWords(): iterable ."place1-->transition0\n" ."transition1[\"t1\"]\n" ."place2-->transition1\n" - ."transition1-->place3", + .'transition1-->place3', ]; } @@ -186,7 +186,7 @@ public static function provideStateMachine(): iterable ."place3-->|\"My custom transition label 3\"|place1\n" ."linkStyle 1 stroke:Grey\n" ."place1-->|\"t2\"|place2\n" - ."place1-->|\"t3\"|place3", + .'place1-->|"t3"|place3', ]; } @@ -212,7 +212,7 @@ public static function provideWorkflowWithMarking(): iterable ."linkStyle 1 stroke:Grey\n" ."transition1[\"t2\"]\n" ."place1-->transition1\n" - ."transition1-->place2", + .'transition1-->place2', ]; } } From ac5d26747d123060562468e77295549461d0d511 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 21 Jul 2025 19:38:14 +0200 Subject: [PATCH 05/11] Declare new parameters on interfaces and methods explicitly --- CHANGELOG.md | 1 + Marking.php | 12 ++---------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b6e1777..3ae763b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ CHANGELOG 8.0 --- + * Add `$nbToken` argument to `Marking::mark()` and `Marking::unmark()` * Remove `Event::getWorkflow()` method *Before* diff --git a/Marking.php b/Marking.php index c3629a2..a09d848 100644 --- a/Marking.php +++ b/Marking.php @@ -32,14 +32,10 @@ public function __construct(array $representation = []) } /** - * @param int $nbToken - * * @psalm-param int<1, max> $nbToken */ - public function mark(string $place /* , int $nbToken = 1 */): void + public function mark(string $place, int $nbToken = 1): void { - $nbToken = 1 < \func_num_args() ? func_get_arg(1) : 1; - if ($nbToken < 1) { throw new \InvalidArgumentException(\sprintf('The number of tokens must be greater than 0, "%s" given.', $nbToken)); } @@ -49,14 +45,10 @@ public function mark(string $place /* , int $nbToken = 1 */): void } /** - * @param int $nbToken - * * @psalm-param int<1, max> $nbToken */ - public function unmark(string $place /* , int $nbToken = 1 */): void + public function unmark(string $place, int $nbToken = 1): void { - $nbToken = 1 < \func_num_args() ? func_get_arg(1) : 1; - if ($nbToken < 1) { throw new \InvalidArgumentException(\sprintf('The number of tokens must be greater than 0, "%s" given.', $nbToken)); } From c6580d0fb66e274d8b5c232a99ce0f3c0e71d38b Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Wed, 9 Oct 2024 11:06:51 +0200 Subject: [PATCH 06/11] run tests using PHPUnit 11.5 --- phpunit.xml.dist | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 15e5deb..f4d8267 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,10 +1,11 @@ @@ -18,7 +19,7 @@ - + ./ @@ -26,5 +27,9 @@ ./Tests ./vendor - + + + + + From 699c2abd97535ae4ea6cd8c04807731e82a617f8 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Thu, 31 Jul 2025 14:36:46 +0200 Subject: [PATCH 07/11] replace PHPUnit annotations with attributes --- Tests/Attribute/AsListenerTest.php | 13 ++++--------- Tests/Debug/TraceableWorkflowTest.php | 5 ++--- Tests/Dumper/GraphvizDumperTest.php | 9 +++------ Tests/Dumper/MermaidDumperTest.php | 17 +++++------------ Tests/Dumper/PlantUmlDumperTest.php | 9 +++------ Tests/Event/EventNameTraitTest.php | 4 ++-- Tests/WorkflowTest.php | 12 +++++------- 7 files changed, 24 insertions(+), 45 deletions(-) diff --git a/Tests/Attribute/AsListenerTest.php b/Tests/Attribute/AsListenerTest.php index 0a8c232..b2a7440 100644 --- a/Tests/Attribute/AsListenerTest.php +++ b/Tests/Attribute/AsListenerTest.php @@ -11,15 +11,14 @@ namespace Symfony\Component\Workflow\Tests\Attribute; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Symfony\Component\Workflow\Attribute; use Symfony\Component\Workflow\Exception\LogicException; class AsListenerTest extends TestCase { - /** - * @dataProvider provideOkTests - */ + #[DataProvider('provideOkTests')] public function testOk(string $class, string $expectedEvent, ?string $workflow = null, ?string $node = null) { $attribute = new $class($workflow, $node); @@ -58,9 +57,7 @@ public static function provideOkTests(): iterable yield [Attribute\AsTransitionListener::class, 'workflow.w.transition.n', 'w', 'n']; } - /** - * @dataProvider provideTransitionThrowException - */ + #[DataProvider('provideTransitionThrowException')] public function testTransitionThrowException(string $class) { $this->expectException(LogicException::class); @@ -77,9 +74,7 @@ public static function provideTransitionThrowException(): iterable yield [Attribute\AsTransitionListener::class, 'workflow.transition']; } - /** - * @dataProvider providePlaceThrowException - */ + #[DataProvider('providePlaceThrowException')] public function testPlaceThrowException(string $class) { $this->expectException(LogicException::class); diff --git a/Tests/Debug/TraceableWorkflowTest.php b/Tests/Debug/TraceableWorkflowTest.php index 257ad66..d513450 100644 --- a/Tests/Debug/TraceableWorkflowTest.php +++ b/Tests/Debug/TraceableWorkflowTest.php @@ -11,6 +11,7 @@ namespace Symfony\Component\Workflow\Tests\Debug; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Symfony\Component\Stopwatch\Stopwatch; @@ -38,9 +39,7 @@ protected function setUp(): void ); } - /** - * @dataProvider provideFunctionNames - */ + #[DataProvider('provideFunctionNames')] public function testCallsInner(string $function, array $args, mixed $returnValue) { $this->innerWorkflow->expects($this->once()) diff --git a/Tests/Dumper/GraphvizDumperTest.php b/Tests/Dumper/GraphvizDumperTest.php index 9356715..228c496 100644 --- a/Tests/Dumper/GraphvizDumperTest.php +++ b/Tests/Dumper/GraphvizDumperTest.php @@ -11,6 +11,7 @@ namespace Symfony\Component\Workflow\Tests\Dumper; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Symfony\Component\Workflow\Dumper\GraphvizDumper; use Symfony\Component\Workflow\Marking; @@ -20,9 +21,7 @@ class GraphvizDumperTest extends TestCase { use WorkflowBuilderTrait; - /** - * @dataProvider provideWorkflowDefinitionWithoutMarking - */ + #[DataProvider('provideWorkflowDefinitionWithoutMarking')] public function testDumpWithoutMarking($definition, $expected, $withMetadata) { $dump = (new GraphvizDumper())->dump($definition, null, ['with-metadata' => $withMetadata]); @@ -30,9 +29,7 @@ public function testDumpWithoutMarking($definition, $expected, $withMetadata) $this->assertEquals($expected, $dump); } - /** - * @dataProvider provideWorkflowDefinitionWithMarking - */ + #[DataProvider('provideWorkflowDefinitionWithMarking')] public function testDumpWithMarking($definition, $marking, $expected, $withMetadata) { $dump = (new GraphvizDumper())->dump($definition, $marking, ['with-metadata' => $withMetadata]); diff --git a/Tests/Dumper/MermaidDumperTest.php b/Tests/Dumper/MermaidDumperTest.php index a8d1978..639f67c 100644 --- a/Tests/Dumper/MermaidDumperTest.php +++ b/Tests/Dumper/MermaidDumperTest.php @@ -11,6 +11,7 @@ namespace Symfony\Component\Workflow\Tests\Dumper; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Symfony\Component\Workflow\Definition; use Symfony\Component\Workflow\DefinitionBuilder; @@ -23,9 +24,7 @@ class MermaidDumperTest extends TestCase { use WorkflowBuilderTrait; - /** - * @dataProvider provideWorkflowDefinitionWithoutMarking - */ + #[DataProvider('provideWorkflowDefinitionWithoutMarking')] public function testDumpWithoutMarking(Definition $definition, string $expected) { $dumper = new MermaidDumper(MermaidDumper::TRANSITION_TYPE_WORKFLOW); @@ -35,9 +34,7 @@ public function testDumpWithoutMarking(Definition $definition, string $expected) $this->assertEquals($expected, $dump); } - /** - * @dataProvider provideWorkflowWithReservedWords - */ + #[DataProvider('provideWorkflowWithReservedWords')] public function testDumpWithReservedWordsAsPlacenames(Definition $definition, string $expected) { $dumper = new MermaidDumper(MermaidDumper::TRANSITION_TYPE_WORKFLOW); @@ -47,9 +44,7 @@ public function testDumpWithReservedWordsAsPlacenames(Definition $definition, st $this->assertEquals($expected, $dump); } - /** - * @dataProvider provideStateMachine - */ + #[DataProvider('provideStateMachine')] public function testDumpAsStateMachine(Definition $definition, string $expected) { $dumper = new MermaidDumper(MermaidDumper::TRANSITION_TYPE_STATEMACHINE); @@ -59,9 +54,7 @@ public function testDumpAsStateMachine(Definition $definition, string $expected) $this->assertEquals($expected, $dump); } - /** - * @dataProvider provideWorkflowWithMarking - */ + #[DataProvider('provideWorkflowWithMarking')] public function testDumpWorkflowWithMarking(Definition $definition, Marking $marking, string $expected) { $dumper = new MermaidDumper(MermaidDumper::TRANSITION_TYPE_WORKFLOW); diff --git a/Tests/Dumper/PlantUmlDumperTest.php b/Tests/Dumper/PlantUmlDumperTest.php index a018a4e..838c9bd 100644 --- a/Tests/Dumper/PlantUmlDumperTest.php +++ b/Tests/Dumper/PlantUmlDumperTest.php @@ -11,6 +11,7 @@ namespace Symfony\Component\Workflow\Tests\Dumper; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Symfony\Component\Workflow\Definition; use Symfony\Component\Workflow\Dumper\PlantUmlDumper; @@ -23,9 +24,7 @@ class PlantUmlDumperTest extends TestCase { use WorkflowBuilderTrait; - /** - * @dataProvider provideWorkflowDefinitionWithoutMarking - */ + #[DataProvider('provideWorkflowDefinitionWithoutMarking')] public function testDumpWorkflowWithoutMarking($definition, $marking, $expectedFileName, $title) { $dumper = new PlantUmlDumper(PlantUmlDumper::WORKFLOW_TRANSITION); @@ -46,9 +45,7 @@ public static function provideWorkflowDefinitionWithoutMarking(): \Generator yield [self::createComplexWorkflowDefinition(), $marking, 'complex-workflow-marking', 'ComplexDiagram']; } - /** - * @dataProvider provideStateMachineDefinitionWithoutMarking - */ + #[DataProvider('provideStateMachineDefinitionWithoutMarking')] public function testDumpStateMachineWithoutMarking($definition, $marking, $expectedFileName, $title) { $dumper = new PlantUmlDumper(PlantUmlDumper::STATEMACHINE_TRANSITION); diff --git a/Tests/Event/EventNameTraitTest.php b/Tests/Event/EventNameTraitTest.php index 3c74523..24780f4 100644 --- a/Tests/Event/EventNameTraitTest.php +++ b/Tests/Event/EventNameTraitTest.php @@ -11,6 +11,7 @@ namespace Symfony\Component\Workflow\Tests\Event; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Symfony\Component\Workflow\Event\AnnounceEvent; use Symfony\Component\Workflow\Event\CompletedEvent; @@ -23,10 +24,9 @@ class EventNameTraitTest extends TestCase { /** - * @dataProvider getEvents - * * @param class-string $class */ + #[DataProvider('getEvents')] public function testEventNames(string $class, ?string $workflowName, ?string $transitionOrPlaceName, string $expected) { $name = $class::getName($workflowName, $transitionOrPlaceName); diff --git a/Tests/WorkflowTest.php b/Tests/WorkflowTest.php index 48e2209..6d12a7c 100644 --- a/Tests/WorkflowTest.php +++ b/Tests/WorkflowTest.php @@ -11,6 +11,8 @@ namespace Symfony\Component\Workflow\Tests; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\TestWith; use PHPUnit\Framework\TestCase; use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\Workflow\Definition; @@ -439,9 +441,7 @@ public static function provideApplyWithEventDispatcherForAnnounceTests(): \Gener yield [true, []]; } - /** - * @dataProvider provideApplyWithEventDispatcherForAnnounceTests - */ + #[DataProvider('provideApplyWithEventDispatcherForAnnounceTests')] public function testApplyWithEventDispatcherForAnnounce(bool $fired, array $context) { $definition = $this->createComplexWorkflowDefinition(); @@ -820,10 +820,8 @@ public function testGetEnabledTransitionsWithSameNameTransition() $this->assertSame('to_a', $transitions[2]->getName()); } - /** - * @@testWith ["back1"] - * ["back2"] - */ + #[TestWith(['back1'])] + #[TestWith(['back2'])] public function testApplyWithSameNameBackTransition(string $transition) { $definition = $this->createWorkflowWithSameNameBackTransition(); From cefb2f2ed26a9111aa5f1b2d6b7119a9d6d04427 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 4 Aug 2025 09:53:42 +0200 Subject: [PATCH 08/11] CS fixes --- Tests/WorkflowTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Tests/WorkflowTest.php b/Tests/WorkflowTest.php index 6d12a7c..d44d2c6 100644 --- a/Tests/WorkflowTest.php +++ b/Tests/WorkflowTest.php @@ -29,6 +29,7 @@ use Symfony\Component\Workflow\TransitionBlocker; use Symfony\Component\Workflow\Workflow; use Symfony\Component\Workflow\WorkflowEvents; +use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; class WorkflowTest extends TestCase { @@ -876,7 +877,7 @@ private function assertPlaces(array $expected, Marking $marking) } } -class EventDispatcherMock implements \Symfony\Contracts\EventDispatcher\EventDispatcherInterface +class EventDispatcherMock implements EventDispatcherInterface { public array $dispatchedEvents = []; From 679d40c7a3a00056678da55d69b781be35cee3c7 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 4 Aug 2025 14:33:15 +0200 Subject: [PATCH 09/11] [Ldap][Messenger][Validator][Workflow] Add methods to interfaces as planned --- CHANGELOG.md | 1 + WorkflowInterface.php | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ae763b..3ae8f62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ CHANGELOG 8.0 --- + * Add method `getEnabledTransition()` to `WorkflowInterface` * Add `$nbToken` argument to `Marking::mark()` and `Marking::unmark()` * Remove `Event::getWorkflow()` method diff --git a/WorkflowInterface.php b/WorkflowInterface.php index 6f5bff2..b63e02c 100644 --- a/WorkflowInterface.php +++ b/WorkflowInterface.php @@ -20,8 +20,6 @@ * Describes a workflow instance. * * @author Amrouche Hamza - * - * @method Transition|null getEnabledTransition(object $subject, string $name) */ interface WorkflowInterface { @@ -58,6 +56,8 @@ public function apply(object $subject, string $transitionName, array $context = */ public function getEnabledTransitions(object $subject): array; + public function getEnabledTransition(object $subject, string $name): ?Transition; + public function getName(): string; public function getDefinition(): Definition; From 007fb4b0277ec08577607d6472f532f66f656e2c Mon Sep 17 00:00:00 2001 From: Dariusz Ruminski Date: Sun, 10 Aug 2025 00:28:14 +0200 Subject: [PATCH 10/11] chore: heredoc indentation as of PHP 7.3 https://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc --- .../Dumper/StateMachineGraphvizDumperTest.php | 68 +++++++++---------- Tests/WorkflowBuilderTrait.php | 6 +- 2 files changed, 37 insertions(+), 37 deletions(-) diff --git a/Tests/Dumper/StateMachineGraphvizDumperTest.php b/Tests/Dumper/StateMachineGraphvizDumperTest.php index 20b3694..52779e4 100644 --- a/Tests/Dumper/StateMachineGraphvizDumperTest.php +++ b/Tests/Dumper/StateMachineGraphvizDumperTest.php @@ -27,23 +27,23 @@ public function testDumpWithoutMarking() $dump = (new StateMachineGraphvizDumper())->dump($definition); $expected = <<<'EOGRAPH' -digraph workflow { - ratio="compress" rankdir="LR" - node [fontsize="9" fontname="Arial" color="#333333" fillcolor="lightblue" fixedsize="false" width="1"]; - edge [fontsize="9" fontname="Arial" color="#333333" arrowhead="normal" arrowsize="0.5"]; - - place_86f7e437faa5a7fce15d1ddcb9eaeaea377667b8 [label="a", shape=circle style="filled"]; - place_e9d71f5ee7c92d6dc9e92ffdad17b8bd49418f98 [label="b", shape=circle]; - place_84a516841ba77a5b4648de2cd0dfcb30ea46dbb4 [label="c", shape=circle]; - place_3c363836cf4e16666669a25da280a1865c2d2874 [label="d", shape=circle]; - place_86f7e437faa5a7fce15d1ddcb9eaeaea377667b8 -> place_e9d71f5ee7c92d6dc9e92ffdad17b8bd49418f98 [label="t1" style="solid"]; - place_3c363836cf4e16666669a25da280a1865c2d2874 -> place_e9d71f5ee7c92d6dc9e92ffdad17b8bd49418f98 [label="My custom transition -label 3" style="solid" fontcolor="Grey" color="Red"]; - place_e9d71f5ee7c92d6dc9e92ffdad17b8bd49418f98 -> place_84a516841ba77a5b4648de2cd0dfcb30ea46dbb4 [label="t2" style="solid" color="Blue"]; - place_e9d71f5ee7c92d6dc9e92ffdad17b8bd49418f98 -> place_3c363836cf4e16666669a25da280a1865c2d2874 [label="t3" style="solid"]; -} - -EOGRAPH; + digraph workflow { + ratio="compress" rankdir="LR" + node [fontsize="9" fontname="Arial" color="#333333" fillcolor="lightblue" fixedsize="false" width="1"]; + edge [fontsize="9" fontname="Arial" color="#333333" arrowhead="normal" arrowsize="0.5"]; + + place_86f7e437faa5a7fce15d1ddcb9eaeaea377667b8 [label="a", shape=circle style="filled"]; + place_e9d71f5ee7c92d6dc9e92ffdad17b8bd49418f98 [label="b", shape=circle]; + place_84a516841ba77a5b4648de2cd0dfcb30ea46dbb4 [label="c", shape=circle]; + place_3c363836cf4e16666669a25da280a1865c2d2874 [label="d", shape=circle]; + place_86f7e437faa5a7fce15d1ddcb9eaeaea377667b8 -> place_e9d71f5ee7c92d6dc9e92ffdad17b8bd49418f98 [label="t1" style="solid"]; + place_3c363836cf4e16666669a25da280a1865c2d2874 -> place_e9d71f5ee7c92d6dc9e92ffdad17b8bd49418f98 [label="My custom transition + label 3" style="solid" fontcolor="Grey" color="Red"]; + place_e9d71f5ee7c92d6dc9e92ffdad17b8bd49418f98 -> place_84a516841ba77a5b4648de2cd0dfcb30ea46dbb4 [label="t2" style="solid" color="Blue"]; + place_e9d71f5ee7c92d6dc9e92ffdad17b8bd49418f98 -> place_3c363836cf4e16666669a25da280a1865c2d2874 [label="t3" style="solid"]; + } + + EOGRAPH; $this->assertEquals($expected, $dump); } @@ -54,23 +54,23 @@ public function testDumpWithMarking() $marking = new Marking(['b' => 1]); $expected = <<<'EOGRAPH' -digraph workflow { - ratio="compress" rankdir="LR" - node [fontsize="9" fontname="Arial" color="#333333" fillcolor="lightblue" fixedsize="false" width="1"]; - edge [fontsize="9" fontname="Arial" color="#333333" arrowhead="normal" arrowsize="0.5"]; - - place_86f7e437faa5a7fce15d1ddcb9eaeaea377667b8 [label="a", shape=circle style="filled"]; - place_e9d71f5ee7c92d6dc9e92ffdad17b8bd49418f98 [label="b", shape=circle color="#FF0000" shape="doublecircle"]; - place_84a516841ba77a5b4648de2cd0dfcb30ea46dbb4 [label="c", shape=circle]; - place_3c363836cf4e16666669a25da280a1865c2d2874 [label="d", shape=circle]; - place_86f7e437faa5a7fce15d1ddcb9eaeaea377667b8 -> place_e9d71f5ee7c92d6dc9e92ffdad17b8bd49418f98 [label="t1" style="solid"]; - place_3c363836cf4e16666669a25da280a1865c2d2874 -> place_e9d71f5ee7c92d6dc9e92ffdad17b8bd49418f98 [label="My custom transition -label 3" style="solid" fontcolor="Grey" color="Red"]; - place_e9d71f5ee7c92d6dc9e92ffdad17b8bd49418f98 -> place_84a516841ba77a5b4648de2cd0dfcb30ea46dbb4 [label="t2" style="solid" color="Blue"]; - place_e9d71f5ee7c92d6dc9e92ffdad17b8bd49418f98 -> place_3c363836cf4e16666669a25da280a1865c2d2874 [label="t3" style="solid"]; -} - -EOGRAPH; + digraph workflow { + ratio="compress" rankdir="LR" + node [fontsize="9" fontname="Arial" color="#333333" fillcolor="lightblue" fixedsize="false" width="1"]; + edge [fontsize="9" fontname="Arial" color="#333333" arrowhead="normal" arrowsize="0.5"]; + + place_86f7e437faa5a7fce15d1ddcb9eaeaea377667b8 [label="a", shape=circle style="filled"]; + place_e9d71f5ee7c92d6dc9e92ffdad17b8bd49418f98 [label="b", shape=circle color="#FF0000" shape="doublecircle"]; + place_84a516841ba77a5b4648de2cd0dfcb30ea46dbb4 [label="c", shape=circle]; + place_3c363836cf4e16666669a25da280a1865c2d2874 [label="d", shape=circle]; + place_86f7e437faa5a7fce15d1ddcb9eaeaea377667b8 -> place_e9d71f5ee7c92d6dc9e92ffdad17b8bd49418f98 [label="t1" style="solid"]; + place_3c363836cf4e16666669a25da280a1865c2d2874 -> place_e9d71f5ee7c92d6dc9e92ffdad17b8bd49418f98 [label="My custom transition + label 3" style="solid" fontcolor="Grey" color="Red"]; + place_e9d71f5ee7c92d6dc9e92ffdad17b8bd49418f98 -> place_84a516841ba77a5b4648de2cd0dfcb30ea46dbb4 [label="t2" style="solid" color="Blue"]; + place_e9d71f5ee7c92d6dc9e92ffdad17b8bd49418f98 -> place_3c363836cf4e16666669a25da280a1865c2d2874 [label="t3" style="solid"]; + } + + EOGRAPH; $dump = (new StateMachineGraphvizDumper())->dump($definition, $marking); diff --git a/Tests/WorkflowBuilderTrait.php b/Tests/WorkflowBuilderTrait.php index 86478bb..99a07d7 100644 --- a/Tests/WorkflowBuilderTrait.php +++ b/Tests/WorkflowBuilderTrait.php @@ -129,9 +129,9 @@ private static function createComplexStateMachineDefinition(): Definition $transitionsMetadata = new \SplObjectStorage(); // PHP 7.2 doesn't allow this heredoc syntax in an array, use a dedicated variable instead $label = <<<'EOTXT' -My custom transition -label 3 -EOTXT; + My custom transition + label 3 + EOTXT; $transitionsMetadata[$transitionWithMetadataDumpStyle] = [ 'label' => $label, 'color' => 'Grey', From ab5a127df397ce2beea0966524afe8dc4db061cc Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Fri, 1 Aug 2025 14:58:41 +0200 Subject: [PATCH 11/11] run tests with PHPUnit 12.3 --- Tests/Attribute/AsListenerTest.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Tests/Attribute/AsListenerTest.php b/Tests/Attribute/AsListenerTest.php index b2a7440..0656574 100644 --- a/Tests/Attribute/AsListenerTest.php +++ b/Tests/Attribute/AsListenerTest.php @@ -68,10 +68,10 @@ public function testTransitionThrowException(string $class) public static function provideTransitionThrowException(): iterable { - yield [Attribute\AsAnnounceListener::class, 'workflow.announce']; - yield [Attribute\AsCompletedListener::class, 'workflow.completed']; - yield [Attribute\AsGuardListener::class, 'workflow.guard']; - yield [Attribute\AsTransitionListener::class, 'workflow.transition']; + yield [Attribute\AsAnnounceListener::class]; + yield [Attribute\AsCompletedListener::class]; + yield [Attribute\AsGuardListener::class]; + yield [Attribute\AsTransitionListener::class]; } #[DataProvider('providePlaceThrowException')] @@ -85,8 +85,8 @@ public function testPlaceThrowException(string $class) public static function providePlaceThrowException(): iterable { - yield [Attribute\AsEnteredListener::class, 'workflow.entered']; - yield [Attribute\AsEnterListener::class, 'workflow.enter']; - yield [Attribute\AsLeaveListener::class, 'workflow.leave']; + yield [Attribute\AsEnteredListener::class]; + yield [Attribute\AsEnterListener::class]; + yield [Attribute\AsLeaveListener::class]; } }