/** * @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); }
/** * @param OutputInterface $output * @param string $action * @param string[] $requestType */ protected function dumpProcessors(OutputInterface $output, $action, array $requestType) { $output->writeln('The processors are displayed in order they are executed.'); /** @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); if (!empty($requestType)) { $context->set('requestType', $requestType); } $processors = $processorBag->getProcessors($context); $applicableChecker = new ChainApplicableChecker(); $applicableChecker->addChecker(new RequestTypeApplicableChecker()); $processors->setApplicableChecker($applicableChecker); $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 testGenericMethods() { $context = new Context(); $this->assertFalse($context->has('test')); $this->assertFalse(isset($context['test'])); $this->assertNull($context->get('test')); $this->assertNull($context['test']); $context->set('test', 'value'); $this->assertTrue($context->has('test')); $this->assertTrue(isset($context['test'])); $this->assertEquals('value', $context->get('test')); $this->assertEquals('value', $context['test']); $context->remove('test'); $this->assertFalse($context->has('test')); $this->assertFalse(isset($context['test'])); $this->assertNull($context->get('test')); $this->assertNull($context['test']); $context['test1'] = 'value1'; $this->assertTrue($context->has('test1')); $this->assertTrue(isset($context['test1'])); $this->assertEquals('value1', $context->get('test1')); $this->assertEquals('value1', $context['test1']); unset($context['test1']); $this->assertFalse($context->has('test1')); $this->assertFalse(isset($context['test1'])); $this->assertNull($context->get('test1')); $this->assertNull($context['test1']); $context->set('test', null); $this->assertTrue($context->has('test')); $this->assertTrue(isset($context['test'])); $this->assertNull($context->get('test')); $this->assertNull($context['test']); $this->assertEquals(1, count($context)); $this->assertEquals(['test' => null], $context->toArray()); $context->clear(); $this->assertEquals(0, count($context)); }