Created
April 17, 2025 08:19
-
-
Save TomasVotruba/4e2a0aabed649346e17ed743b24a6cca to your computer and use it in GitHub Desktop.
[post] How we Maintain Dozens of Symfony Workflows with Ease
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
namespace Tests\Unit\Smoke; | |
use AppKernel; | |
use PHPUnit\Framework\TestCase; | |
use ReflectionProperty; | |
use Symfony\Component\DependencyInjection\ContainerInterface; | |
use Symfony\Component\Workflow\Dumper\MermaidDumper; | |
use Symfony\Component\Workflow\Registry; | |
use Symfony\Component\Workflow\StateMachine; | |
use Symfony\Component\Workflow\SupportStrategy\InstanceOfSupportStrategy; | |
final class SymfonyWorkflowsTest extends TestCase | |
{ | |
private static ContainerInterface $container; | |
protected function setUp(): void | |
{ | |
$appKernel = new AppKernel('dev', true); | |
$appKernel->boot(); | |
self::$container = $appKernel->getContainer(); | |
} | |
public function test(): void | |
{ | |
$workflowRegistry = self::$container->get('workflow.registry'); | |
$this->assertInstanceOf(Registry::class, $workflowRegistry); | |
/** @var Registry $workflowRegistry */ | |
$workflowsPropertyReflection = new ReflectionProperty($workflowRegistry, 'workflows'); | |
$workflows = $workflowsPropertyReflection->getValue($workflowRegistry); | |
$this->assertCount(100, $workflows); | |
// dump workflow to test config transition | |
// @see https://symfony.com/doc/current/workflow/dumping-workflows.html | |
$mermaidDumper = new MermaidDumper(MermaidDumper::TRANSITION_TYPE_STATEMACHINE); | |
$exactContents = ''; | |
foreach ($workflows as [$workflow, $supportStrategy]) { | |
$this->assertInstanceOf(StateMachine::class, $workflow); | |
$this->assertInstanceOf(InstanceOfSupportStrategy::class, $supportStrategy); | |
// compare exact definition before and after | |
$workflowDefinition = $workflow->getDefinition(); | |
$contents = $mermaidDumper->dump($workflowDefinition); | |
$exactContents .= $contents; | |
} | |
$exactHash = sha1($exactContents); | |
$this->assertSame('expectedHash', $exactHash); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment