Skip to content

[Workflow] Allow spaces in place names so the PUML dump doesn't break #48738

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions src/Symfony/Component/Workflow/Dumper/PlantUmlDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace Symfony\Component\Workflow\Dumper;

use InvalidArgumentException;
use Symfony\Component\Workflow\Definition;
use Symfony\Component\Workflow\Marking;
use Symfony\Component\Workflow\Metadata\MetadataStoreInterface;
Expand Down Expand Up @@ -57,7 +56,7 @@ class PlantUmlDumper implements DumperInterface
public function __construct(string $transitionType = null)
{
if (!\in_array($transitionType, self::TRANSITION_TYPES, true)) {
throw new InvalidArgumentException("Transition type '$transitionType' does not exist.");
throw new \InvalidArgumentException("Transition type '$transitionType' does not exist.");
}
$this->transitionType = $transitionType;
}
Expand Down Expand Up @@ -209,9 +208,7 @@ private function getState(string $place, Definition $definition, Marking $markin

$description = $workflowMetadata->getMetadata('description', $place);
if (null !== $description) {
$output .= ' as '.$place.
\PHP_EOL.
$place.' : '.$description;
$output .= \PHP_EOL.$placeEscaped.' : '.$description;
}

return $output;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@
namespace Symfony\Component\Workflow\Tests\Dumper;

use PHPUnit\Framework\TestCase;
use Symfony\Component\Workflow\Definition;
use Symfony\Component\Workflow\Dumper\PlantUmlDumper;
use Symfony\Component\Workflow\Marking;
use Symfony\Component\Workflow\Metadata\InMemoryMetadataStore;
use Symfony\Component\Workflow\Tests\WorkflowBuilderTrait;
use Symfony\Component\Workflow\Transition;

class PlantUmlDumperTest extends TestCase
{
Expand Down Expand Up @@ -63,6 +66,34 @@ public function provideStateMachineDefinitionWithoutMarking()
yield [$this->createComplexStateMachineDefinition(), $marking, 'complex-state-machine-marking', 'SimpleDiagram'];
}

public function testDumpWorkflowWithSpacesInTheStateNamesAndDescription()
{
$dumper = new PlantUmlDumper(PlantUmlDumper::WORKFLOW_TRANSITION);

// The graph looks like:
//
// +---------+ t 1 +----------+ |
// | place a | -----> | place b | |
// +---------+ +----------+ |
$places = ['place a', 'place b'];

$transitions = [];
$transition = new Transition('t 1', 'place a', 'place b');
$transitions[] = $transition;

$placesMetadata = [];
$placesMetadata['place a'] = [
'description' => 'My custom place description',
];
$inMemoryMetadataStore = new InMemoryMetadataStore([], $placesMetadata);
$definition = new Definition($places, $transitions, null, $inMemoryMetadataStore);

$dump = $dumper->dump($definition, null, ['title' => 'SimpleDiagram']);
$dump = str_replace(\PHP_EOL, "\n", $dump.\PHP_EOL);
$file = $this->getFixturePath('simple-workflow-with-spaces', PlantUmlDumper::WORKFLOW_TRANSITION);
$this->assertStringEqualsFile($file, $dump);
}

private function getFixturePath($name, $transitionType)
{
return __DIR__.'/../fixtures/puml/'.$transitionType.'/'.$name.'.puml';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ skinparam agent {
}
state "a" <<initial>>
state "b" <<marked>>
state "c" <<DeepSkyBlue>> as c
c : My custom place description
state "c" <<DeepSkyBlue>>
"c" : My custom place description
agent "t1"
agent "t2"
"a" -[#Purple]-> "t1": "<font color=Grey>My custom transition label 2</font>"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ skinparam agent {
}
state "a" <<initial>>
state "b"
state "c" <<DeepSkyBlue>> as c
c : My custom place description
state "c" <<DeepSkyBlue>>
"c" : My custom place description
agent "t1"
agent "t2"
"a" -[#Purple]-> "t1": "<font color=Grey>My custom transition label 2</font>"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@startuml
allow_mixing
title SimpleDiagram
skinparam titleBorderRoundCorner 15
skinparam titleBorderThickness 2
skinparam state {
BackgroundColor<<initial>> #87b741
BackgroundColor<<marked>> #3887C6
BorderColor #3887C6
BorderColor<<marked>> Black
FontColor<<marked>> White
}
skinparam agent {
BackgroundColor #ffffff
BorderColor #3887C6
}
state "place a" <<initial>>
"place a" : My custom place description
state "place b"
agent "t 1"
"place a" --> "t 1"
"t 1" --> "place b"
@enduml