2014-08-28 10:45:55 +02:00
|
|
|
<?php
|
|
|
|
namespace Szurubooru\Tests;
|
|
|
|
|
2014-09-01 20:51:59 +02:00
|
|
|
abstract class AbstractDatabaseTestCase extends \Szurubooru\Tests\AbstractTestCase
|
2014-08-28 10:45:55 +02:00
|
|
|
{
|
2014-08-30 17:10:45 +02:00
|
|
|
protected $databaseConnection;
|
2014-08-28 10:45:55 +02:00
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
2014-09-14 16:16:15 +02:00
|
|
|
parent::setUp();
|
|
|
|
$config = $this->mockConfig($this->createTestDirectory());
|
|
|
|
$config->set('database/dsn', 'sqlite::memory:');
|
|
|
|
|
2014-08-30 17:10:45 +02:00
|
|
|
$this->databaseConnection = new \Szurubooru\DatabaseConnection($config);
|
2014-09-27 10:06:22 +02:00
|
|
|
\Szurubooru\Injector::set(\Szurubooru\DatabaseConnection::class, $this->databaseConnection);
|
2014-09-14 16:16:15 +02:00
|
|
|
|
|
|
|
$upgradeRepository = \Szurubooru\Injector::get(\Szurubooru\Upgrades\UpgradeRepository::class);
|
|
|
|
$upgradeService = new \Szurubooru\Services\UpgradeService($config, $this->databaseConnection, $upgradeRepository);
|
|
|
|
$upgradeService->runUpgradesQuiet();
|
2014-08-28 10:45:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function tearDown()
|
|
|
|
{
|
2014-09-14 16:16:15 +02:00
|
|
|
parent::tearDown();
|
|
|
|
if ($this->databaseConnection)
|
|
|
|
$this->databaseConnection->close();
|
2014-08-28 10:45:55 +02:00
|
|
|
}
|
2014-09-21 09:35:43 +02:00
|
|
|
|
|
|
|
protected function assertEntitiesEqual($expected, $actual)
|
|
|
|
{
|
|
|
|
if (!is_array($expected))
|
|
|
|
{
|
|
|
|
$expected = [$expected];
|
|
|
|
$actual = [$actual];
|
|
|
|
}
|
2014-09-24 20:13:16 +02:00
|
|
|
$this->assertEquals(count($expected), count($actual), 'Unmatching array sizes');
|
|
|
|
$this->assertEquals(array_keys($expected), array_keys($actual), 'Unmatching array keys');
|
2014-09-21 09:35:43 +02:00
|
|
|
foreach (array_keys($expected) as $key)
|
|
|
|
{
|
|
|
|
if ($expected[$key] === null)
|
|
|
|
{
|
|
|
|
$this->assertNull($actual[$key]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$expected[$key]->resetLazyLoaders();
|
2014-09-21 09:58:04 +02:00
|
|
|
$expected[$key]->resetMeta();
|
2014-09-21 09:35:43 +02:00
|
|
|
$actual[$key]->resetLazyLoaders();
|
2014-09-21 09:58:04 +02:00
|
|
|
$actual[$key]->resetMeta();
|
2014-09-21 09:35:43 +02:00
|
|
|
$this->assertEquals($expected[$key], $actual[$key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-08-28 10:45:55 +02:00
|
|
|
}
|