2017-02-09 23:05:13 -05:00
|
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
2017-03-27 23:12:12 -05:00
|
|
|
namespace JKingWeb\Arsse;
|
2017-03-28 20:30:40 -04:00
|
|
|
Use Phake;
|
2017-02-09 23:05:13 -05:00
|
|
|
|
|
|
|
|
|
|
|
class TestException extends \PHPUnit\Framework\TestCase {
|
2017-02-16 14:29:42 -06:00
|
|
|
use Test\Tools;
|
2017-02-09 23:05:13 -05:00
|
|
|
|
2017-03-28 18:50:00 -04:00
|
|
|
function setUp() {
|
|
|
|
$this->clearData(false);
|
2017-03-28 20:30:40 -04:00
|
|
|
// create a mock Lang object so as not to create a dependency loop
|
|
|
|
Data::$l = Phake::mock(Lang::class);
|
|
|
|
Phake::when(Data::$l)->msg->thenReturn("");
|
2017-02-16 14:29:42 -06:00
|
|
|
}
|
2017-02-09 23:05:13 -05:00
|
|
|
|
2017-03-28 18:50:00 -04:00
|
|
|
function tearDown() {
|
2017-03-28 20:30:40 -04:00
|
|
|
// verify calls to the mock Lang object
|
|
|
|
Phake::verify(Data::$l, Phake::atLeast(0))->msg($this->isType("string"), $this->anything());
|
|
|
|
Phake::verifyNoOtherInteractions(Data::$l);
|
|
|
|
// clean up
|
2017-03-28 18:50:00 -04:00
|
|
|
$this->clearData(true);
|
2017-02-16 14:29:42 -06:00
|
|
|
}
|
2017-04-06 21:41:21 -04:00
|
|
|
|
2017-02-16 14:29:42 -06:00
|
|
|
function testBaseClass() {
|
|
|
|
$this->assertException("unknown");
|
|
|
|
throw new Exception("unknown");
|
|
|
|
}
|
2017-02-09 23:05:13 -05:00
|
|
|
|
2017-02-16 14:29:42 -06:00
|
|
|
/**
|
2017-02-11 13:50:34 -05:00
|
|
|
* @depends testBaseClass
|
2017-02-09 23:05:13 -05:00
|
|
|
*/
|
2017-02-16 14:29:42 -06:00
|
|
|
function testBaseClassWithoutMessage() {
|
|
|
|
$this->assertException("unknown");
|
|
|
|
throw new Exception();
|
|
|
|
}
|
2017-04-06 21:41:21 -04:00
|
|
|
|
2017-02-16 14:29:42 -06:00
|
|
|
/**
|
2017-02-11 13:50:34 -05:00
|
|
|
* @depends testBaseClass
|
2017-02-09 23:05:13 -05:00
|
|
|
*/
|
2017-02-16 14:29:42 -06:00
|
|
|
function testDerivedClass() {
|
|
|
|
$this->assertException("fileMissing", "Lang");
|
|
|
|
throw new Lang\Exception("fileMissing");
|
|
|
|
}
|
2017-02-09 23:05:13 -05:00
|
|
|
|
2017-02-16 14:29:42 -06:00
|
|
|
/**
|
2017-02-11 13:50:34 -05:00
|
|
|
* @depends testDerivedClass
|
2017-02-09 23:05:13 -05:00
|
|
|
*/
|
2017-02-16 14:29:42 -06:00
|
|
|
function testDerivedClassWithMessageParameters() {
|
|
|
|
$this->assertException("fileMissing", "Lang");
|
|
|
|
throw new Lang\Exception("fileMissing", "en");
|
|
|
|
}
|
2017-02-11 13:50:34 -05:00
|
|
|
|
2017-02-16 14:29:42 -06:00
|
|
|
/**
|
2017-02-11 13:50:34 -05:00
|
|
|
* @depends testBaseClass
|
|
|
|
*/
|
2017-02-16 14:29:42 -06:00
|
|
|
function testBaseClassWithUnknownCode() {
|
|
|
|
$this->assertException("uncoded");
|
|
|
|
throw new Exception("testThisExceptionMessageDoesNotExist");
|
|
|
|
}
|
2017-02-11 13:50:34 -05:00
|
|
|
|
2017-02-16 14:29:42 -06:00
|
|
|
/**
|
2017-02-11 13:50:34 -05:00
|
|
|
* @depends testBaseClassWithUnknownCode
|
|
|
|
*/
|
2017-02-16 14:29:42 -06:00
|
|
|
function testDerivedClassWithMissingMessage() {
|
|
|
|
$this->assertException("uncoded");
|
|
|
|
throw new Lang\Exception("testThisExceptionMessageDoesNotExist");
|
|
|
|
}
|
2017-02-09 23:05:13 -05:00
|
|
|
}
|