Exemple #1
0
 /**
  * @param OutputInterface $output
  * @param string          $action
  */
 protected function dumpProcessors(OutputInterface $output, $action)
 {
     /** @var ProcessorBagInterface $processorBag */
     $processorBag = $this->getContainer()->get('oro_api.processor_bag');
     $table = new Table($output);
     $table->setHeaders(['Processor', 'Attributes']);
     $context = new Context();
     $context->setAction($action);
     $processors = $processorBag->getProcessors($context);
     $processors->setApplicableChecker(new ChainApplicableChecker());
     $i = 0;
     foreach ($processors as $processor) {
         if ($i > 0) {
             $table->addRow(new TableSeparator());
         }
         $processorColumn = sprintf('<comment>%s</comment>%s%s', $processors->getProcessorId(), PHP_EOL, get_class($processor));
         $processorDescription = $this->getClassDocComment(get_class($processor));
         if (!empty($processorDescription)) {
             $processorColumn .= PHP_EOL . $processorDescription;
         }
         $attributesColumn = $this->formatProcessorAttributes($processors->getProcessorAttributes());
         $table->addRow([$processorColumn, $attributesColumn]);
         $i++;
     }
     $table->render();
 }
 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 testSkipGroupApplicableChecker()
 {
     $context = new Context();
     $context->setAction('action1');
     $processors = ['action1' => [['processor' => 'processor1', 'attributes' => ['group' => 'group1']], ['processor' => 'processor2', 'attributes' => ['group' => 'group2']], ['processor' => 'processor3', 'attributes' => ['group' => 'group2']], ['processor' => 'processor4', 'attributes' => ['group' => 'group3']]]];
     $iterator = new ProcessorIterator($processors, $context, $this->getApplicableChecker(), $this->getProcessorFactory(['processor1' => function (ContextInterface $context) {
         $context->skipGroup('group2');
     }]));
     $this->assertProcessors(['processor1', 'processor4'], $iterator, $context);
 }
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testMatchApplicableCheckerWithCustomApplicableChecker()
 {
     $context = new Context();
     $context->setAction('action1');
     $context->set('class', 'TestCls');
     $context->set('type', 'test');
     $processors = ['action1' => [['processor' => 'processor1', 'attributes' => []], ['processor' => 'processor1_disabled', 'attributes' => ['disabled' => true]], ['processor' => 'processor2', 'attributes' => ['class' => 'TestCls']], ['processor' => 'processor2_disabled', 'attributes' => ['disabled' => true, 'class' => 'TestCls']], ['processor' => 'processor3', 'attributes' => ['type' => 'test']], ['processor' => 'processor3_disabled', 'attributes' => ['disabled' => true, 'type' => 'test']], ['processor' => 'processor4', 'attributes' => ['class' => 'TestCls', 'type' => 'test']], ['processor' => 'processor4_disabled', 'attributes' => ['disabled' => true, 'class' => 'TestCls', 'type' => 'test']], ['processor' => 'processor5', 'attributes' => ['class' => 'TestCls', 'type' => 'test', 'another' => 'val']], ['processor' => 'processor5_disabled', 'attributes' => ['disabled' => true, 'class' => 'TestCls', 'type' => 'test', 'another' => 'val']], ['processor' => 'processor6', 'attributes' => ['class' => 'AnotherCls']], ['processor' => 'processor6_disabled', 'attributes' => ['disabled' => true, 'class' => 'AnotherCls']], ['processor' => 'processor7', 'attributes' => ['type' => 'test']], ['processor' => 'processor7_disabled', 'attributes' => ['disabled' => true, 'type' => 'test']], ['processor' => 'processor8', 'attributes' => ['class' => 'AnotherCls', 'type' => 'test']], ['processor' => 'processor8_disabled', 'attributes' => ['disabled' => true, 'class' => 'AnotherCls', 'type' => 'test']], ['processor' => 'processor9', 'attributes' => ['class' => 'AnotherCls', 'type' => 'test', 'another' => 'val']], ['processor' => 'processor9_disabled', 'attributes' => ['disabled' => true, 'class' => 'AnotherCls', 'type' => 'test', 'another' => 'val']], ['processor' => 'processor10', 'attributes' => ['class' => 'TestCls']], ['processor' => 'processor10_disabled', 'attributes' => ['disabled' => true, 'class' => 'TestCls']], ['processor' => 'processor11', 'attributes' => ['type' => 'another']], ['processor' => 'processor11_disabled', 'attributes' => ['disabled' => true, 'type' => 'another']], ['processor' => 'processor12', 'attributes' => ['class' => 'TestCls', 'type' => 'another']], ['processor' => 'processor12_disabled', 'attributes' => ['disabled' => true, 'class' => 'TestCls', 'type' => 'another']], ['processor' => 'processor13', 'attributes' => ['class' => 'TestCls', 'type' => 'another', 'another' => 'val']], ['processor' => 'processor13_disabled', 'attributes' => ['disabled' => true, 'class' => 'TestCls', 'type' => 'another', 'another' => 'val']]]];
     $applicableChecker = $this->getApplicableChecker();
     $applicableChecker->addChecker(new NotDisabledApplicableChecker());
     $iterator = new ProcessorIterator($processors, $context, $applicableChecker, $this->getProcessorFactory());
     $this->assertProcessors(['processor1', 'processor2', 'processor3', 'processor4', 'processor5', 'processor7', 'processor10'], $iterator);
 }
 public function testServiceProperties()
 {
     $context = new Context();
     $context->setAction('action1');
     $processors = ['action1' => [['processor' => 'processor1', 'attributes' => ['group' => 'group1', 'attr1' => 'val1']], ['processor' => 'processor2', 'attributes' => ['group' => 'group2', 'attr1' => 'val1']]]];
     $iterator = new ProcessorIterator($processors, $context, new ChainApplicableChecker(), $this->getProcessorFactory());
     $iterator->rewind();
     $this->assertEquals('processor1', $iterator->getProcessorId());
     $this->assertEquals('action1', $iterator->getAction());
     $this->assertEquals('group1', $iterator->getGroup());
     $this->assertEquals(['group' => 'group1', 'attr1' => 'val1'], $iterator->getProcessorAttributes());
     $iterator->next();
     $this->assertEquals('processor2', $iterator->getProcessorId());
     $this->assertEquals('action1', $iterator->getAction());
     $this->assertEquals('group2', $iterator->getGroup());
     $this->assertEquals(['group' => 'group2', 'attr1' => 'val1'], $iterator->getProcessorAttributes());
 }
Exemple #6
0
 public function testResult()
 {
     $context = new Context();
     $this->assertFalse($context->hasResult());
     $this->assertNull($context->getResult());
     $context->setResult('test');
     $this->assertTrue($context->hasResult());
     $this->assertEquals('test', $context->getResult());
     $this->assertEquals('test', $context->get(Context::RESULT));
     $context->setResult(null);
     $this->assertTrue($context->hasResult());
     $context->removeResult();
     $this->assertFalse($context->hasResult());
 }
 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));
 }
 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);
 }