Skip to content

Commit 4f1f398

Browse files
committed
[FrameworkBundle][Workflow] Attach the workflow's configuration to the workflow tag
1 parent 4be3193 commit 4f1f398

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ CHANGELOG
1212
* Add `rate_limiter` tags to rate limiter services
1313
* Add `secrets:reveal` command
1414
* Add `rate_limiter` option to `http_client.default_options` and `http_client.scoped_clients`
15+
* Attach the workflow's configuration to the `workflow` tag
1516

1617
7.0
1718
---

DependencyInjection/FrameworkExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,7 @@ private function registerWorkflowConfiguration(array $config, ContainerBuilder $
10291029
$workflowDefinition->replaceArgument(3, $name);
10301030
$workflowDefinition->replaceArgument(4, $workflow['events_to_dispatch']);
10311031

1032-
$workflowDefinition->addTag('workflow', ['name' => $name]);
1032+
$workflowDefinition->addTag('workflow', ['name' => $name, 'metadata' => $workflow['metadata']]);
10331033
if ('workflow' === $type) {
10341034
$workflowDefinition->addTag('workflow.workflow', ['name' => $name]);
10351035
} elseif ('state_machine' === $type) {

Tests/DependencyInjection/FrameworkExtensionTestCase.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@
8484
use Symfony\Component\Validator\Validator\ValidatorInterface;
8585
use Symfony\Component\Webhook\Client\RequestParser;
8686
use Symfony\Component\Webhook\Controller\WebhookController;
87-
use Symfony\Component\Workflow;
8887
use Symfony\Component\Workflow\Exception\InvalidDefinitionException;
8988
use Symfony\Component\Workflow\Metadata\InMemoryMetadataStore;
9089
use Symfony\Component\Workflow\WorkflowEvents;
@@ -302,7 +301,15 @@ public function testWorkflows()
302301
$this->assertArrayHasKey('index_4', $args);
303302
$this->assertNull($args['index_4'], 'Workflows has eventsToDispatch=null');
304303

305-
$this->assertSame(['workflow' => [['name' => 'article']], 'workflow.workflow' => [['name' => 'article']]], $container->getDefinition('workflow.article')->getTags());
304+
$tags = $container->getDefinition('workflow.article')->getTags();
305+
$this->assertArrayHasKey('workflow', $tags);
306+
$this->assertArrayHasKey('workflow.workflow', $tags);
307+
$this->assertSame([['name' => 'article']], $tags['workflow.workflow']);
308+
$this->assertSame('article', $tags['workflow'][0]['name'] ?? null);
309+
$this->assertSame([
310+
'title' => 'article workflow',
311+
'description' => 'workflow for articles',
312+
], $tags['workflow'][0]['metadata'] ?? null);
306313

307314
$this->assertTrue($container->hasDefinition('workflow.article.definition'), 'Workflow definition is registered as a service');
308315

@@ -333,7 +340,14 @@ public function testWorkflows()
333340
$this->assertSame('state_machine.abstract', $container->getDefinition('state_machine.pull_request')->getParent());
334341
$this->assertTrue($container->hasDefinition('state_machine.pull_request.definition'), 'State machine definition is registered as a service');
335342

336-
$this->assertSame(['workflow' => [['name' => 'pull_request']], 'workflow.state_machine' => [['name' => 'pull_request']]], $container->getDefinition('state_machine.pull_request')->getTags());
343+
$tags = $container->getDefinition('state_machine.pull_request')->getTags();
344+
$this->assertArrayHasKey('workflow', $tags);
345+
$this->assertArrayHasKey('workflow.state_machine', $tags);
346+
$this->assertSame([['name' => 'pull_request']], $tags['workflow.state_machine']);
347+
$this->assertSame('pull_request', $tags['workflow'][0]['name'] ?? null);
348+
$this->assertSame([
349+
'title' => 'workflow title',
350+
], $tags['workflow'][0]['metadata'] ?? null);
337351

338352
$stateMachineDefinition = $container->getDefinition('state_machine.pull_request.definition');
339353

@@ -357,7 +371,7 @@ public function testWorkflows()
357371
$this->assertSame('state_machine.pull_request.metadata_store', (string) $metadataStoreReference);
358372

359373
$metadataStoreDefinition = $container->getDefinition('state_machine.pull_request.metadata_store');
360-
$this->assertSame(Workflow\Metadata\InMemoryMetadataStore::class, $metadataStoreDefinition->getClass());
374+
$this->assertSame(InMemoryMetadataStore::class, $metadataStoreDefinition->getClass());
361375
$this->assertSame(InMemoryMetadataStore::class, $metadataStoreDefinition->getClass());
362376

363377
$workflowMetadata = $metadataStoreDefinition->getArgument(0);

0 commit comments

Comments
 (0)