/** * @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 testLoad() { $config = ['test' => true, ProcessorRegistry::TYPE_IMPORT => ['additional_config' => true]]; $expectedConfig = [ProcessorRegistry::TYPE_IMPORT => ['processorAlias' => $this->processorAlias, 'entityName' => '\\stdClass', 'channel' => 1, 'channelType' => 'mage', 'additional_config' => true], 'test' => true]; $this->connector->expects($this->once())->method('getImportEntityFQCN')->will($this->returnValue('\\stdClass')); $this->connector->expects($this->once())->method('getImportJobName')->will($this->returnValue('test_import')); $jobResult = $this->getMockBuilder('Oro\\Bundle\\ImportExportBundle\\Job\\JobResult')->disableOriginalConstructor()->getMock(); $jobResult->expects($this->once())->method('isSuccessful')->will($this->returnValue(true)); $this->jobExecutor->expects($this->once())->method('executeJob')->with(ProcessorRegistry::TYPE_IMPORT, 'test_import', $expectedConfig)->will($this->returnValue($jobResult)); /** @var \PHPUnit_Framework_MockObject_MockObject|Channel $channel */ $channel = $this->getMockBuilder('Oro\\Bundle\\IntegrationBundle\\Entity\\Channel')->disableOriginalConstructor()->getMock(); $channel->expects($this->once())->method('getId')->will($this->returnValue(1)); $channel->expects($this->once())->method('getType')->will($this->returnValue('mage')); $this->assertTrue($this->loader->load($channel, $config)); }
public function testExecute() { $options = ['jobType' => 'type', 'jobName' => new PropertyPath('a'), 'configuration' => ['c' => new PropertyPath('c'), 'd' => 'e'], 'attribute' => new PropertyPath('attr')]; $context = new \stdClass(); $context->a = 'name'; $context->c = 'test'; $context->attr = null; $jobResult = $this->getMockBuilder('Oro\\Bundle\\ImportExportBundle\\Job\\JobResult')->disableOriginalConstructor()->getMock(); $this->jobExecutor->expects($this->once())->method('executeJob')->with('type', 'name', ['c' => 'test', 'd' => 'e'])->will($this->returnValue($jobResult)); $this->action->initialize($options); $this->action->execute($context); $expectedContext = new \stdClass(); $expectedContext->a = 'name'; $expectedContext->c = 'test'; $expectedContext->attr = $jobResult; $this->assertEquals($expectedContext, $context); }