public function testRunJob() { $jobResult = $this->jobExecutor->executeJob(ProcessorRegistry::TYPE_IMPORT, MemberActivityConnector::JOB_IMPORT, [ProcessorRegistry::TYPE_IMPORT => ['channel' => $this->getReference('mailchimp:channel_1')->getId(), 'channelType' => $this->getReference('mailchimp:channel_1')->getType()]]); $this->assertTrue($jobResult->isSuccessful(), implode(',', $jobResult->getFailureExceptions())); $this->assertEquals(0, $jobResult->getContext()->getErrorEntriesCount(), implode(', ', $jobResult->getContext()->getErrors())); $this->assertDatabaseContent($jobResult); }
/** * @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()); }
/** * {@inheritdoc} */ protected function executeAction($context) { $jobType = $this->getJobType($context); $jobName = $this->getJobName($context); $configuration = $this->getConfiguration($context); $jobResult = $this->jobExecutor->executeJob($jobType, $jobName, $configuration); if (!$jobResult->isSuccessful() && $jobResult->getFailureExceptions()) { throw new \RuntimeException(implode(PHP_EOL, $jobResult->getFailureExceptions())); } $this->contextAccessor->setValue($context, $this->attribute, $jobResult); }
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); }
/** * @param string $jobType * @param string $jobName * @return JobResult */ protected function executePostProcessingJob($jobType, $jobName) { $clearSkipped = $this->jobExecutor->isSkipClear(); $this->jobExecutor->setSkipClear(true); $jobResult = $this->jobExecutor->executeJob($jobType, $jobName, $this->getJobConfiguration()); $this->jobExecutor->setSkipClear($clearSkipped); return $jobResult; }
public function testGetJobFailureExceptions() { $code = 'known'; $jobExecution = $this->getMockBuilder('Akeneo\\Bundle\\BatchBundle\\Entity\\JobExecution')->disableOriginalConstructor()->getMock(); $jobExecution->expects($this->once())->method('getAllFailureExceptions')->will($this->returnValue(array(array('message' => 'Error 1')))); $jobInstance = $this->getMockBuilder('Akeneo\\Bundle\\BatchBundle\\Entity\\JobInstance')->disableOriginalConstructor()->getMock(); $jobInstance->expects($this->once())->method('getJobExecutions')->will($this->returnValue(new ArrayCollection(array($jobExecution)))); $repository = $this->getMockBuilder('Doctrine\\ORM\\EntityRepository')->disableOriginalConstructor()->getMock(); $repository->expects($this->once())->method('findOneBy')->with(array('code' => $code))->will($this->returnValue($jobInstance)); $this->entityManager->expects($this->once())->method('getRepository')->with('AkeneoBatchBundle:JobInstance')->will($this->returnValue($repository)); $this->assertEquals(array('Error 1'), $this->executor->getJobFailureExceptions($code)); }
/** * @param string $jobType * @param string $jobName * @return JobResult */ protected function executePostProcessingJob($jobType, $jobName) { $jobResult = $this->jobExecutor->executeJob($jobType, $jobName, $this->getJobConfiguration()); return $jobResult; }
public function testSkipClear() { $this->assertFalse($this->executor->isSkipClear()); $this->executor->setSkipClear(true); $this->assertTrue($this->executor->isSkipClear()); }