2017-02-10 04:05:13 +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-02-10 04:05:13 +00:00
|
|
|
declare(strict_types=1);
|
2021-04-14 15:17:01 +00:00
|
|
|
|
2017-12-22 03:47:19 +00:00
|
|
|
namespace JKingWeb\Arsse\TestCase\Exception;
|
2017-02-10 04:05:13 +00:00
|
|
|
|
2017-12-22 03:47:19 +00:00
|
|
|
use JKingWeb\Arsse\Arsse;
|
|
|
|
use JKingWeb\Arsse\Lang;
|
|
|
|
use JKingWeb\Arsse\Exception;
|
|
|
|
use JKingWeb\Arsse\Lang\Exception as LangException;
|
2017-02-10 04:05:13 +00:00
|
|
|
|
2017-07-20 22:36:03 +00:00
|
|
|
/** @covers \JKingWeb\Arsse\AbstractException */
|
2017-12-22 03:47:19 +00:00
|
|
|
class TestException extends \JKingWeb\Arsse\Test\AbstractTest {
|
2019-10-16 18:42:43 +00:00
|
|
|
public function setUp(): void {
|
2018-11-23 15:01:17 +00:00
|
|
|
self::clearData(false);
|
2017-03-29 00:30:40 +00:00
|
|
|
// create a mock Lang object so as not to create a dependency loop
|
2023-11-11 22:22:13 +00:00
|
|
|
Arsse::$lang = \Phake::mock(Lang::class);
|
|
|
|
\Phake::when(Arsse::$lang)->msg->thenReturn("");
|
2017-02-16 20:29:42 +00:00
|
|
|
}
|
2017-04-07 01:41:21 +00:00
|
|
|
|
2020-01-20 18:52:48 +00:00
|
|
|
public function testBaseClass(): void {
|
2017-02-16 20:29:42 +00:00
|
|
|
$this->assertException("unknown");
|
|
|
|
throw new Exception("unknown");
|
|
|
|
}
|
2017-02-10 04:05:13 +00:00
|
|
|
|
2017-02-16 20:29:42 +00:00
|
|
|
/**
|
2017-02-11 18:50:34 +00:00
|
|
|
* @depends testBaseClass
|
2017-02-10 04:05:13 +00:00
|
|
|
*/
|
2020-01-20 18:52:48 +00:00
|
|
|
public function testBaseClassWithoutMessage(): void {
|
2017-02-16 20:29:42 +00:00
|
|
|
$this->assertException("unknown");
|
|
|
|
throw new Exception();
|
|
|
|
}
|
2017-04-07 01:41:21 +00:00
|
|
|
|
2017-02-16 20:29:42 +00:00
|
|
|
/**
|
2017-02-11 18:50:34 +00:00
|
|
|
* @depends testBaseClass
|
2017-02-10 04:05:13 +00:00
|
|
|
*/
|
2020-01-20 18:52:48 +00:00
|
|
|
public function testDerivedClass(): void {
|
2017-02-16 20:29:42 +00:00
|
|
|
$this->assertException("fileMissing", "Lang");
|
2017-12-22 03:47:19 +00:00
|
|
|
throw new LangException("fileMissing");
|
2017-02-16 20:29:42 +00:00
|
|
|
}
|
2017-02-10 04:05:13 +00:00
|
|
|
|
2017-02-16 20:29:42 +00:00
|
|
|
/**
|
2017-02-11 18:50:34 +00:00
|
|
|
* @depends testDerivedClass
|
2017-02-10 04:05:13 +00:00
|
|
|
*/
|
2020-01-20 18:52:48 +00:00
|
|
|
public function testDerivedClassWithMessageParameters(): void {
|
2017-02-16 20:29:42 +00:00
|
|
|
$this->assertException("fileMissing", "Lang");
|
2017-12-22 03:47:19 +00:00
|
|
|
throw new LangException("fileMissing", "en");
|
2017-02-16 20:29:42 +00:00
|
|
|
}
|
2017-02-11 18:50:34 +00:00
|
|
|
|
2017-02-16 20:29:42 +00:00
|
|
|
/**
|
2017-02-11 18:50:34 +00:00
|
|
|
* @depends testBaseClass
|
|
|
|
*/
|
2020-01-20 18:52:48 +00:00
|
|
|
public function testBaseClassWithUnknownCode(): void {
|
2017-02-16 20:29:42 +00:00
|
|
|
$this->assertException("uncoded");
|
|
|
|
throw new Exception("testThisExceptionMessageDoesNotExist");
|
|
|
|
}
|
2017-02-11 18:50:34 +00:00
|
|
|
|
2017-02-16 20:29:42 +00:00
|
|
|
/**
|
2017-02-11 18:50:34 +00:00
|
|
|
* @depends testBaseClassWithUnknownCode
|
|
|
|
*/
|
2020-01-20 18:52:48 +00:00
|
|
|
public function testDerivedClassWithMissingMessage(): void {
|
2017-02-16 20:29:42 +00:00
|
|
|
$this->assertException("uncoded");
|
2017-12-22 03:47:19 +00:00
|
|
|
throw new LangException("testThisExceptionMessageDoesNotExist");
|
2017-02-16 20:29:42 +00:00
|
|
|
}
|
2018-08-17 14:34:54 +00:00
|
|
|
|
|
|
|
/** @covers \JKingWeb\Arsse\ExceptionFatal */
|
2020-01-20 18:52:48 +00:00
|
|
|
public function testFatalException(): void {
|
2018-08-17 14:34:54 +00:00
|
|
|
$this->expectException('JKingWeb\Arsse\ExceptionFatal');
|
|
|
|
throw new \JKingWeb\Arsse\ExceptionFatal("");
|
|
|
|
}
|
2021-02-07 14:07:53 +00:00
|
|
|
|
|
|
|
public function testGetExceptionSymbol(): void {
|
|
|
|
$e = new LangException("stringMissing", ['msgID' => "OOK"]);
|
|
|
|
$this->assertSame("stringMissing", $e->getSymbol());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetExceptionParams(): void {
|
|
|
|
$e = new LangException("stringMissing", ['msgID' => "OOK"]);
|
|
|
|
$this->assertSame(['msgID' => "OOK"], $e->getParams());
|
|
|
|
}
|
2017-02-10 04:05:13 +00:00
|
|
|
}
|