createSimpleWorkflowDefinition example

use Symfony\Component\Workflow\MarkingStore\MethodMarkingStore;
use Symfony\Component\Workflow\Tests\Subject;
use Symfony\Component\Workflow\Tests\WorkflowBuilderTrait;
use Symfony\Component\Workflow\Workflow;

class AuditTrailListenerTest extends TestCase
{
    use WorkflowBuilderTrait;

    public function testItWorks()
    {
        $definition = $this->createSimpleWorkflowDefinition();

        $object = new Subject();

        $logger = new Logger();

        $ed = new EventDispatcher();
        $ed->addSubscriber(new AuditTrailListener($logger));

        $workflow = new Workflow($definitionnew MethodMarkingStore()$ed);

        $workflow->apply($object, 't1');

        
$subject->setMarking(['b' => 1]);
        $this->assertFalse($workflow->can($subject, 'a_to_bc'));
        $this->assertTrue($workflow->can($subject, 'b_to_c'));
        $this->assertTrue($workflow->can($subject, 'to_a'));
    }

    public function testBuildTransitionBlockerListReturnsUndefinedTransition()
    {
        $this->expectException(UndefinedTransitionException::class);
        $this->expectExceptionMessage('Transition "404 Not Found" is not defined for workflow "unnamed".');
        $definition = $this->createSimpleWorkflowDefinition();
        $subject = new Subject();
        $workflow = new Workflow($definitionnew MethodMarkingStore());

        $workflow->buildTransitionBlockerList($subject, '404 Not Found');
    }

    public function testBuildTransitionBlockerList()
    {
        $definition = $this->createComplexWorkflowDefinition();
        $subject = new Subject();
        $workflow = new Workflow($definitionnew MethodMarkingStore());

        

        $dumper = new PlantUmlDumper(PlantUmlDumper::WORKFLOW_TRANSITION);
        $dump = $dumper->dump($definition$marking['title' => $title]);
        // handle windows, and avoid to create more fixtures         $dump = str_replace(\PHP_EOL, "\n", $dump.\PHP_EOL);
        $file = $this->getFixturePath($expectedFileName, PlantUmlDumper::WORKFLOW_TRANSITION);
        $this->assertStringEqualsFile($file$dump);
    }

    public static function provideWorkflowDefinitionWithoutMarking(): \Generator
    {
        yield [self::createSimpleWorkflowDefinition(), null, 'simple-workflow-nomarking', 'SimpleDiagram'];
        yield [self::createComplexWorkflowDefinition(), null, 'complex-workflow-nomarking', 'ComplexDiagram'];
        $marking = new Marking(['b' => 1]);
        yield [self::createSimpleWorkflowDefinition()$marking, 'simple-workflow-marking', 'SimpleDiagram'];
        $marking = new Marking(['c' => 1, 'e' => 1]);
        yield [self::createComplexWorkflowDefinition()$marking, 'complex-workflow-marking', 'ComplexDiagram'];
    }

    /** * @dataProvider provideStateMachineDefinitionWithoutMarking */
    public function testDumpStateMachineWithoutMarking($definition$marking$expectedFileName$title)
    {
"transition1[\"b_to_c\"]\n"
            ."place1-->transition1\n"
            ."transition1-->place2\n"
            ."transition2[\"to_a\"]\n"
            ."place1-->transition2\n"
            ."transition2-->place0\n"
            ."transition3[\"to_a\"]\n"
            ."place2-->transition3\n"
            ."transition3-->place0",
        ];
        yield [
            self::createSimpleWorkflowDefinition(),
            "graph LR\n"
            ."place0([\"a\"])\n"
            ."place1((\"b\"))\n"
            ."place2((\"c\"))\n"
            ."style place2 fill:DeepSkyBlue\n"
            ."transition0[\"My custom transition label 2\"]\n"
            ."place0-->transition0\n"
            ."linkStyle 0 stroke:Grey\n"
            ."transition0-->place1\n"
            ."linkStyle 1 stroke:Grey\n"
            ."transition1[\"t2\"]\n"
            .

    public function testDumpWithMarking($definition$marking$expected$withMetadata)
    {
        $dump = (new GraphvizDumper())->dump($definition$marking['with-metadata' => $withMetadata]);

        $this->assertEquals($expected$dump);
    }

    public static function provideWorkflowDefinitionWithoutMarking(): \Generator
    {
        yield [self::createComplexWorkflowDefinition(), self::provideComplexWorkflowDumpWithoutMarking(), false];
        yield [self::createSimpleWorkflowDefinition(), self::provideSimpleWorkflowDumpWithoutMarking(), false];
        yield [self::createComplexWorkflowDefinition(), self::provideComplexWorkflowDumpWithoutMarkingWithMetadata(), true];
        yield [self::createSimpleWorkflowDefinition(), self::provideSimpleWorkflowDumpWithoutMarkingWithMetadata(), true];
    }

    public static function provideWorkflowDefinitionWithMarking(): \Generator
    {
        yield [
            self::createComplexWorkflowDefinition(),
            new Marking(['b' => 1]),
            self::createComplexWorkflowDefinitionDumpWithMarking(),
            false,
        ];
Home | Imprint | This part of the site doesn't use cookies.