Upgrades successfully to PHPUnit 7, removed DBUnit support and integrated custom testing.
This commit is contained in:
+3
-3
@@ -31,8 +31,8 @@
|
||||
|
||||
],
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^5.0",
|
||||
"phpunit/dbunit": "^2.0",
|
||||
"block8/php-docblock-checker": "2.0.0"
|
||||
"phpunit/phpunit": "^7.0",
|
||||
"phpunit/php-code-coverage": "*",
|
||||
"dancryer/php-docblock-checker": "*"
|
||||
}
|
||||
}
|
||||
|
||||
Generated
+675
-460
File diff suppressed because it is too large
Load Diff
@@ -13,8 +13,9 @@ use Monolog\Handler\NullHandler;
|
||||
use LotGD\Core\Bootstrap;
|
||||
use LotGD\Core\ComposerManager;
|
||||
use LotGD\Core\Tests\FakeModule\Models\UserEntity;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class BootstrapTest extends \PHPUnit_Framework_TestCase
|
||||
class BootstrapTest extends TestCase
|
||||
{
|
||||
private $logger;
|
||||
|
||||
|
||||
@@ -10,8 +10,9 @@ use Monolog\Handler\NullHandler;
|
||||
|
||||
use LotGD\Core\ComposerManager;
|
||||
use LotGD\Core\Tests\FakeModule\UserEntity;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ComposerManagerTest extends \PHPUnit_Framework_TestCase
|
||||
class ComposerManagerTest extends TestCase
|
||||
{
|
||||
private $logger;
|
||||
|
||||
|
||||
@@ -10,8 +10,9 @@ use Monolog\Handler\NullHandler;
|
||||
|
||||
use LotGD\Core\Configuration;
|
||||
use LotGD\Core\Exceptions\InvalidConfigurationException;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ConfigurationTest extends \PHPUnit_Framework_TestCase
|
||||
class ConfigurationTest extends TestCase
|
||||
{
|
||||
private $logger;
|
||||
private $configDir;
|
||||
|
||||
@@ -3,14 +3,19 @@ declare(strict_types=1);
|
||||
|
||||
namespace LotGD\Core\Tests;
|
||||
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
class CoreModelTestCase extends ModelTestCase
|
||||
{
|
||||
/**
|
||||
* Returns a .yml dataset under this name
|
||||
* @return \PHPUnit_Extensions_Database_DataSet_YamlDataSet
|
||||
* @return array
|
||||
*/
|
||||
protected function getDataSet(): \PHPUnit_Extensions_Database_DataSet_YamlDataSet
|
||||
protected function getDataSet(): array
|
||||
{
|
||||
return new \PHPUnit_Extensions_Database_DataSet_YamlDataSet(implode(DIRECTORY_SEPARATOR, [__DIR__, 'datasets', $this->dataset . '.yml']));
|
||||
$datasetFile = implode(DIRECTORY_SEPARATOR, [__DIR__, 'datasets', $this->dataset . '.yml']);
|
||||
$dataset = Yaml::parseFile($datasetFile);
|
||||
|
||||
return $dataset;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,12 +4,13 @@ declare(strict_types=1);
|
||||
namespace LotGD\Core\Tests;
|
||||
|
||||
use LotGD\Core\DiceBag;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @backupGlobals disabled
|
||||
* @backupStaticAttributes disabled
|
||||
*/
|
||||
class DiceBagTests extends \PHPUnit_Framework_TestCase
|
||||
class DiceBagTests extends TestCase
|
||||
{
|
||||
public function testUniform()
|
||||
{
|
||||
|
||||
+38
-5
@@ -20,25 +20,25 @@ use LotGD\Core\Exceptions\InvalidConfigurationException;
|
||||
use LotGD\Core\ModelExtender;
|
||||
use Monolog\Handler\NullHandler;
|
||||
use Monolog\Logger;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Description of ModelTestCase
|
||||
*/
|
||||
abstract class ModelTestCase extends \PHPUnit_Extensions_Database_TestCase
|
||||
abstract class ModelTestCase extends TestCase
|
||||
{
|
||||
/** @var \PDO */
|
||||
static private $pdo = null;
|
||||
/** @var EntityManager */
|
||||
static private $em = null;
|
||||
/** @var \PHPUnit_Extensions_Database_DB_DefaultDatabaseConnection */
|
||||
private $connection = null;
|
||||
public $g;
|
||||
protected $tables = null;
|
||||
|
||||
/**
|
||||
* Returns a connection to test models
|
||||
* @return \PHPUnit_Extensions_Database_DB_DefaultDatabaseConnection
|
||||
*/
|
||||
final public function getConnection(): \PHPUnit_Extensions_Database_DB_DefaultDatabaseConnection
|
||||
final public function getConnection()
|
||||
{
|
||||
if ($this->connection === null) {
|
||||
$configFilePath = getenv('LOTGD_TESTS_CONFIG_PATH');
|
||||
@@ -71,12 +71,29 @@ abstract class ModelTestCase extends \PHPUnit_Extensions_Database_TestCase
|
||||
$schemaTool->updateSchema($metaData);
|
||||
}
|
||||
|
||||
$this->connection = $this->createDefaultDBConnection(self::$pdo, $config->getDatabaseName());
|
||||
$this->connection = [self::$pdo, $config->getDatabaseName()];
|
||||
}
|
||||
|
||||
return $this->connection;
|
||||
}
|
||||
|
||||
protected function insertData($dataSet)
|
||||
{
|
||||
/** @var \PDO $pdo */
|
||||
$pdo = $this->connection[0];
|
||||
|
||||
foreach ($dataSet as $table => $rows) {
|
||||
$this->tables[] = $table;
|
||||
foreach ($rows as $row) {
|
||||
$fields = implode(",", array_keys($row));
|
||||
$placeholders = substr(str_repeat("?,", count($row)), 0, -1);
|
||||
$query = "INSERT INTO $table ($fields) VALUES ($placeholders)";
|
||||
$stmt = $pdo->prepare($query);
|
||||
$stmt->execute(array_values($row));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current entity manager
|
||||
* @return EntityManagerInterface
|
||||
@@ -88,6 +105,14 @@ abstract class ModelTestCase extends \PHPUnit_Extensions_Database_TestCase
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->getConnection();
|
||||
|
||||
// Set up database content
|
||||
if (method_exists($this, "getDataSet")) {
|
||||
$dataSet = $this->getDataSet();
|
||||
$this->insertData($dataSet);
|
||||
}
|
||||
|
||||
parent::setUp();
|
||||
|
||||
$this->getEntityManager()->flush();
|
||||
@@ -128,6 +153,14 @@ abstract class ModelTestCase extends \PHPUnit_Extensions_Database_TestCase
|
||||
protected function tearDown() {
|
||||
parent::tearDown();
|
||||
|
||||
/** @var \PDO $pdo */
|
||||
$pdo = $this->connection[0];
|
||||
|
||||
foreach ($this->tables as $table) {
|
||||
$stmt = $pdo->prepare("DELETE FROM $table WHERE 1");
|
||||
$stmt->execute();
|
||||
}
|
||||
|
||||
// Clear out the cache so tests don't get confused.
|
||||
$this->getEntityManager()->clear();
|
||||
}
|
||||
|
||||
@@ -162,11 +162,6 @@ class OneToManyCollectionTest extends CoreModelTestCase
|
||||
$this->assertFalse($oldElementFound);
|
||||
}
|
||||
|
||||
public function testCollectionFilterInterface()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function testTypeClass()
|
||||
{
|
||||
$collection = $this->getCollection();
|
||||
|
||||
@@ -5,12 +5,13 @@ namespace LotGD\Core\Tests;
|
||||
|
||||
use DateTime;
|
||||
use LotGD\Core\TimeKeeper;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @backupGlobals disabled
|
||||
* @backupStaticAttributes disabled
|
||||
*/
|
||||
class TimeKeeperTests extends \PHPUnit_Framework_TestCase {
|
||||
class TimeKeeperTests extends TestCase {
|
||||
private $gameEpoch;
|
||||
private $gameOffsetSeconds;
|
||||
private $gameDaysPerDay;
|
||||
|
||||
Reference in New Issue
Block a user