function it_returns_false_for_the_unsupported_job(ItemReaderInterface $reader, JobExecution $jobExecution, JobInstance $jobInstance, Job $job, ItemStep $step)
 {
     $jobExecution->getJobInstance()->willReturn($jobInstance);
     $jobExecution->getId()->willReturn(12);
     $jobInstance->getJob()->willReturn($job);
     $jobInstance->getType()->willReturn('type');
     $jobInstance->getAlias()->willReturn('alias');
     $job->getSteps()->willReturn([$step]);
     $step->getReader()->willReturn($reader);
     $this->supports($jobExecution)->shouldReturn(false);
 }
示例#2
0
 public function testDispatchWriteInvalidItemException()
 {
     $stepExecution = $this->getMockBuilder('Akeneo\\Bundle\\BatchBundle\\Entity\\StepExecution')->disableOriginalConstructor()->getMock();
     $stepExecution->expects($this->any())->method('getStatus')->will($this->returnValue(new BatchStatus(BatchStatus::STARTING)));
     $stepExecution->expects($this->any())->method('getExitStatus')->will($this->returnValue(new BatchStatus(BatchStatus::STARTED)));
     $this->eventDispatcher->expects($this->at(1))->method('dispatch')->with(EventInterface::INVALID_ITEM, $this->logicalAnd($this->isInstanceOf('Akeneo\\Bundle\\BatchBundle\\Event\\InvalidItemEvent'), $this->attributeEqualTo('reason', 'The written item is invalid'), $this->attributeEqualTo('item', array('foo' => 'bar'))));
     $reader = $this->getMock('Akeneo\\Bundle\\BatchBundle\\Tests\\Unit\\Step\\Stub\\ReaderStub');
     $reader->expects($this->exactly(2))->method('read')->will($this->onConsecutiveCalls($this->returnValue(array('foo' => 'bar')), $this->returnValue(null)));
     $processor = $this->getMock('Akeneo\\Bundle\\BatchBundle\\Tests\\Unit\\Item\\ItemProcessorTestHelper');
     $processor->expects($this->exactly(1))->method('process')->will($this->returnValue(array('foo' => 'bar')));
     $writer = $this->getMock('Akeneo\\Bundle\\BatchBundle\\Tests\\Unit\\Item\\ItemWriterTestHelper');
     $writer->expects($this->exactly(1))->method('write')->will($this->throwException(new InvalidItemException('The written item is invalid', array('foo' => 'bar'))));
     $writer->expects($this->any())->method('getName')->will($this->returnValue('stub_writer'));
     $this->itemStep->setReader($reader);
     $this->itemStep->setProcessor($processor);
     $this->itemStep->setWriter($writer);
     $stepExecution->expects($this->once())->method('addWarning')->with('stub_writer', 'The written item is invalid', array(), array('foo' => 'bar'));
     $this->itemStep->setBatchSize(5);
     $this->itemStep->execute($stepExecution);
 }
 function it_creates_a_file_if_writer_is_correct(CsvWriter $writer, JobExecution $jobExecution, JobInstance $jobInstance, Job $job, ItemStep $step, $factory, $filesystem)
 {
     $jobExecution->getJobInstance()->willReturn($jobInstance);
     $jobExecution->getId()->willReturn(12);
     $jobInstance->getJob()->willReturn($job);
     $jobInstance->getType()->willReturn('type');
     $jobInstance->getAlias()->willReturn('alias');
     $job->getSteps()->willReturn([$step]);
     $step->getWriter()->willReturn($writer);
     $writer->getWrittenFiles()->willReturn(['/tmp/tmp' => 'tmp', '/tmp/tmp2' => 'tmp2']);
     $writer->getPath()->willReturn('/tmp/tmp');
     $adapter = new LocalAdapter('/tmp');
     $fs = new Filesystem($adapter);
     $fs->write('tmp', '', true);
     $fs->write('tmp2', '', true);
     $factory->createZip(Argument::any())->willReturn($filesystem);
     $filesystem->write('tmp', '', true)->shouldBeCalled();
     $filesystem->write('tmp2', '', true)->shouldBeCalled();
     $this->archive($jobExecution);
 }
 function it_creates_a_file_if_writer_is_correct(CsvWriter $writer, JobExecution $jobExecution, JobInstance $jobInstance, Job $job, ItemStep $step, $factory, $filesystem)
 {
     $file1 = tempnam(sys_get_temp_dir(), 'spec');
     $file2 = tempnam(sys_get_temp_dir(), 'spec');
     $jobExecution->getJobInstance()->willReturn($jobInstance);
     $jobExecution->getId()->willReturn(12);
     $jobInstance->getJob()->willReturn($job);
     $jobInstance->getType()->willReturn('type');
     $jobInstance->getAlias()->willReturn('alias');
     $job->getSteps()->willReturn([$step]);
     $step->getWriter()->willReturn($writer);
     $writer->getWrittenFiles()->willReturn([$file1 => 'file1', $file2 => 'file2']);
     $writer->getPath()->willReturn(sys_get_temp_dir());
     $filesystem->has('type/alias/12/archive')->willReturn(false);
     $filesystem->createDir('type/alias/12/archive')->shouldBeCalled();
     $factory->createZip(Argument::any())->willReturn($filesystem);
     $filesystem->put('file1', '')->shouldBeCalled();
     $filesystem->put('file2', '')->shouldBeCalled();
     $this->archive($jobExecution);
     unlink($file1);
     unlink($file2);
 }
示例#5
0
 public function getItemStep($name, $reader, $processor, $writer)
 {
     $itemStep = new ItemStep($name);
     $itemStep->setReader($reader);
     $itemStep->setProcessor($processor);
     $itemStep->setWriter($writer);
     return $itemStep;
 }