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')); }
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)); }
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')); }