/**
  * @param array $contextSharedKeys
  * @param array $context
  * @param array $job
  * @param bool $isJobSuccess
  * @param int $jobExecutions
  * @param array $expectedContext
  *
  * @dataProvider executeDataProvider
  */
 public function testExecute(array $contextSharedKeys, array $context, array $job, $isJobSuccess = true, $jobExecutions = 0, $expectedContext = [])
 {
     if ($job) {
         list($jobType, $jobName) = $job;
         $this->executor->addPostProcessingJob($jobType, $jobName);
     }
     $this->executor->setContextSharedKeys($contextSharedKeys);
     /** @var \PHPUnit_Framework_MockObject_MockObject|StepExecution $stepExecution */
     $stepExecution = $this->getMockBuilder('Akeneo\\Bundle\\BatchBundle\\Entity\\StepExecution')->disableOriginalConstructor()->getMock();
     $executionContext = new ExecutionContext();
     foreach ($context as $key => $value) {
         $executionContext->put($key, $value);
     }
     $jobExecution = $this->getMock('Akeneo\\Bundle\\BatchBundle\\Entity\\JobExecution');
     $jobInstance = $this->getMock('Akeneo\\Bundle\\BatchBundle\\Entity\\JobInstance');
     $jobExecution->expects($this->any())->method('getJobInstance')->will($this->returnValue($jobInstance));
     $jobExecution->expects($this->any())->method('getExecutionContext')->will($this->returnValue($executionContext));
     $stepExecution->expects($this->any())->method('getJobExecution')->will($this->returnValue($jobExecution));
     $this->executor->setStepExecution($stepExecution);
     $jobResult = new JobResult();
     $jobResult->setSuccessful($isJobSuccess);
     if (!$isJobSuccess) {
         $this->setExpectedException('Oro\\Bundle\\ImportExportBundle\\Exception\\RuntimeException');
     }
     $this->jobExecutor->expects($this->exactly($jobExecutions))->method('executeJob')->willReturn($jobResult);
     $this->processor->expects($this->any())->method('process')->willReturnArgument(0);
     $this->reader->expects($this->atLeastOnce())->method('read')->willReturnOnConsecutiveCalls(new \stdClass(), new \stdClass(), new \stdClass(), null);
     $this->executor->execute();
     $this->assertEquals($expectedContext, $executionContext->getKeys());
 }
 /**
  * @param mixed $readItem
  *
  * @return mixed processed item
  */
 protected function process($readItem)
 {
     try {
         return $this->processor->process($readItem);
     } catch (InvalidItemException $e) {
         $this->handleStepExecutionWarning($this->stepExecution, $this->processor, $e);
         return null;
     }
 }
示例#3
0
 /**
  * @param mixed                                     $readItem
  * @param StepExecutionWarningHandlerInterface|null $warningHandler
  *
  * @return mixed processed item
  */
 protected function process($readItem, StepExecutionWarningHandlerInterface $warningHandler = null)
 {
     try {
         return $this->processor->process($readItem);
     } catch (InvalidItemException $e) {
         $this->handleStepExecutionWarning($this->processor, $e, $warningHandler);
         return null;
     }
 }
示例#4
0
 /**
  * {@inheritdoc}
  */
 public function load($file)
 {
     $this->eventDispatcher->dispatch(static::EVENT_STARTED, new FixtureLoaderEvent($file));
     $this->reader->setFilePath($file);
     if ($this->multiple) {
         $items = $this->reader->read();
         foreach ($this->processor->process($items) as $object) {
             $this->persistObjects($object);
         }
     } else {
         while ($item = $this->reader->read()) {
             $this->persistObjects($this->processor->process($item));
         }
     }
     $this->objectManager->flush();
     $this->objectManager->clear();
     $this->doctrineCache->clear();
     $this->eventDispatcher->dispatch(static::EVENT_COMPLETED, new FixtureLoaderEvent($file));
 }