Dropped sqlite support; changed DB testing
This commit is contained in:
parent
5ceecbd0ca
commit
9ca712cc6d
4 changed files with 44 additions and 23 deletions
2
data/.gitignore
vendored
2
data/.gitignore
vendored
|
@ -1,3 +1,3 @@
|
||||||
db.sqlite
|
db.sqlite
|
||||||
executed_upgrades.txt
|
executed_upgrades*.txt
|
||||||
local.ini
|
local.ini
|
||||||
|
|
|
@ -11,12 +11,17 @@ activationSubject = szurubooru - account activation
|
||||||
activationBodyPath = mail/activation.txt
|
activationBodyPath = mail/activation.txt
|
||||||
|
|
||||||
[database]
|
[database]
|
||||||
dsn = sqlite:db.sqlite
|
dsn = mysql:dbname=szuru_dev
|
||||||
user =
|
user = szuru-dev
|
||||||
password =
|
password = dog
|
||||||
maxPostSize = 10485760 ;10mb
|
maxPostSize = 10485760 ;10mb
|
||||||
maxCustomThumbnailSize = 1048576 ;1mb
|
maxCustomThumbnailSize = 1048576 ;1mb
|
||||||
|
|
||||||
|
[database.tests]
|
||||||
|
dsn = mysql:host=localhost
|
||||||
|
user = szuru_test
|
||||||
|
password = cat
|
||||||
|
|
||||||
[security]
|
[security]
|
||||||
secret = change
|
secret = change
|
||||||
minPasswordLength = 5
|
minPasswordLength = 5
|
||||||
|
|
|
@ -4,5 +4,31 @@ require_once(__DIR__
|
||||||
. DIRECTORY_SEPARATOR . 'src'
|
. DIRECTORY_SEPARATOR . 'src'
|
||||||
. DIRECTORY_SEPARATOR . 'Bootstrap.php');
|
. 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();
|
$upgradeService->runUpgradesVerbose();
|
||||||
|
|
|
@ -1,14 +1,12 @@
|
||||||
<?php
|
<?php
|
||||||
namespace Szurubooru\Tests;
|
namespace Szurubooru\Tests;
|
||||||
|
use Szurubooru\Config;
|
||||||
use Szurubooru\Dao\PublicFileDao;
|
use Szurubooru\Dao\PublicFileDao;
|
||||||
use Szurubooru\DatabaseConnection;
|
use Szurubooru\DatabaseConnection;
|
||||||
use Szurubooru\Entities\Post;
|
use Szurubooru\Entities\Post;
|
||||||
use Szurubooru\Entities\User;
|
use Szurubooru\Entities\User;
|
||||||
use Szurubooru\Helpers\HttpHelper;
|
|
||||||
use Szurubooru\Injector;
|
use Szurubooru\Injector;
|
||||||
use Szurubooru\Services\UpgradeService;
|
|
||||||
use Szurubooru\Tests\AbstractTestCase;
|
use Szurubooru\Tests\AbstractTestCase;
|
||||||
use Szurubooru\Upgrades\UpgradeRepository;
|
|
||||||
|
|
||||||
abstract class AbstractDatabaseTestCase extends AbstractTestCase
|
abstract class AbstractDatabaseTestCase extends AbstractTestCase
|
||||||
{
|
{
|
||||||
|
@ -17,22 +15,21 @@ abstract class AbstractDatabaseTestCase extends AbstractTestCase
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
$realConfig = Injector::get(Config::class);
|
||||||
$config = $this->mockConfig($this->createTestDirectory());
|
$config = $this->mockConfig($this->createTestDirectory());
|
||||||
$config->set('database/dsn', 'sqlite::memory:');
|
$config->set('database/dsn', $realConfig->database->tests->dsn);
|
||||||
$config->set('database/user', '');
|
$config->set('database/user', $realConfig->database->tests->user);
|
||||||
$config->set('database/password', '');
|
$config->set('database/password', $realConfig->database->tests->password);
|
||||||
|
|
||||||
$this->databaseConnection = new DatabaseConnection($config);
|
$this->databaseConnection = new DatabaseConnection($config);
|
||||||
|
$this->databaseConnection->getPDO()->exec('USE szuru_test');
|
||||||
|
$this->databaseConnection->getPDO()->beginTransaction();
|
||||||
Injector::set(DatabaseConnection::class, $this->databaseConnection);
|
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()
|
public function tearDown()
|
||||||
{
|
{
|
||||||
|
$this->databaseConnection->getPDO()->rollBack();
|
||||||
parent::tearDown();
|
parent::tearDown();
|
||||||
if ($this->databaseConnection)
|
if ($this->databaseConnection)
|
||||||
$this->databaseConnection->close();
|
$this->databaseConnection->close();
|
||||||
|
@ -59,11 +56,4 @@ abstract class AbstractDatabaseTestCase extends AbstractTestCase
|
||||||
$user->setAccessRank(User::ACCESS_RANK_REGULAR_USER);
|
$user->setAccessRank(User::ACCESS_RANK_REGULAR_USER);
|
||||||
return $user;
|
return $user;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function preparePublicFileDao()
|
|
||||||
{
|
|
||||||
$testDirectory = $this->createTestDirectory();
|
|
||||||
$configMock = $this->mockConfig(null, $testDirectory);
|
|
||||||
return new PublicFileDao($configMock);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue