mirror of
https://code.mensbeam.com/MensBeam/Arsse.git
synced 2024-12-22 13:12:41 +00:00
Basic tests for exceptions
This commit is contained in:
parent
f78048317e
commit
2c134c76dc
5 changed files with 50 additions and 3 deletions
45
tests/TestException.php
Normal file
45
tests/TestException.php
Normal file
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace JKingWeb\NewsSync;
|
||||
|
||||
|
||||
class TestException extends \PHPUnit\Framework\TestCase {
|
||||
use TestingHelpers;
|
||||
|
||||
static function setUpBeforeClass() {
|
||||
Lang::set("");
|
||||
}
|
||||
|
||||
static function tearDownAfterClass() {
|
||||
Lang::set(Lang::DEFAULT);
|
||||
}
|
||||
|
||||
function testBasic() {
|
||||
$this->assertException("unknown");
|
||||
throw new Exception("unknown");
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testBasic
|
||||
*/
|
||||
function testPlain() {
|
||||
$this->assertException("unknown");
|
||||
throw new Exception();
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testBasic
|
||||
*/
|
||||
function testNamespace() {
|
||||
$this->assertException("fileMissing", "Lang");
|
||||
throw new Lang\Exception("fileMissing");
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testNamespace
|
||||
*/
|
||||
function testValues() {
|
||||
$this->assertException("fileMissing", "Lang");
|
||||
throw new Lang\Exception("fileMissing", "en");
|
||||
}
|
||||
}
|
|
@ -55,6 +55,6 @@ trait LanguageTestingHelpers {
|
|||
self::$vfs = null;
|
||||
self::$files = null;
|
||||
Lang::set("", true);
|
||||
Lang::set(Lang::DEFAULT, true);
|
||||
Lang::set(Lang::DEFAULT);
|
||||
}
|
||||
}
|
|
@ -12,6 +12,7 @@
|
|||
<testsuite name="Localization and exceptions">
|
||||
<file>TestLang.php</file>
|
||||
<file>TestLangComplex.php</file>
|
||||
<file>TestException.php</file>
|
||||
</testsuite>
|
||||
|
||||
<testsuite name="Configuration loading and saving">
|
||||
|
|
4
vendor/JKingWeb/NewsSync/Exception.php
vendored
4
vendor/JKingWeb/NewsSync/Exception.php
vendored
|
@ -41,8 +41,8 @@ class Exception extends \Exception {
|
|||
|
||||
public function __construct(string $msgID = "", $vars = null, \Throwable $e = null) {
|
||||
if($msgID=="") {
|
||||
$msg = "";
|
||||
$code = 0;
|
||||
$msg = "Exception.unknown";
|
||||
$code = 10000;
|
||||
} else {
|
||||
$codeID = str_replace("\\", "/", str_replace(NS_BASE, "", get_called_class())).".$msgID";
|
||||
if(!array_key_exists($codeID,self::CODES)) {
|
||||
|
|
1
vendor/JKingWeb/NewsSync/Lang.php
vendored
1
vendor/JKingWeb/NewsSync/Lang.php
vendored
|
@ -7,6 +7,7 @@ class Lang {
|
|||
const DEFAULT = "en";
|
||||
const REQUIRED = [
|
||||
'Exception.JKingWeb/NewsSync/Exception.uncoded' => 'The specified exception symbol {0} has no code specified in Exception.php',
|
||||
'Exception.JKingWeb/NewsSync/Exception.unknown' => 'An unknown error has occurred',
|
||||
'Exception.JKingWeb/NewsSync/Lang/Exception.defaultFileMissing' => 'Default language file "{0}" missing',
|
||||
'Exception.JKingWeb/NewsSync/Lang/Exception.fileMissing' => 'Language file "{0}" is not available',
|
||||
'Exception.JKingWeb/NewsSync/Lang/Exception.fileUnreadable' => 'Insufficient permissions to read language file "{0}"',
|
||||
|
|
Loading…
Reference in a new issue