Fix some bugs in ModelTestCase, including clearing the cache
This commit is contained in:
+19
-12
@@ -20,7 +20,7 @@ abstract class ModelTestCase extends \PHPUnit_Extensions_Database_TestCase
|
||||
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
|
||||
@@ -30,15 +30,15 @@ abstract class ModelTestCase extends \PHPUnit_Extensions_Database_TestCase
|
||||
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 = EntityManager::create(["pdo" => self::$pdo], $configuration);
|
||||
self::$em->getFilters()->enable("soft-deleteable");
|
||||
self::$em->getEventManager()->addEventSubscriber(new \Gedmo\SoftDeleteable\SoftDeleteableListener());
|
||||
|
||||
// Create Schema
|
||||
@@ -46,16 +46,16 @@ abstract class ModelTestCase extends \PHPUnit_Extensions_Database_TestCase
|
||||
$schemaTool = new SchemaTool(self::$em);
|
||||
$schemaTool->updateSchema($metaData);
|
||||
}
|
||||
|
||||
$this->conn = $this->createDefaultDBConnection(self::$pdo, $GLOBALS["DB_NAME"]);
|
||||
|
||||
$this->connection = $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;
|
||||
|
||||
return $this->connection;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a .yml dataset under this name
|
||||
* @return \PHPUnit_Extensions_Database_DataSet_YamlDataSet
|
||||
@@ -66,7 +66,7 @@ abstract class ModelTestCase extends \PHPUnit_Extensions_Database_TestCase
|
||||
__DIR__."/datasets/".$this->dataset.".yml"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the current entity manager
|
||||
* @return EntityManagerInterface
|
||||
@@ -75,4 +75,11 @@ abstract class ModelTestCase extends \PHPUnit_Extensions_Database_TestCase
|
||||
{
|
||||
return self::$em;
|
||||
}
|
||||
|
||||
protected function tearDown() {
|
||||
parent::tearDown();
|
||||
|
||||
// Clear out the cache so tests don't get confused.
|
||||
$this->getEntityManager()->clear();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user