Made changes requested, and fixed tests

This commit is contained in:
nekosune
2018-04-09 16:01:37 +00:00
parent 8ba04dade4
commit 6c4b1e15f4
5 changed files with 44 additions and 45 deletions
+12 -11
View File
@@ -28,6 +28,7 @@ class GameBuilder
private $eventManagerClass;
private $diceBagClass;
private $messageManagerClass;
/**
* Creates the game instance with the prepared parameters.
* @return Game
@@ -111,6 +112,17 @@ class GameBuilder
return $this;
}
/**
* Sets the fqcn for the message manager to be used
* @param string $messageManagerFqcn
* @return self
*/
public function withMessageManager(string $messageManagerFqcn): self
{
$this->messageManagerClass=$messageManagerFqcn;
return $this;
}
/**
* Sets the fqcn for the module manager to be used.
* @param string $moduleManagerFqcn
@@ -133,17 +145,6 @@ class GameBuilder
return $this;
}
/**
* Sets the fqcn for the message manager to be used
* @param string $messageManagerFqcn
* @return self
*/
public function useMessageManager(string $messageManagerFqcn): self
{
$this->messageManagerClass=$messageManagerFqcn;
return $this;
}
/**
* Sets the fqcn for the event manager to be used.
* @param string $eventManagerFqcn
+1 -8
View File
@@ -1,14 +1,8 @@
<?php
/**
* Handles the messages in the game
* User: nekosune
* Date: 07/04/2018
* Time: 18:54
*/
declare(strict_types=1);
namespace LotGD\Core;
use LotGD\Core\Models\Character;
use LotGD\Core\Models\Message;
use LotGD\Core\Models\MessageThread;
@@ -41,7 +35,6 @@ class MessageManager
return $message;
}
/**
* Sends a system message to a MessageThread
* @param string $message
+1 -2
View File
@@ -44,8 +44,7 @@ class Message
/**
* Constructs the message.
*
* Use the static methods self::send() and self::sendSystemMessage() instead.
* Use the Message Manager methods send() and sendSystemMessage() instead.
* @param CharacterInterface $from
* @param string $message
* @param MessageThread $thread
+18 -12
View File
@@ -3,6 +3,7 @@ declare(strict_types=1);
namespace LotGD\Core\Tests\Models;
use LotGD\Core\MessageManager;
use LotGD\Core\Models\Character;
use LotGD\Core\Models\MessageThread;
use LotGD\Core\Models\Message;
@@ -14,12 +15,14 @@ use LotGD\Core\Tests\CoreModelTestCase;
*/
class MessageModelTest extends CoreModelTestCase
{
/** @var string default data set */
protected $dataset = "messages";
public function testSendMessageToSingleCharacter()
{
$em = $this->getEntityManager();
$mm=new MessageManager();
$character1 = $em->getRepository(Character::class)->find(1);
$character2 = $em->getRepository(Character::class)->find(4);
@@ -29,9 +32,9 @@ class MessageModelTest extends CoreModelTestCase
$this->assertSame($thread1, $thread2);
Message::send($character1, "Hi, how are you?", $thread1);
Message::send($character2, "I'm fine, and you?", $thread1);
Message::send($character1, "Sorry, I need to leave~", $thread1);
$mm->send($character1, "Hi, how are you?", $thread1);
$mm->send($character2, "I'm fine, and you?", $thread1);
$mm->send($character1, "Sorry, I need to leave~", $thread1);
$this->assertSame(3, count($thread1->getMessages()));
@@ -57,6 +60,7 @@ class MessageModelTest extends CoreModelTestCase
public function testSendMessageToMultipleCharacters()
{
$em = $this->getEntityManager();
$mm=new MessageManager();
$character1 = $em->getRepository(Character::class)->find(1);
$character2 = $em->getRepository(Character::class)->find(2);
@@ -67,15 +71,15 @@ class MessageModelTest extends CoreModelTestCase
$thread2 = $em->getRepository(MessageThread::class)->findOrCreateFor([$character4, $character2, $character1, $character3]);
$this->assertSame($thread1, $thread2);
Message::send($character1, "Multi-User-Message", $thread1);
Message::send($character2, "Multi-User-Message", $thread1);
$mm->send($character1, "Multi-User-Message", $thread1);
$mm->send($character2, "Multi-User-Message", $thread1);
try {
$exception = false;
Message::send($character3, "Multi-User-Message", $thread1);
$mm->send($character3, "Multi-User-Message", $thread1);
} catch(\LotGD\Core\Exceptions\ArgumentException $e) {
$exception = true;
}
Message::send($character4, "Multi-User-Message", $thread1);
$mm->send($character4, "Multi-User-Message", $thread1);
$this->assertTrue($exception);
$this->assertSame(3, count($thread1->getMessages()));
@@ -105,6 +109,7 @@ class MessageModelTest extends CoreModelTestCase
public function testSendSystemMessageToSingleCharacter()
{
$em = $this->getEntityManager();
$mm=new MessageManager();
$character1 = $em->getRepository(Character::class)->find(1);
$character2 = $em->getRepository(Character::class)->find(2);
@@ -114,8 +119,8 @@ class MessageModelTest extends CoreModelTestCase
$this->assertNotSame($thread1, $thread2);
Message::sendSystemMessage("This is a Systemmessage for Character 1.", $thread1);
Message::sendSystemMessage("This is a Systemmessage for Character 2.", $thread2);
$mm->sendSystemMessage("This is a Systemmessage for Character 1.", $thread1);
$mm->sendSystemMessage("This is a Systemmessage for Character 2.", $thread2);
$em->flush();
$em->clear();
@@ -133,12 +138,12 @@ class MessageModelTest extends CoreModelTestCase
// needs to be able to get attached
try {
$exception = false;
Message::send($character1, "A normal message", $thread1);
$mm->send($character1, "A normal message", $thread1);
} catch (\LotGD\Core\Exceptions\CoreException $ex) {
$exception = true;
}
Message::sendSystemMessage("A second system Message", $thread1);
$mm->sendSystemMessage("A second system Message", $thread1);
$this->assertTrue($exception);
$this->assertSame(2, count($thread1->getMessages()));
@@ -147,6 +152,7 @@ class MessageModelTest extends CoreModelTestCase
public function testSendSystemMessageToMultipleCharacters()
{
$em = $this->getEntityManager();
$mm=new MessageManager();
$character1 = $em->getRepository(Character::class)->find(1);
$character2 = $em->getRepository(Character::class)->find(2);
@@ -156,7 +162,7 @@ class MessageModelTest extends CoreModelTestCase
$this->assertNotSame($thread1, $thread2);
Message::sendSystemMessage("A system message to 2 recipients", $thread1);
$mm->sendSystemMessage("A system message to 2 recipients", $thread1);
$em->flush();
$em->clear();