public function testProcess()
 {
     $this->processor1->expects($this->any())->method('supports')->will($this->returnValue(true));
     $this->processor1->expects($this->any())->method('isLinked')->will($this->returnValue(true));
     $this->processor1->expects($this->once())->method('process');
     $this->processor2->expects($this->any())->method('supports')->will($this->returnValue(true));
     $this->processor2->expects($this->any())->method('isLinked')->will($this->returnValue(true));
     $this->processor2->expects($this->once())->method('process');
     $this->delegate->process(new SourceMock(123));
 }
 /**
  * @param array $payload Payload containing the source id
  *
  * @return boolean
  */
 public function execute(array $payload)
 {
     list($sourceId) = $payload;
     if (null === ($source = $this->findSource($sourceId))) {
         $this->getLogger()->info(sprintf('Could not find source with id %d', $sourceId));
         return false;
     }
     if ($source->isBlocked()) {
         $this->getLogger()->debug('Source is blocked');
         $this->processor->unlink($source);
         return false;
     }
     // reset messages
     $source->setMessages([]);
     try {
         // link the source first before processing it
         $linked = $this->processor->isLinked($source);
         if (!$linked) {
             $this->logger->debug('Linking source first');
             $this->processor->link($source);
         }
         $this->processor->process($source);
         // if the source was unlinked, flush it now
         if (!$linked) {
             $this->sourceManager->flush($source);
         }
         return true;
     } catch (SourceLinkException $e) {
         $this->setMessage($source, 'link', sprintf('Could not link source (%d): %s', $sourceId, $e->getMessage()));
     } catch (SourceProcessException $e) {
         $this->setMessage($source, 'process', sprintf('Error while processing source (%d): %s', $sourceId, $e->getMessage()));
     }
     foreach ($source->getMessages() as $key => $messages) {
         foreach ($messages as $level => $message) {
             $this->logger->log($level, sprintf('[%s] %s', $key, $message));
         }
     }
     return false;
 }