diff --git a/data/.gitignore b/data/.gitignore index f84f8da4..a1af5458 100644 --- a/data/.gitignore +++ b/data/.gitignore @@ -1,3 +1,3 @@ db.sqlite -executed_upgrades.txt +executed_upgrades*.txt local.ini diff --git a/data/config.ini b/data/config.ini index aaf74d6c..fe312c88 100644 --- a/data/config.ini +++ b/data/config.ini @@ -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 diff --git a/scripts/upgrade.php b/scripts/upgrade.php index 9bd127e2..aacad7b4 100644 --- a/scripts/upgrade.php +++ b/scripts/upgrade.php @@ -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(); diff --git a/tests/AbstractDatabaseTestCase.php b/tests/AbstractDatabaseTestCase.php index 35604d71..29801b88 100644 --- a/tests/AbstractDatabaseTestCase.php +++ b/tests/AbstractDatabaseTestCase.php @@ -1,14 +1,12 @@ 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); - } }