public function testGetMessages()
 {
     $conversation = Mockery::mock('FOS\\Message\\Model\\ConversationInterface');
     $message = Mockery::mock('FOS\\Message\\Model\\PersonInterface');
     $this->driver->shouldReceive('findMessages')->once()->with($conversation, 5, 10, 'DESC')->andReturn([$message]);
     $this->assertSame([$message], $this->repository->getMessages($conversation, 5, 10, 'DESC'));
 }
Exemple #2
0
 /**
  * {@inheritdoc}
  */
 public function getMessages(ConversationInterface $conversation, $offset = 0, $limit = 20, $sortDirection = 'ASC')
 {
     Assert::integer($offset, '$offset expected an integer in Repository::getMessages(). Got: %s');
     Assert::integer($limit, '$limit expected an integer in Repository::getMessages(). Got: %s');
     Assert::oneOf(strtoupper($sortDirection), ['ASC', 'DESC'], '$sortDirection expected either ASC or DESC in Repository::getMessages(). Got: %s');
     return $this->driver->findMessages($conversation, $offset, $limit, $sortDirection);
 }
Exemple #3
0
 public function testRemoveExistingTag()
 {
     $person = Mockery::mock('FOS\\Message\\Model\\PersonInterface');
     $conversation = Mockery::mock('FOS\\Message\\Model\\ConversationInterface');
     $tag = Mockery::mock('FOS\\Message\\Model\\TagInterface');
     $conversationPerson = Mockery::mock('FOS\\Message\\Model\\ConversationPersonInterface');
     $conversationPerson->shouldReceive('hasTag')->with($tag)->once()->andReturn(true);
     $conversationPerson->shouldReceive('removeTag')->with($tag)->once()->andReturn(true);
     $this->repository->shouldReceive('getConversationPerson')->once()->with($conversation, $person)->andReturn($conversationPerson);
     $this->driver->shouldReceive('persistConversationPerson')->once()->with($conversationPerson)->andReturn(true);
     $this->driver->shouldReceive('flush')->once()->withNoArgs()->andReturn(true);
     $this->assertTrue($this->tagger->removeTag($conversation, $person, $tag));
 }
Exemple #4
0
 /**
  * {@inheritdoc}
  */
 public function removeTag(ConversationInterface $conversation, PersonInterface $person, TagInterface $tag)
 {
     $conversationPerson = $this->repository->getConversationPerson($conversation, $person);
     if (!$conversationPerson instanceof ConversationPersonInterface) {
         throw new \LogicException(sprintf('Link between conversation %s and person %s was not found in %s', $conversation->getId(), $person->getId(), __METHOD__));
     }
     if (!$conversationPerson->hasTag($tag)) {
         return false;
     }
     $conversationPerson->removeTag($tag);
     $this->driver->persistConversationPerson($conversationPerson);
     $this->driver->flush();
     return true;
 }
Exemple #5
0
 /**
  * Create and persist a message person object.
  *
  * @param MessageInterface $message
  * @param PersonInterface  $person
  * @param bool             $setRead
  *
  * @return ConversationPersonInterface
  */
 private function createAndPersistMessagePerson(MessageInterface $message, PersonInterface $person, $setRead)
 {
     $messagePerson = $this->driver->createMessagePersonModel($message, $person);
     if ($setRead) {
         $messagePerson->setRead();
     }
     $this->driver->persistMessagePerson($messagePerson);
     return $messagePerson;
 }
 public function testFindMessagesLimit()
 {
     $conversation = $this->driver->createConversationModel();
     $conversation->setSubject('Subject');
     $this->driver->persistConversation($conversation);
     $firstMessage = $this->driver->createMessageModel($conversation, $this->createPerson(), 'Body1');
     $this->driver->persistMessage($firstMessage);
     $secondMessage = $this->driver->createMessageModel($conversation, $this->createPerson(), 'Body2');
     $this->driver->persistMessage($secondMessage);
     $thirdMessage = $this->driver->createMessageModel($conversation, $this->createPerson(), 'Body3');
     $this->driver->persistMessage($thirdMessage);
     $this->driver->flush();
     $fetched = $this->driver->findMessages($conversation, 0, 2, 'ASC');
     $this->assertInstanceOf('Doctrine\\Common\\Collections\\Collection', $fetched);
     $this->assertCount(2, $fetched);
     $this->assertMessagesEquals($firstMessage, $fetched[0]);
     $this->assertMessagesEquals($secondMessage, $fetched[1]);
     $fetched = $this->driver->findMessages($conversation, 1, 2, 'ASC');
     $this->assertInstanceOf('Doctrine\\Common\\Collections\\Collection', $fetched);
     $this->assertCount(2, $fetched);
     $this->assertMessagesEquals($secondMessage, $fetched[0]);
     $this->assertMessagesEquals($thirdMessage, $fetched[1]);
 }
Exemple #7
0
 public function testSendMessage()
 {
     $from = Mockery::mock('FOS\\Message\\Model\\PersonInterface');
     $from->shouldReceive('getId')->withNoArgs()->once()->andReturn(1);
     $firstRecipient = Mockery::mock('FOS\\Message\\Model\\PersonInterface');
     $firstRecipient->shouldReceive('getId')->withNoArgs()->once()->andReturn(2);
     $secondRecipient = Mockery::mock('FOS\\Message\\Model\\PersonInterface');
     $secondRecipient->shouldReceive('getId')->withNoArgs()->once()->andReturn(2);
     $fromConversationModel = Mockery::mock('FOS\\Message\\Model\\ConversationPersonInterface');
     $fromConversationModel->shouldReceive('getPerson')->withNoArgs()->once()->andReturn($from);
     $firstConversationModel = Mockery::mock('FOS\\Message\\Model\\ConversationPersonInterface');
     $firstConversationModel->shouldReceive('getPerson')->withNoArgs()->once()->andReturn($firstRecipient);
     $secondConversationModel = Mockery::mock('FOS\\Message\\Model\\ConversationPersonInterface');
     $secondConversationModel->shouldReceive('getPerson')->withNoArgs()->once()->andReturn($secondRecipient);
     $conversation = Mockery::mock('FOS\\Message\\Model\\ConversationInterface');
     $conversation->shouldReceive('getConversationPersons')->withNoArgs()->andReturn([$fromConversationModel, $firstConversationModel, $secondConversationModel]);
     $fromMessageModel = Mockery::mock('FOS\\Message\\Model\\MessagePersonInterface');
     $fromMessageModel->shouldReceive('setRead')->withNoArgs()->andReturnSelf();
     $firstMessageModel = Mockery::mock('FOS\\Message\\Model\\MessagePersonInterface');
     $secondMessageModel = Mockery::mock('FOS\\Message\\Model\\MessagePersonInterface');
     $message = Mockery::mock('FOS\\Message\\Model\\MessageInterface');
     // Create the message
     $this->driver->shouldReceive('createMessageModel')->once()->with($conversation, $from, 'ReplyBody')->andReturn($message);
     $this->driver->shouldReceive('persistMessage')->once()->with($message)->andReturn(true);
     // Create links between persons and message
     $this->driver->shouldReceive('createMessagePersonModel')->once()->with($message, $from)->andReturn($fromMessageModel);
     $this->driver->shouldReceive('persistMessagePerson')->once()->with($fromMessageModel)->andReturn(true);
     $this->driver->shouldReceive('createMessagePersonModel')->once()->with($message, $firstRecipient)->andReturn($firstMessageModel);
     $this->driver->shouldReceive('persistMessagePerson')->once()->with($firstMessageModel)->andReturn(true);
     $this->driver->shouldReceive('createMessagePersonModel')->once()->with($message, $secondRecipient)->andReturn($secondMessageModel);
     $this->driver->shouldReceive('persistMessagePerson')->once()->with($secondMessageModel)->andReturn(true);
     // Final flush
     $this->driver->shouldReceive('flush')->once()->withNoArgs()->andReturn(true);
     // Dispatcher
     $this->dispatcher->shouldReceive('dispatch')->with(Mockery::type('FOS\\Message\\Event\\MessageEvent'))->once()->andReturn(true);
     $this->assertSame($message, $this->sender->sendMessage($conversation, $from, 'ReplyBody'));
 }