/** * 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."); } }
/** * Tests PipelineStarter. */ public function testPipelineStarter() { /** @var PipelineInterface|\PHPUnit_Framework_MockObject_MockObject $pipeline */ $pipeline = $this->getMockForAbstractClass('ONGR\\ConnectionsBundle\\Pipeline\\PipelineInterface'); $pipeline->expects($this->once())->method('start'); /** @var PipelineFactory|\PHPUnit_Framework_MockObject_MockObject $factory */ $factory = $this->getMock('ONGR\\ConnectionsBundle\\Pipeline\\PipelineFactory'); $factory->expects($this->once())->method('create')->with('prefix_target')->willReturn($pipeline); $starter = new PipelineStarter(); $starter->setPipelineFactory($factory); $starter->startPipeline('prefix_', 'target'); }
/** * Test event dispatching. */ public function testPipelineEventDispatching() { $pipelineName = 'some-target'; /** @var EventDispatcherInterface|MockObject $dispatcher */ $dispatcher = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface'); $dispatcher->expects($this->exactly(3))->method('dispatch')->withConsecutive(['ongr.pipeline.data_sync.' . $pipelineName . '.source', $this->anything()], ['ongr.pipeline.data_sync.' . $pipelineName . '.start', $this->anything()], ['ongr.pipeline.data_sync.' . $pipelineName . '.finish', $this->anything()], ['ongr.pipeline.data_sync.' . $pipelineName . '.consume', $this->anything()], ['ongr.pipeline.data_sync.' . $pipelineName . '.modify', $this->anything()]); $dataSyncService = new PipelineStarter(); $pipelineFactory = new PipelineFactory(); $pipelineFactory->setDispatcher($dispatcher); $pipelineFactory->setClassName('ONGR\\ConnectionsBundle\\Pipeline\\Pipeline'); $dataSyncService->setPipelineFactory($pipelineFactory); $dataSyncService->startPipeline('data_sync.', $pipelineName); }
/** * Test ongr:sync:storage:create behavior. */ public function testCommand() { $targetName = 'some-target'; $this->pipelineStarter->expects($this->once())->method('startPipeline')->with('data_sync.', $targetName); $container = new ContainerBuilder(); $container->set('ongr_connections.sync.data_sync_service', $this->pipelineStarter); $command = new SyncProvideCommand(); $command->setContainer($container); $application = new Application(); $application->add($command); $commandForTesting = $application->find('ongr:sync:provide'); $commandTester = new CommandTester($commandForTesting); $commandTester->execute(['command' => $command->getName(), 'target' => $targetName]); $this->assertContains('Job finished', $commandTester->getDisplay()); }