/**
  * Start a consumer that retrieved documents that have to be saved to the index.
  *
  * @param \Symfony\Component\Console\Input\InputInterface   $input
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  *
  * @return integer
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->queue->listen(function ($message) {
         if (strlen($message->body) == 0) {
             $this->queue->rejectMessage($message);
             return;
         }
         $data = json_decode($message->body, true);
         $this->indexer->prepareDocument($message);
         $this->queue->acknowledge($message);
     });
     return 1;
 }
 /**
  * @test
  * @testdox Tests if every 10 documents the index saves them.
  */
 public function ifEveryFiftyDocumentsAreSaved()
 {
     $solrQuery = $this->getMockBuilder('Solarium\\QueryType\\Update\\Query\\Query')->disableOriginalConstructor()->setMethods(null)->getMock();
     $solrClient = $this->getMockBuilder('Solarium\\Client')->setMethods(['createUpdate', 'update'])->getMock();
     $solrClient->expects($this->any())->method('createUpdate')->will($this->returnValue($solrQuery));
     $mapping = ['id' => 'id', 'groups' => ['SIM' => ['dummyKey1' => 'dummyKeySolr1'], 'DCTERMS' => ['dummyKey2' => 'dummyKeySolr2']]];
     $indexer = new Indexer($solrClient, $mapping, 50);
     for ($i = 0; $i <= 49; $i++) {
         $body = json_encode(['document' => ['id' => rand(0, 10), 'title' => sha1(rand(0, 10)), 'tstamp' => date('Y-m-d\\TH:i:s\\Z'), 'date' => date('Y-m-d\\TH:i:s\\Z'), 'publishedDate' => date('Y-m-d\\TH:i:s\\Z'), 'content' => str_repeat(sha1(rand(0, 10)), 5), 'url' => 'https://www.github.com', 'SIM.dummyKey1' => 'dummyvalue1', 'DCTERMS.dummyKey2' => 'dummyvalue2'], 'metadata' => ['core' => 'core1']]);
         $message = new AMQPMessage($body);
         $indexer->prepareDocument($message);
     }
 }