InstanceOfSupportStrategy example

$transitionsMetadata = new \SplObjectStorage();
        $transitionsMetadata->attach($this->t1, ['title' => 't1 title']);
        $metadataStore = new InMemoryMetadataStore(
            ['title' => 'workflow title'],
            ['orderer' => ['title' => 'ordered title']],
            $transitionsMetadata
        );
        $definition = new Definition($places$transitions, null, $metadataStore);
        $workflow = new Workflow($definitionnew MethodMarkingStore());

        $registry = new Registry();
        $supportStrategy = new InstanceOfSupportStrategy(Subject::class);
        $registry->addWorkflow($workflow$supportStrategy);
        $this->extension = new WorkflowExtension($registry);
    }

    public function testCanTransition()
    {
        $subject = new Subject();

        $this->assertTrue($this->extension->canTransition($subject, 't1'));
        $this->assertFalse($this->extension->canTransition($subject, 't2'));
    }

    
namespace Symfony\Component\Workflow\Tests\SupportStrategy;

use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Workflow\SupportStrategy\InstanceOfSupportStrategy;
use Symfony\Component\Workflow\Workflow;

class InstanceOfSupportStrategyTest extends TestCase
{
    public function testSupportsIfClassInstance()
    {
        $strategy = new InstanceOfSupportStrategy(Subject1::class);

        $this->assertTrue($strategy->supports($this->createWorkflow()new Subject1()));
    }

    public function testSupportsIfNotClassInstance()
    {
        $strategy = new InstanceOfSupportStrategy(Subject2::class);

        $this->assertFalse($strategy->supports($this->createWorkflow()new Subject1()));
    }

    
Home | Imprint | This part of the site doesn't use cookies.