1
1
Fork 0
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:
J. King 2017-02-09 23:05:13 -05:00
parent f78048317e
commit 2c134c76dc
5 changed files with 50 additions and 3 deletions

45
tests/TestException.php Normal file
View 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");
}
}

View file

@ -55,6 +55,6 @@ trait LanguageTestingHelpers {
self::$vfs = null; self::$vfs = null;
self::$files = null; self::$files = null;
Lang::set("", true); Lang::set("", true);
Lang::set(Lang::DEFAULT, true); Lang::set(Lang::DEFAULT);
} }
} }

View file

@ -12,6 +12,7 @@
<testsuite name="Localization and exceptions"> <testsuite name="Localization and exceptions">
<file>TestLang.php</file> <file>TestLang.php</file>
<file>TestLangComplex.php</file> <file>TestLangComplex.php</file>
<file>TestException.php</file>
</testsuite> </testsuite>
<testsuite name="Configuration loading and saving"> <testsuite name="Configuration loading and saving">

View file

@ -41,8 +41,8 @@ class Exception extends \Exception {
public function __construct(string $msgID = "", $vars = null, \Throwable $e = null) { public function __construct(string $msgID = "", $vars = null, \Throwable $e = null) {
if($msgID=="") { if($msgID=="") {
$msg = ""; $msg = "Exception.unknown";
$code = 0; $code = 10000;
} else { } else {
$codeID = str_replace("\\", "/", str_replace(NS_BASE, "", get_called_class())).".$msgID"; $codeID = str_replace("\\", "/", str_replace(NS_BASE, "", get_called_class())).".$msgID";
if(!array_key_exists($codeID,self::CODES)) { if(!array_key_exists($codeID,self::CODES)) {

View file

@ -7,6 +7,7 @@ class Lang {
const DEFAULT = "en"; const DEFAULT = "en";
const REQUIRED = [ const REQUIRED = [
'Exception.JKingWeb/NewsSync/Exception.uncoded' => 'The specified exception symbol {0} has no code specified in Exception.php', '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.defaultFileMissing' => 'Default language file "{0}" missing',
'Exception.JKingWeb/NewsSync/Lang/Exception.fileMissing' => 'Language file "{0}" is not available', '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}"', 'Exception.JKingWeb/NewsSync/Lang/Exception.fileUnreadable' => 'Insufficient permissions to read language file "{0}"',