/**
  * Test ongr:repository-crawler:crawl progress helper behavior.
  */
 public function testCommandProgress()
 {
     $document1 = $this->getMockForAbstractClass('ONGR\\ElasticsearchBundle\\Document\\DocumentInterface');
     $source = $this->getMockForAbstractClass('ONGR\\ConnectionsBundle\\EventListener\\AbstractCrawlerSource');
     $modifier = $this->getMockForAbstractClass('ONGR\\ConnectionsBundle\\EventListener\\AbstractCrawlerModifier');
     $container = new ContainerBuilder();
     $command = new RepositoryCrawlerCommand();
     $command->setContainer($container);
     $input = $this->getMock('Symfony\\Component\\Console\\Input\\InputInterface');
     $input->expects($this->any())->method('getOption')->with('action-name')->will($this->returnValue('default'));
     $writes = 0;
     $callback = function () use(&$writes) {
         $writes++;
     };
     $output = $this->getMock('Symfony\\Component\\Console\\Output\\OutputInterface');
     $outputFormatter = $this->getMock('Symfony\\Component\\Console\\Formatter\\OutputFormatterInterface');
     $output->expects($this->any())->method('write')->will($this->returnCallback($callback));
     $output->expects($this->any())->method('isDecorated')->will($this->returnValue(true));
     $output->expects($this->any())->method('getFormatter')->will($this->returnValue($outputFormatter));
     $itemEvent = new ItemPipelineEvent($document1);
     $dispatcher = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface');
     $dispatcher->expects($this->exactly(3))->method('dispatch')->withConsecutive(['ongr.pipeline.repository_crawler.default.source', $this->anything()], ['ongr.pipeline.repository_crawler.default.start', $this->anything()], ['ongr.pipeline.repository_crawler.default.finish', $this->anything()], ['ongr.pipeline.repository_crawler.default.modify', $this->anything()])->willReturnOnConsecutiveCalls($this->returnValue($source->onSource(new SourcePipelineEvent())), $this->returnValue(null), $this->returnValue(null), $this->returnValue($modifier->onModify($itemEvent)));
     $pipelineFactory = new PipelineFactory();
     $pipelineFactory->setClassName('\\ONGR\\ConnectionsBundle\\Pipeline\\Pipeline');
     $pipelineFactory->setDispatcher($dispatcher);
     $crawler = new PipelineStarter();
     $crawler->setPipelineFactory($pipelineFactory);
     $container->set('ongr_connections.repository_crawler_service', $crawler);
     $command->run($input, $output);
     if ($writes < 2) {
         $this->fail("Console output was expected to be written at least 2 times, actually written {$writes} times.");
     }
 }
Example #2
0
 /**
  * Tests pipeline with progressbar.
  *
  * @param array $data
  * @param int   $expectedConsumedItems
  * @param int   $expectedSkippedItems
  *
  * @dataProvider PipelineData
  */
 public function testPipelineProgress($data, $expectedConsumedItems, $expectedSkippedItems)
 {
     $pipelineFactory = new PipelineFactory();
     $pipelineFactory->setDispatcher(new EventDispatcher());
     $pipelineFactory->setClassName('ONGR\\ConnectionsBundle\\Pipeline\\Pipeline');
     $expectedContext = 'This is a test of context';
     $progressBar = $this->getMockBuilder('Symfony\\Component\\Console\\Helper\\ProgressBar')->disableOriginalConstructor()->getMock();
     $progressBar->expects($this->once())->method('start');
     $progressBar->expects($this->exactly(count($data)))->method('advance');
     $progressBar->expects($this->once())->method('finish');
     $consumer = new PipelineTestConsumer();
     $source = function (SourcePipelineEvent $event) use($data, $expectedContext) {
         $event->addSource($data);
         $event->setContext($expectedContext);
     };
     $pipeline = $pipelineFactory->create('test', ['sources' => [$source], 'modifiers' => [[$this, 'onModify']], 'consumers' => [[$consumer, 'onConsume']]]);
     $pipeline->setProgressBar($progressBar);
     $pipeline->start();
     $this->assertEquals($expectedConsumedItems, $consumer->getConsumeCalled());
     $this->assertEquals($expectedSkippedItems, $consumer->getSkipCalled());
     $this->assertEquals($expectedContext, $pipeline->getContext());
 }
 /**
  * Test pipeline factory exception.
  *
  * @expectedException \InvalidArgumentException
  */
 public function testPipelineFactoryException()
 {
     $pipelineFactory = new PipelineFactory();
     $pipelineFactory->setClassName('ONGR\\ConnectionsBundle\\Pipeline\\Event\\SourcePipelineEvent');
     $pipelineFactory->create(null);
 }