/** * @param MessageEvent $event * * @return MessageEvent */ private function dispatchEvent(MessageEvent $event) { if ($this->eventDispatcher) { return $this->eventDispatcher->dispatch($event); } return $event; }
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')); }