0ff9958830
This commit adds the MotD model for storing and retrieving messages-of-the-day. It also adds a model for messages. Messages have an author as well as a thread they belong to, the thread can be read by a specific number of authors. FUrthermore, the message model supports system messages. This commit introduces a number of needed changes: - Character is now implementing the CharacterInterface - MissingCharacter and SystemCharacter are supporting "pseudo-characters" - trait MockCharacter implements non-implemented methods for MissingCharacter and SytemCharacter - Characters are now soft-deletable. Models wanting to load soft-deleted characters need to fetch them eagerly. Closes #17
79 lines
2.7 KiB
PHP
79 lines
2.7 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace LotGD\Core\Tests;
|
|
|
|
use Doctrine\ORM\EntityManager;
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
use Doctrine\ORM\Mapping\AnsiQuoteStrategy;
|
|
use Doctrine\ORM\Tools\Setup;
|
|
use Doctrine\ORM\Tools\SchemaTool;
|
|
|
|
/**
|
|
* Description of ModelTestCase
|
|
*/
|
|
abstract class ModelTestCase extends \PHPUnit_Extensions_Database_TestCase
|
|
{
|
|
/** @var \PDO */
|
|
static private $pdo = null;
|
|
/** @var EntityManager */
|
|
static private $em = null;
|
|
/** @var \PHPUnit_Extensions_Database_DB_DefaultDatabaseConnection */
|
|
private $connection = null;
|
|
|
|
/**
|
|
* Returns a connection to test models
|
|
* @return \PHPUnit_Extensions_Database_DB_DefaultDatabaseConnection
|
|
*/
|
|
final public function getConnection(): \PHPUnit_Extensions_Database_DB_DefaultDatabaseConnection
|
|
{
|
|
if ($this->connection === null) {
|
|
if (self::$pdo === null) {
|
|
self::$pdo = new \PDO($GLOBALS['DB_DSN'], $GLOBALS["DB_USER"], $GLOBALS["DB_PASSWORD"]);
|
|
|
|
// Read db annotations from model files
|
|
$configuration = Setup::createAnnotationMetadataConfiguration(["src/Models"], true);
|
|
$configuration->setQuoteStrategy(new AnsiQuoteStrategy());
|
|
|
|
$configuration->addFilter("soft-deleteable", 'Gedmo\SoftDeleteable\Filter\SoftDeleteableFilter');
|
|
|
|
self::$em = EntityManager::create(["pdo" => self::$pdo], $configuration);
|
|
self::$em->getFilters()->enable("soft-deleteable");
|
|
self::$em->getEventManager()->addEventSubscriber(new \Gedmo\SoftDeleteable\SoftDeleteableListener());
|
|
|
|
// Create Schema
|
|
$metaData = self::$em->getMetadataFactory()->getAllMetadata();
|
|
$schemaTool = new SchemaTool(self::$em);
|
|
$schemaTool->updateSchema($metaData);
|
|
}
|
|
|
|
$this->conn = $this->createDefaultDBConnection(self::$pdo, $GLOBALS["DB_NAME"]);
|
|
}
|
|
|
|
// It is important to clear the cache of the entity manager every time a new test runs!
|
|
self::$em->clear();
|
|
|
|
return $this->conn;
|
|
}
|
|
|
|
/**
|
|
* Returns a .yml dataset under this name
|
|
* @return \PHPUnit_Extensions_Database_DataSet_YamlDataSet
|
|
*/
|
|
protected function getDataSet(): \PHPUnit_Extensions_Database_DataSet_YamlDataSet
|
|
{
|
|
return new \PHPUnit_Extensions_Database_DataSet_YamlDataSet(
|
|
__DIR__."/datasets/".$this->dataset.".yml"
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Returns the current entity manager
|
|
* @return EntityManagerInterface
|
|
*/
|
|
protected function getEntityManager(): EntityManagerInterface
|
|
{
|
|
return self::$em;
|
|
}
|
|
}
|