szurubooru/tests/run-all.php

85 lines
1.8 KiB
PHP
Raw Normal View History

2014-05-04 21:23:12 +02:00
<?php
2014-05-06 11:18:04 +02:00
require_once __DIR__ . '/../src/core.php';
\Chibi\Autoloader::registerFileSystem(__DIR__);
2014-05-15 09:39:48 +02:00
$dbPath = __DIR__ . '/db.sqlite';
2014-05-15 09:39:48 +02:00
function cleanDatabase()
{
global $dbPath;
if (file_exists($dbPath))
unlink($dbPath);
}
2014-05-15 09:39:48 +02:00
function removeTestFolders()
{
$folders =
[
realpath(Core::getConfig()->main->filesPath),
realpath(Core::getConfig()->main->thumbsPath),
realpath(dirname(Core::getConfig()->main->logsPath)),
];
foreach ($folders as $folder)
{
2014-05-15 09:39:48 +02:00
if (!file_exists($folder))
continue;
2014-05-15 09:39:48 +02:00
$it = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator(
$folder,
FilesystemIterator::SKIP_DOTS),
RecursiveIteratorIterator::CHILD_FIRST);
2014-05-15 09:39:48 +02:00
foreach ($it as $path)
2014-05-04 21:23:12 +02:00
{
2014-05-15 09:39:48 +02:00
$path->isFile()
? unlink($path->getPathname())
: rmdir($path->getPathname());
2014-05-04 21:23:12 +02:00
}
2014-05-15 09:39:48 +02:00
rmdir($folder);
2014-05-04 21:23:12 +02:00
}
}
2014-05-15 09:39:48 +02:00
function resetEnvironment()
2014-05-04 21:23:12 +02:00
{
2014-05-15 09:39:48 +02:00
global $dbPath;
$_SESSION = [];
Core::prepareConfig(true);
Core::getConfig()->main->dbDriver = 'sqlite';
Core::getConfig()->main->dbLocation = $dbPath;
removeTestFolders();
Core::prepareEnvironment(true);
2014-05-04 21:23:12 +02:00
}
$options = getopt('cf:', ['clean', 'filter:']);
2014-05-15 09:39:48 +02:00
$cleanDatabase = (isset($options['c']) or isset($options['clean']));
if (isset($options['f']))
$filter = $options['f'];
elseif (isset($options['filter']))
$filter = $options['filter'];
else
$filter = null;
resetEnvironment();
if ($cleanDatabase)
cleanDatabase();
resetEnvironment();
Core::upgradeDatabase();
$testRunner = new TestRunner;
$testRunner->setFilter($filter);
$testRunner->setEnvironmentPrepareAction(function() { resetEnvironment(); });
$testRunner->setEnvironmentCleanAction(function() { removeTestFolders(); });
$testRunner->setTestWrapperAction(function($callback)
{
\Chibi\Database::rollback(function() use ($callback)
{
$callback();
});
});
$testRunner->run($filter);