/** * {@inheritdoc} */ public function setStepExecution(StepExecution $stepExecution) { $this->stepExecution = $stepExecution; if (!$this->contextRegistry) { throw new \InvalidArgumentException('Missing ContextRegistry'); } $this->setImportExportContext($this->contextRegistry->getByStepExecution($this->stepExecution)); }
/** * @param StepExecution $stepExecution */ public function setStepExecution(StepExecution $stepExecution) { $this->stepExecution = $stepExecution; if ($this->strategy instanceof StepExecutionAwareInterface) { $this->strategy->setStepExecution($stepExecution); } $this->setImportExportContext($this->contextRegistry->getByStepExecution($this->stepExecution)); }
protected function setUp() { $this->contextRegistry = $this->getMockbuilder('Oro\\Bundle\\ImportExportBundle\\Context\\ContextRegistry')->disableOriginalConstructor()->getMock(); $this->context = $this->getMock('Oro\\Bundle\\ImportExportBundle\\Context\\ContextInterface'); $this->contextRegistry->expects($this->any())->method('getByStepExecution')->will($this->returnValue($this->context)); $this->stepExecution = $this->getMockBuilder('Akeneo\\Bundle\\BatchBundle\\Entity\\StepExecution')->disableOriginalConstructor()->getMock(); $this->reader = new ContextOptionReader($this->contextRegistry); }
/** * @expectedException \InvalidArgumentException * @expectedExceptionMessage Context key is missing */ public function testReadFailed() { $reader = $this->getReader(null); /** @var \PHPUnit_Framework_MockObject_MockObject|StepExecution $stepExecution */ $stepExecution = $this->getMockBuilder('Akeneo\\Bundle\\BatchBundle\\Entity\\StepExecution')->disableOriginalConstructor()->getMock(); $context = $this->getMock('Oro\\Bundle\\ImportExportBundle\\Context\\ContextInterface'); $this->contextRegistry->expects($this->once())->method('getByStepExecution')->with($stepExecution)->will($this->returnValue($context)); $reader->setStepExecution($stepExecution); }
/** * {@inheritdoc} */ public function setStepExecution(StepExecution $stepExecution) { $this->stepExecution = $stepExecution; if (!$this->contextRegistry) { throw new \InvalidArgumentException('Missing ContextRegistry'); } if ($this->strategy instanceof StepExecutionAwareInterface) { $this->strategy->setStepExecution($stepExecution); } $this->setImportExportContext($this->contextRegistry->getByStepExecution($this->stepExecution)); }
public function testGetByStepExecution() { $fooStepExecution = $this->createStepExecution(); $fooContext = $this->registry->getByStepExecution($fooStepExecution); $this->assertInstanceOf('Oro\\Bundle\\ImportExportBundle\\Context\\StepExecutionProxyContext', $fooContext); $this->assertAttributeEquals($fooStepExecution, 'stepExecution', $fooContext); $this->assertSame($fooContext, $this->registry->getByStepExecution($fooStepExecution)); $barStepExecution = $this->createStepExecution(); $barContext = $this->registry->getByStepExecution($barStepExecution); $this->assertNotSame($barContext, $fooContext); }
/** * {@inheritdoc} */ public function write(array $items) { foreach ($items as $item) { $this->entityManager->persist($item); $this->detachFixer->fixEntityAssociationFields($item, 1); } $this->entityManager->flush(); $configuration = $this->contextRegistry->getByStepExecution($this->stepExecution)->getConfiguration(); if (empty($configuration[self::SKIP_CLEAR])) { $this->entityManager->clear(); } }
public function testClassResolvedOnce() { /** @var StepExecution $stepExecution */ $stepExecution = $this->getMockBuilder('Akeneo\\Bundle\\BatchBundle\\Entity\\StepExecution')->disableOriginalConstructor()->getMock(); $context = $this->getMock('Oro\\Bundle\\ImportExportBundle\\Context\\ContextInterface'); $context->expects($this->once())->method('getConfiguration')->will($this->returnValue(['entityName' => '\\stdClass'])); $this->contextRegistry->expects($this->once())->method('getByStepExecution')->with($stepExecution)->will($this->returnValue($context)); $this->writer->setStepExecution($stepExecution); $this->writer->write([]); // trigger detection twice $this->writer->write([]); }
/** * @return array */ public function getConfig() { if (null === $this->config) { $this->config = $this->contextRegistry->getByStepExecution($this->stepExecution)->getConfiguration(); } return $this->config; }
/** * @param JobExecution $jobExecution * @return array */ protected function collectErrors(JobExecution $jobExecution) { $errors = array(); foreach ($jobExecution->getStepExecutions() as $stepExecution) { $errors = array_merge($errors, $this->contextRegistry->getByStepExecution($stepExecution)->getErrors()); } return $errors; }
/** * @return ProcessorInterface * @throws InvalidConfigurationException * @throws LogicException */ protected function getDelegateProcessor() { if (!$this->stepExecution) { throw new LogicException('Step execution entity must be injected to processor.'); } $context = $this->contextRegistry->getByStepExecution($this->stepExecution); if (!$context->getOption('processorAlias')) { throw new InvalidConfigurationException('Configuration of processor must contain "processorAlias" options.'); } $result = $this->processorRegistry->getProcessor($this->delegateType, $context->getOption('processorAlias')); if ($result instanceof ContextAwareInterface) { $result->setImportExportContext($context); } if ($result instanceof StepExecutionAwareInterface) { $result->setStepExecution($this->stepExecution); } return $result; }
protected function setUp() { $this->contextRegistry = $this->getMock('Oro\\Bundle\\ImportExportBundle\\Context\\ContextRegistry'); $this->logger = new LoggerStrategy(new NullLogger()); $this->contextMediator = $this->getMockBuilder('Oro\\Bundle\\IntegrationBundle\\Provider\\ConnectorContextMediator')->disableOriginalConstructor()->getMock(); $this->stepExecutionMock = $this->getMockBuilder('Akeneo\\Bundle\\BatchBundle\\Entity\\StepExecution')->disableOriginalConstructor()->getMock(); $this->context = $this->getMock('Oro\\Bundle\\ImportExportBundle\\Context\\ContextInterface'); $this->contextRegistry->expects($this->any())->method('getByStepExecution')->will($this->returnValue($this->context)); $channel = $this->getMock('Oro\\Bundle\\IntegrationBundle\\Entity\\Channel'); $transportSettings = $this->getMockForAbstractClass('Oro\\Bundle\\IntegrationBundle\\Entity\\Transport'); $channel->expects($this->any())->method('getTransport')->will($this->returnValue($transportSettings)); $this->transport = $this->getMock('OroCRM\\Bundle\\MagentoBundle\\Provider\\Transport\\MagentoTransportInterface'); $this->contextMediator->expects($this->any())->method('getInitializedTransport')->will($this->returnValue($this->transport)); $this->contextMediator->expects($this->any())->method('getChannel')->will($this->returnValue($channel)); $this->executionContext = $this->getMock('Akeneo\\Bundle\\BatchBundle\\Item\\ExecutionContext'); $this->jobExecution = $this->getMock('Akeneo\\Bundle\\BatchBundle\\Entity\\JobExecution'); $this->jobExecution->expects($this->any())->method('getExecutionContext')->will($this->returnValue($this->executionContext)); $this->stepExecutionMock->expects($this->once())->method('getJobExecution')->will($this->returnValue($this->jobExecution)); }
/** * {@inheritdoc} */ public function write(array $items) { /** @var EntityManager $em */ $em = $this->registry->getManager(); try { $em->beginTransaction(); foreach ($items as $item) { $em->persist($item); } $em->flush(); $em->commit(); $configuration = $this->contextRegistry->getByStepExecution($this->stepExecution)->getConfiguration(); $contextSkipClear = $this->stepExecution->getJobExecution()->getExecutionContext()->get(EntityWriter::SKIP_CLEAR); if (empty($configuration[EntityWriter::SKIP_CLEAR]) && !$contextSkipClear) { $em->clear(); } } catch (\Exception $exception) { $em->rollback(); if (!$em->isOpen()) { $this->registry->resetManager(); } $jobName = $this->stepExecution->getJobExecution()->getJobInstance()->getAlias(); $event = new WriterErrorEvent($items, $jobName, $exception); $this->eventDispatcher->dispatch(WriterErrorEvent::NAME, $event); if ($event->getCouldBeSkipped()) { $importContext = $this->contextRegistry->getByStepExecution($this->stepExecution); $importContext->setValue('error_entries_count', (int) $importContext->getValue('error_entries_count') + count($items)); $this->logger->warning($event->getWarning()); if ($event->getException() === $exception) { // exception are already handled and job can move forward throw new InvalidItemException($event->getWarning(), []); } else { // exception are already created and ready to be rethrown throw $event->getException(); } } else { throw $exception; } } $this->eventDispatcher->dispatch(WriterAfterFlushEvent::NAME, new WriterAfterFlushEvent($em)); }
/** * @dataProvider initializationDataProvider * * @param \PHPUnit_Framework_MockObject_MockObject|mixed $transport * @param null $source * @param bool|string $expectedException */ public function testInitialization($transport, $source = null, $expectedException = false) { $logger = new LoggerStrategy(new NullLogger()); $contextRegistry = new ContextRegistry(); $contextMediatorMock = $this->getMockBuilder('Oro\\Bundle\\IntegrationBundle\\Provider\\ConnectorContextMediator')->disableOriginalConstructor()->getMock(); $integration = new Integration(); $integration->setTransport($this->transportSettings); $context = $contextRegistry->getByStepExecution($this->stepExecutionMock); $contextMediatorMock->expects($this->at(0))->method('getTransport')->with($this->equalTo($context))->will($this->returnValue($transport)); $contextMediatorMock->expects($this->at(1))->method('getChannel')->with($this->equalTo($context))->will($this->returnValue($integration)); $connector = $this->getMockBuilder('Oro\\Bundle\\IntegrationBundle\\Provider\\AbstractConnector')->setMethods(['getConnectorSource'])->setConstructorArgs([$contextRegistry, $logger, $contextMediatorMock])->getMockForAbstractClass(); if (false !== $expectedException) { $this->setExpectedException($expectedException); } else { $transport->expects($this->once())->method('init')->with($this->equalTo($this->transportSettings)); $connector->expects($this->once())->method('getConnectorSource')->will($this->returnValue($source)); } $connector->setStepExecution($this->stepExecutionMock); $this->assertAttributeSame($transport, 'transport', $connector); $this->assertAttributeSame($integration, 'channel', $connector); }
/** * {@inheritdoc} */ public function setStepExecution(StepExecution $stepExecution) { $context = $this->contextRegistry->getByStepExecution($stepExecution); if (!$context->hasOption('filePath')) { throw new InvalidConfigurationException('Configuration of CSV writer must contain "filePath".'); } else { $this->setFilePath($context->getOption('filePath')); } if ($context->hasOption('delimiter')) { $this->delimiter = $context->getOption('delimiter'); } if ($context->hasOption('enclosure')) { $this->enclosure = $context->getOption('enclosure'); } if ($context->hasOption('firstLineIsHeader')) { $this->firstLineIsHeader = (bool) $context->getOption('firstLineIsHeader'); } if ($context->hasOption('header')) { $this->header = $context->getOption('header'); } }
/** * Set data to JobResult * TODO: Find a way to work with multiple amount of job and step executions * TODO https://magecore.atlassian.net/browse/BAP-2600 * * @param JobResult $jobResult * @param JobInstance $jobInstance */ protected function setJobResultData(JobResult $jobResult, JobInstance $jobInstance) { $jobResult->setJobId($jobInstance->getId()); $jobResult->setJobCode($jobInstance->getCode()); /** @var JobExecution $jobExecution */ $jobExecution = $jobInstance->getJobExecutions()->first(); if ($jobExecution) { $stepExecutions = $jobExecution->getStepExecutions(); /** @var StepExecution $firstStepExecution */ $firstStepExecution = $stepExecutions->first(); if ($firstStepExecution) { $context = $this->contextRegistry->getByStepExecution($firstStepExecution); if ($stepExecutions->count() > 1) { /** @var StepExecution $stepExecution */ foreach ($stepExecutions->slice(1) as $stepExecution) { ContextHelper::mergeContextCounters($context, $this->contextRegistry->getByStepExecution($stepExecution)); } } $jobResult->setContext($context); } } }
public function testGetByStepExecution() { $fooStepExecution = $this->createStepExecution(); $fooContext = $this->registry->getByStepExecution($fooStepExecution); $this->assertInstanceOf('Oro\\Bundle\\ImportExportBundle\\Context\\StepExecutionProxyContext', $fooContext); $this->assertAttributeEquals($fooStepExecution, 'stepExecution', $fooContext); $this->assertSame($fooContext, $this->registry->getByStepExecution($fooStepExecution)); $barStepExecution = $this->createStepExecution('job2'); $barContext = $this->registry->getByStepExecution($barStepExecution); $this->assertNotSame($barContext, $fooContext); /** @var \PHPUnit_Framework_MockObject_MockObject|JobInstance $jobInstance */ $jobInstance = $this->getMock('Akeneo\\Bundle\\BatchBundle\\Entity\\JobInstance'); $jobInstance->expects($this->any())->method('getAlias')->will($this->returnValue('job2')); $this->registry->clear($jobInstance); $barContext2 = $this->registry->getByStepExecution($barStepExecution); $this->assertNotSame($barContext, $barContext2); }
public function testSetStepExecution() { $this->processor->setContextRegistry($this->contextRegistry); $this->contextRegistry->expects($this->once())->method('getByStepExecution')->will($this->returnValue($this->context)); $this->processor->setStepExecution($this->stepExecution); }
/** * {@inheritdoc} */ public function setStepExecution(StepExecution $stepExecution) { $this->importExportContext = $this->contextRegistry->getByStepExecution($stepExecution); $this->setImportExportContext($this->importExportContext); }
/** * @return ContextInterface */ protected function getContext() { return $this->contextRegistry->getByStepExecution($this->getStepExecution()); }
/** * @param array $item */ protected function updateContext(array $item) { $context = $this->contextRegistry->getByStepExecution($this->stepExecution); $toDelete = (int) $context->getDeleteCount() + $this->getItemsToRemoveCount($item); $context->setValue('delete_count', $toDelete); }
/** * @param mixed $context * * @return \PHPUnit_Framework_MockObject_MockObject+ */ protected function getMockStepExecution($context) { $stepExecution = $this->getMockBuilder('Akeneo\\Bundle\\BatchBundle\\Entity\\StepExecution')->disableOriginalConstructor()->getMock(); $this->contextRegistry->expects($this->any())->method('getByStepExecution')->with($stepExecution)->will($this->returnValue($context)); return $stepExecution; }