2017-07-08 01:06:38 +00:00
|
|
|
<?php
|
2017-11-17 01:23:18 +00:00
|
|
|
/** @license MIT
|
|
|
|
* Copyright 2017 J. King, Dustin Wilson et al.
|
|
|
|
* See LICENSE and AUTHORS files for details */
|
|
|
|
|
2017-07-08 01:06:38 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
namespace JKingWeb\Arsse\Test;
|
2017-08-29 14:50:31 +00:00
|
|
|
|
2017-07-08 01:06:38 +00:00
|
|
|
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
|
|
|
|
2017-07-20 22:36:03 +00:00
|
|
|
/** @coversNothing */
|
2017-07-08 01:06:38 +00:00
|
|
|
abstract class AbstractTest extends \PHPUnit\Framework\TestCase {
|
2017-08-29 14:50:31 +00:00
|
|
|
public function assertException(string $msg = "", string $prefix = "", string $type = "Exception") {
|
|
|
|
if (func_num_args()) {
|
2017-07-08 01:06:38 +00:00
|
|
|
$class = \JKingWeb\Arsse\NS_BASE . ($prefix !== "" ? str_replace("/", "\\", $prefix) . "\\" : "") . $type;
|
|
|
|
$msgID = ($prefix !== "" ? $prefix . "/" : "") . $type. ".$msg";
|
2017-08-29 14:50:31 +00:00
|
|
|
if (array_key_exists($msgID, Exception::CODES)) {
|
2017-07-08 01:06:38 +00:00
|
|
|
$code = Exception::CODES[$msgID];
|
|
|
|
} else {
|
|
|
|
$code = 0;
|
|
|
|
}
|
|
|
|
$this->expectException($class);
|
|
|
|
$this->expectExceptionCode($code);
|
|
|
|
} else {
|
|
|
|
// expecting a standard PHP exception
|
|
|
|
$this->expectException(\Exception::class);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-28 02:25:45 +00:00
|
|
|
public function assertTime($exp, $test, string $msg = null) {
|
2017-07-17 11:47:57 +00:00
|
|
|
$exp = Date::transform($exp, "iso8601");
|
|
|
|
$test = Date::transform($test, "iso8601");
|
2017-09-28 02:25:45 +00:00
|
|
|
$this->assertSame($exp, $test, $msg);
|
2017-07-08 01:06:38 +00:00
|
|
|
}
|
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public 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());
|
2017-08-29 14:50:31 +00:00
|
|
|
foreach ($props as $prop) {
|
2017-07-17 11:47:57 +00:00
|
|
|
Arsse::$$prop = null;
|
2017-07-08 01:06:38 +00:00
|
|
|
}
|
2017-08-29 14:50:31 +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;
|
|
|
|
}
|
2017-08-29 14:50:31 +00:00
|
|
|
}
|