2017-07-08 01:06:38 +00:00
|
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace JKingWeb\Arsse\Test;
|
|
|
|
use JKingWeb\Arsse\Exception;
|
2017-07-17 11:47:57 +00:00
|
|
|
use JKingWeb\Arsse\Arsse;
|
|
|
|
use JKingWeb\Arsse\Misc\Date;
|
2017-07-08 01:06:38 +00:00
|
|
|
|
|
|
|
abstract class AbstractTest extends \PHPUnit\Framework\TestCase {
|
|
|
|
|
|
|
|
function assertException(string $msg = "", string $prefix = "", string $type = "Exception") {
|
|
|
|
if(func_num_args()) {
|
|
|
|
$class = \JKingWeb\Arsse\NS_BASE . ($prefix !== "" ? str_replace("/", "\\", $prefix) . "\\" : "") . $type;
|
|
|
|
$msgID = ($prefix !== "" ? $prefix . "/" : "") . $type. ".$msg";
|
|
|
|
if(array_key_exists($msgID, Exception::CODES)) {
|
|
|
|
$code = Exception::CODES[$msgID];
|
|
|
|
} else {
|
|
|
|
$code = 0;
|
|
|
|
}
|
|
|
|
$this->expectException($class);
|
|
|
|
$this->expectExceptionCode($code);
|
|
|
|
} else {
|
|
|
|
// expecting a standard PHP exception
|
|
|
|
$this->expectException(\Exception::class);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function assertTime($exp, $test) {
|
2017-07-17 11:47:57 +00:00
|
|
|
$exp = Date::transform($exp, "iso8601");
|
|
|
|
$test = Date::transform($test, "iso8601");
|
2017-07-08 01:06:38 +00:00
|
|
|
$this->assertSame($exp, $test);
|
|
|
|
}
|
|
|
|
|
|
|
|
function clearData(bool $loadLang = true): bool {
|
2017-07-17 11:47:57 +00:00
|
|
|
$r = new \ReflectionClass(\JKingWeb\Arsse\Arsse::class);
|
2017-07-08 01:06:38 +00:00
|
|
|
$props = array_keys($r->getStaticProperties());
|
|
|
|
foreach($props as $prop) {
|
2017-07-17 11:47:57 +00:00
|
|
|
Arsse::$$prop = null;
|
2017-07-08 01:06:38 +00:00
|
|
|
}
|
|
|
|
if($loadLang) {
|
2017-07-17 11:47:57 +00:00
|
|
|
Arsse::$lang = new \JKingWeb\Arsse\Lang();
|
2017-07-08 01:06:38 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|