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:----vddvQADRM3KTQrrffYaTcz1ebJCiIqO/0hhnAqoCVrYJEw7SR8rxO1jW4MdfxqfUV/mCHJc8l+mEHm3iyzAZCLdpC0Yi/gA6tk+iGnAL6VkLwNgW1sohri+o8mZWhyxL2a2khFCq+E9yEPeUZr7+7jhSyp5qkjxB59AGmyuHCxIPVuVcKnbnfomG/9bFaGXVR2+kKQRt5/jOIvAoanNDhDG6XTo6kVy0D0FgnMsD9MnHgQfNcoenaqsYF5Kdk7Y74MVEevTomKRB0hf6XP+tzzWPcjpsNXxZVj/dqaS4Lf/hxjbRZ8ryIZTkDeYByjxfKf2E++mF9V6uAWGHse131uq0m3eiMWGd5nQFMPCTgNy3CSEVqYQpFKgb+IMHJ89G+miZuRJiHP7iqWg67k0cLHBKLKbIYbAXSn6k1YPk3QL7S2U8yZ7oPq8m90nd137VHbH/tD+ElPhEiak/29/jqn5LNKrO2RA/QLcdAsIKO10Con5UfZzBA1EmmLaJhTk9/ee+rfcDY9I0BPvIkLP9GeQ2amQpXN4A24j0kN7eRO0bVqSchy8ipmoQ+PRbbp0i0edGE6AlrKxa8SzNz1gjthC9rxAGJNTqHnBRSJqKHqbZRm7uu38Ad5ip874nIg2AmLCVrfhbYBgezJETTEaTLREuRKWKs43MM22XnscaZ8A=----ATTACHMENT:----MzExNjAxMTIzNzcyNzEzNSAzNTMzNTc3MzMwMzcwMjUzIDU2NDY5OTczNDU3MDIwOTc=