diff --git a/tests/TestException.php b/tests/TestException.php new file mode 100644 index 00000000..434fd085 --- /dev/null +++ b/tests/TestException.php @@ -0,0 +1,45 @@ +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"); + } +} diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 470d86a2..c4c2368c 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -55,6 +55,6 @@ trait LanguageTestingHelpers { self::$vfs = null; self::$files = null; Lang::set("", true); - Lang::set(Lang::DEFAULT, true); + Lang::set(Lang::DEFAULT); } } \ No newline at end of file diff --git a/tests/phpunit.xml b/tests/phpunit.xml index 2e2fb7ff..8b1dbd80 100644 --- a/tests/phpunit.xml +++ b/tests/phpunit.xml @@ -12,6 +12,7 @@ TestLang.php TestLangComplex.php + TestException.php diff --git a/vendor/JKingWeb/NewsSync/Exception.php b/vendor/JKingWeb/NewsSync/Exception.php index 93b869fb..2e61d689 100644 --- a/vendor/JKingWeb/NewsSync/Exception.php +++ b/vendor/JKingWeb/NewsSync/Exception.php @@ -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)) { diff --git a/vendor/JKingWeb/NewsSync/Lang.php b/vendor/JKingWeb/NewsSync/Lang.php index ed47ae45..9ae9e681 100644 --- a/vendor/JKingWeb/NewsSync/Lang.php +++ b/vendor/JKingWeb/NewsSync/Lang.php @@ -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}"',