public function testExecuteProcessorsFailure()
 {
     $processor1 = $this->getMock('Oro\\Component\\ChainProcessor\\ProcessorInterface');
     $processor2 = $this->getMock('Oro\\Component\\ChainProcessor\\ProcessorInterface');
     $factory = $this->getMock('Oro\\Component\\ChainProcessor\\ProcessorFactoryInterface');
     $factory->expects($this->exactly(2))->method('getProcessor')->willReturnOnConsecutiveCalls($processor1, $processor2);
     $processorBag = new ProcessorBag($factory);
     $processorBag->addGroup('group1', 'action1', 20);
     $processorBag->addGroup('group2', 'action1', 10);
     $processorBag->addProcessor('processor1', [], 'action1', 'group1', 20);
     $processorBag->addProcessor('processor2', [], 'action1', 'group2', 20);
     $processorBag->addProcessor('processor3', [], 'action1', 'group2', 10);
     $context = new Context();
     $context->setAction('action1');
     $processor1->expects($this->once())->method('process')->with($this->identicalTo($context));
     $processor2->expects($this->once())->method('process')->with($this->identicalTo($context))->willThrowException(new \Exception('Some error.'));
     $chainProcessor = new ChainProcessor($processorBag);
     try {
         $chainProcessor->process($context);
         $this->fail('An exception expected');
     } catch (ExecutionFailedException $e) {
         $this->assertEquals('Processor failed: "processor2". Reason: Some error.', $e->getMessage());
         $this->assertEquals('processor2', $e->getProcessorId());
         $this->assertEquals('action1', $e->getAction());
         $this->assertEquals('group2', $e->getGroup());
         $this->assertNotNull($e->getPrevious());
         $this->assertEquals('Some error.', $e->getPrevious()->getMessage());
     } catch (\Exception $e) {
         $this->fail(sprintf('ExecutionFailedException expected. Got: %s', get_class($e)));
     }
 }
 public function testMinEndingCommonProcessorPriority()
 {
     $this->processorBag->addGroup('group1', 'action1');
     $this->processorBag->addProcessor('processor1', [], 'action1', 'group1');
     $this->processorBag->addProcessor('processor2', [], null, null, -256);
     $context = new Context();
     $context->setAction('action1');
     $this->processorBag->getProcessors($context);
 }
 public function testGroupRangeApplicableCheckerWithLastGroupOnly()
 {
     $context = new Context();
     $context->setAction('action1');
     $context->setLastGroup('group5');
     $processorBag = new ProcessorBag($this->getProcessorFactory());
     $processorBag->addGroup('group1', 'action1', -10);
     $processorBag->addGroup('group2', 'action1', -20);
     $processorBag->addGroup('group4', 'action1', -30);
     $processorBag->addGroup('group3', 'action1', -40);
     $processorBag->addGroup('group5', 'action1', -50);
     $processorBag->addGroup('group6', 'action1', -60);
     $processorBag->addProcessor('processor1_no_action', []);
     $processorBag->addProcessor('processor2_no_action', [], null, null, -65536);
     $processorBag->addProcessor('processor1_no_group', [], 'action1');
     $processorBag->addProcessor('processor2_no_group', [], 'action1', null, -65280);
     $processorBag->addProcessor('processor1', [], 'action1', 'group1');
     $processorBag->addProcessor('processor2', [], 'action1', 'group2');
     $processorBag->addProcessor('processor3', [], 'action1', 'group3');
     $processorBag->addProcessor('processor4', [], 'action1', 'group4');
     $processorBag->addProcessor('processor5', [], 'action1', 'group5');
     $processorBag->addProcessor('processor6', [], 'action1', 'group6');
     $this->assertProcessors(['processor1_no_action', 'processor1_no_group', 'processor1', 'processor2', 'processor4', 'processor3', 'processor5', 'processor2_no_group', 'processor2_no_action'], $processorBag->getProcessors($context));
 }