/**
  * @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());
 }
 public function testGetSetExecutionContext()
 {
     $this->assertEquals(new ExecutionContext(), $this->stepExecution->getExecutionContext());
     $expectedExecutionContext = new ExecutionContext();
     $expectedExecutionContext->put('key', 'value');
     $this->assertEntity($this->stepExecution->setExecutionContext($expectedExecutionContext));
     $this->assertSame($expectedExecutionContext, $this->stepExecution->getExecutionContext());
 }
Esempio n. 3
0
 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));
 }
Esempio n. 4
0
 public function testInitializeAndRead()
 {
     /** @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));
     $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));
     $data = $this->getData();
     $this->executionContext->expects($this->once())->method('get')->will($this->returnValue($data));
     $stepExecution->expects($this->once())->method('getJobExecution')->will($this->returnValue($this->jobExecution));
     $reader = $this->getReader();
     $reader->setStepExecution($stepExecution);
     foreach ($data as $item) {
         $this->assertEquals($item, $reader->read());
     }
     $this->assertNull($reader->read());
 }