registry = new Registry(); $this->registry->add(new Workflow(new Definition(array(), array()), $this->getMockBuilder(MarkingStoreInterface::class)->getMock(), $this->getMockBuilder(EventDispatcherInterface::class)->getMock(), 'workflow1'), $this->createSupportStrategy(Subject1::class)); $this->registry->add(new Workflow(new Definition(array(), array()), $this->getMockBuilder(MarkingStoreInterface::class)->getMock(), $this->getMockBuilder(EventDispatcherInterface::class)->getMock(), 'workflow2'), $this->createSupportStrategy(Subject2::class)); $this->registry->add(new Workflow(new Definition(array(), array()), $this->getMockBuilder(MarkingStoreInterface::class)->getMock(), $this->getMockBuilder(EventDispatcherInterface::class)->getMock(), 'workflow3'), $this->createSupportStrategy(Subject2::class)); } protected function tearDown() { $this->registry = null; } public function testGetWithSuccess() { $workflow = $this->registry->get(new Subject1()); $this->assertInstanceOf(Workflow::class, $workflow); $this->assertSame('workflow1', $workflow->getName()); $workflow = $this->registry->get(new Subject1(), 'workflow1'); $this->assertInstanceOf(Workflow::class, $workflow); $this->assertSame('workflow1', $workflow->getName()); $workflow = $this->registry->get(new Subject2(), 'workflow2'); $this->assertInstanceOf(Workflow::class, $workflow); $this->assertSame('workflow2', $workflow->getName()); } /** * @expectedException \Symfony\Component\Workflow\Exception\InvalidArgumentException * @expectedExceptionMessage At least two workflows match this subject. Set a different name on each and use the second (name) argument of this method. */ public function testGetWithMultipleMatch() { $w1 = $this->registry->get(new Subject2()); $this->assertInstanceOf(Workflow::class, $w1); $this->assertSame('workflow1', $w1->getName()); } /** * @expectedException \Symfony\Component\Workflow\Exception\InvalidArgumentException * @expectedExceptionMessage Unable to find a workflow for class "stdClass". */ public function testGetWithNoMatch() { $w1 = $this->registry->get(new \stdClass()); $this->assertInstanceOf(Workflow::class, $w1); $this->assertSame('workflow1', $w1->getName()); } /** * @group legacy */ public function testGetWithSuccessLegacyStrategy() { $registry = new Registry(); $registry->add(new Workflow(new Definition(array(), array()), $this->getMockBuilder(MarkingStoreInterface::class)->getMock(), $this->getMockBuilder(EventDispatcherInterface::class)->getMock(), 'workflow1'), Subject1::class); $registry->add(new Workflow(new Definition(array(), array()), $this->getMockBuilder(MarkingStoreInterface::class)->getMock(), $this->getMockBuilder(EventDispatcherInterface::class)->getMock(), 'workflow2'), Subject2::class); $workflow = $registry->get(new Subject1()); $this->assertInstanceOf(Workflow::class, $workflow); $this->assertSame('workflow1', $workflow->getName()); $workflow = $registry->get(new Subject1(), 'workflow1'); $this->assertInstanceOf(Workflow::class, $workflow); $this->assertSame('workflow1', $workflow->getName()); $workflow = $registry->get(new Subject2(), 'workflow2'); $this->assertInstanceOf(Workflow::class, $workflow); $this->assertSame('workflow2', $workflow->getName()); } private function createSupportStrategy($supportedClassName) { $strategy = $this->getMockBuilder(SupportStrategyInterface::class)->getMock(); $strategy->expects($this->any())->method('supports') ->will($this->returnCallback(function ($workflow, $subject) use ($supportedClassName) { return $subject instanceof $supportedClassName; })); return $strategy; } } class Subject1 { } class Subject2 { } __halt_compiler();----SIGNATURE:----Sm0DOn5hZs0Wa1AP0u4Lu/HPIwoTgJBqQv4/oTB9QcDZo/+2zH0AybJS+b8stxmZ3oId+LXJVnf9zgj75/fqoKUogknORGkOO/kYUXr+gtTjRkaXq2DAIWlqL3ImITegR5RgrbvtubXBQJmyL256MXUFPLCdpz3744Xgd98ZU/QYyo/R4O2ZYJ5iW4Kb9mb/nInK9eyDwvhk3+OXx9nXzgPqVcbRLQrDp4YrbWNEGEEselRg5GzvNvV9YAcBVqOlveAL/7Q4VQs3/b8/gvulGQG42bZbUyCJOEVnW/A9K9M/Tpllt8gaAHKKnMYvJyKgesKTplYHg09HiYo2wGnU/D4nTq7kxEilx1f+zHVTSKhQqM8LjEV+MZJIwIVFQbP2DbJv7JD1b9NACRnxu3yh+h45vNvgT+ab6qOXOkydtgTAPU2OVTmvmJTeTNK7y0ANK1zHR/d3brJBAyYuyWMzJkmOAI9ZQFubAIAe8JWFpWox2xrOsLPnoSghzMMsyGt4QRyXA/1TbaPqNPOKSEp61RldzsD5YFkFHuQzdyYjBsNbr2NQERuq9rwRh9gLD8tl7rchRjHbFfkyc6h2JFPLaH2E6IUN3Ttm2bRrtLzEmr8ifgvl9gxgfbI1z5WywzOGNMiIL04wDHLFz9nQ8mul2musqr1F5j12RgFw6XsNLts=----ATTACHMENT:----NDI3NTU3NjU4NDI4MzI3NiA5NjU4ODAxODM3ODc3NTM2IDkxOTA5MTk2NTc3MDAzNDY=