/**
  * @return \JMS\TranslationBundle\Model\Message\XliffMessage
  */
 private function createMessage($id, $desc, $source)
 {
     $message = new Message\XliffMessage($id, $this->domain);
     $message->addSource(new FileSource($source));
     $message->setDesc($desc);
     $message->setLocaleString($desc);
     $message->addNote('key: ' . $id);
     return $message;
 }
 /**
  * @param $message
  * @return Message\XliffMessage
  */
 private function makeXliffMessage(Message $message)
 {
     $newMessage = new Message\XliffMessage($message->getId(), $message->getDomain());
     $newMessage->setNew($message->isNew());
     $newMessage->setLocaleString($message->getLocaleString());
     $newMessage->setSources($message->getSources());
     $newMessage->addNote('key: ' . $message->getId());
     if ($desc = $message->getDesc()) {
         $newMessage->setDesc($desc);
     }
     return $newMessage;
 }
 public function testMergeScanned()
 {
     $existingMessage = new XliffMessage('foo');
     $existingMessage->setLocaleString('bar');
     $existingMessage->addSource(new FileSource('bar'));
     $existingMessage->setApproved(false);
     $existingMessage->setState(XliffMessage::STATE_NONE);
     $scannedMessage = new XliffMessage('foo');
     $scannedMessage->setDesc('foo');
     $scannedMessage->setApproved(true);
     $scannedMessage->setState(XliffMessage::STATE_TRANSLATED);
     $scannedMessage1 = new Message('foo');
     $scannedMessage1->setDesc('foo');
     $existingMessage1 = clone $existingMessage;
     $scannedMessage1 = clone $scannedMessage;
     $existingMessage1->mergeScanned($scannedMessage1);
     $this->assertEquals('foo', $existingMessage1->getDesc());
     $this->assertEquals('bar', $existingMessage1->getLocaleString());
     $this->assertFalse($existingMessage1->isNew());
     $this->assertEquals(array(), $existingMessage1->getSources());
     $this->assertTrue($existingMessage1->isApproved());
     $this->assertEquals(XliffMessage::STATE_TRANSLATED, $existingMessage1->getState());
     $existingMessage2 = clone $existingMessage;
     $existingMessage2->setDesc('bar');
     $existingMessage2->setApproved(true);
     $existingMessage2->setState(XliffMessage::STATE_TRANSLATED);
     $scannedMessage2 = clone $scannedMessage;
     $scannedMessage2->setDesc('foo');
     $scannedMessage2->setApproved(false);
     $scannedMessage2->setState(XliffMessage::STATE_NONE);
     $existingMessage2->mergeScanned($scannedMessage2);
     $this->assertEquals('bar', $existingMessage2->getDesc());
     $this->assertFalse($existingMessage2->isNew());
     $this->assertEquals(array(), $existingMessage2->getSources());
     $this->assertTrue($existingMessage2->isApproved());
     $this->assertEquals(XliffMessage::STATE_TRANSLATED, $existingMessage2->getState());
     $existingMessage3 = clone $existingMessage;
     $scannedMessage3 = clone $scannedMessage1;
     $existingMessage3->mergeScanned($scannedMessage3);
     $this->assertEquals('foo', $existingMessage3->getDesc());
     $this->assertEquals('bar', $existingMessage3->getLocaleString());
     $this->assertFalse($existingMessage3->isNew());
     $this->assertEquals(array(), $existingMessage3->getSources());
     $this->assertTrue($existingMessage3->isApproved());
     $this->assertEquals(XliffMessage::STATE_TRANSLATED, $existingMessage3->getState());
     $existingMessage4 = clone $existingMessage;
     $existingMessage4->setDesc('bar');
     $existingMessage4->setApproved(true);
     $existingMessage4->setState(XliffMessage::STATE_TRANSLATED);
     $scannedMessage4 = clone $scannedMessage1;
     $scannedMessage4->setDesc('foo');
     $existingMessage4->mergeScanned($scannedMessage4);
     $this->assertEquals('bar', $existingMessage4->getDesc());
     $this->assertEquals(array(), $existingMessage4->getSources());
     $this->assertTrue($existingMessage4->isApproved());
     $this->assertEquals(XliffMessage::STATE_TRANSLATED, $existingMessage4->getState());
 }