Dropped sqlite support; changed DB testing

This commit is contained in:
Marcin Kurczewski 2014-11-09 12:29:20 +01:00
parent 5ceecbd0ca
commit 9ca712cc6d
4 changed files with 44 additions and 23 deletions

2
data/.gitignore vendored
View file

@ -1,3 +1,3 @@
db.sqlite
executed_upgrades.txt
executed_upgrades*.txt
local.ini

View file

@ -11,12 +11,17 @@ activationSubject = szurubooru - account activation
activationBodyPath = mail/activation.txt
[database]
dsn = sqlite:db.sqlite
user =
password =
dsn = mysql:dbname=szuru_dev
user = szuru-dev
password = dog
maxPostSize = 10485760 ;10mb
maxCustomThumbnailSize = 1048576 ;1mb
[database.tests]
dsn = mysql:host=localhost
user = szuru_test
password = cat
[security]
secret = change
minPasswordLength = 5

View file

@ -4,5 +4,31 @@ require_once(__DIR__
. DIRECTORY_SEPARATOR . 'src'
. DIRECTORY_SEPARATOR . 'Bootstrap.php');
$upgradeService = Szurubooru\Injector::get(\Szurubooru\Services\UpgradeService::class);
$testMode = false;
if (isset($argv))
{
foreach ($argv as $arg)
{
if ($arg === '--test')
$testMode = true;
}
}
if ($testMode)
{
$config = \Szurubooru\Injector::get(\Szurubooru\Config::class);
$config->database->dsn = $config->database->tests->dsn;
$config->database->user = $config->database->tests->user;
$config->database->password = $config->database->tests->password;
\Szurubooru\Injector::set(\Szurubooru\Config::class, $config);
$databaseConnection = \Szurubooru\Injector::get(\Szurubooru\DatabaseConnection::class);
$pdo = $databaseConnection->getPDO();
$pdo->exec('DROP DATABASE szuru_test');
$pdo->exec('CREATE DATABASE szuru_test');
$pdo->exec('USE szuru_test');
}
$upgradeService = \Szurubooru\Injector::get(\Szurubooru\Services\UpgradeService::class);
$upgradeService->runUpgradesVerbose();

View file

@ -1,14 +1,12 @@
<?php
namespace Szurubooru\Tests;
use Szurubooru\Config;
use Szurubooru\Dao\PublicFileDao;
use Szurubooru\DatabaseConnection;
use Szurubooru\Entities\Post;
use Szurubooru\Entities\User;
use Szurubooru\Helpers\HttpHelper;
use Szurubooru\Injector;
use Szurubooru\Services\UpgradeService;
use Szurubooru\Tests\AbstractTestCase;
use Szurubooru\Upgrades\UpgradeRepository;
abstract class AbstractDatabaseTestCase extends AbstractTestCase
{
@ -17,22 +15,21 @@ abstract class AbstractDatabaseTestCase extends AbstractTestCase
public function setUp()
{
parent::setUp();
$realConfig = Injector::get(Config::class);
$config = $this->mockConfig($this->createTestDirectory());
$config->set('database/dsn', 'sqlite::memory:');
$config->set('database/user', '');
$config->set('database/password', '');
$config->set('database/dsn', $realConfig->database->tests->dsn);
$config->set('database/user', $realConfig->database->tests->user);
$config->set('database/password', $realConfig->database->tests->password);
$this->databaseConnection = new DatabaseConnection($config);
$this->databaseConnection->getPDO()->exec('USE szuru_test');
$this->databaseConnection->getPDO()->beginTransaction();
Injector::set(DatabaseConnection::class, $this->databaseConnection);
Injector::set(PublicFileDao::class, $this->preparePublicFileDao());
$upgradeRepository = Injector::get(UpgradeRepository::class);
$upgradeService = new UpgradeService($config, $this->databaseConnection, $upgradeRepository);
$upgradeService->runUpgradesQuiet();
}
public function tearDown()
{
$this->databaseConnection->getPDO()->rollBack();
parent::tearDown();
if ($this->databaseConnection)
$this->databaseConnection->close();
@ -59,11 +56,4 @@ abstract class AbstractDatabaseTestCase extends AbstractTestCase
$user->setAccessRank(User::ACCESS_RANK_REGULAR_USER);
return $user;
}
private function preparePublicFileDao()
{
$testDirectory = $this->createTestDirectory();
$configMock = $this->mockConfig(null, $testDirectory);
return new PublicFileDao($configMock);
}
}