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);
|
2017-03-28 04:12:12 +00:00
|
|
|
namespace JKingWeb\Arsse;
|
2017-02-10 04:05:13 +00:00
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
use Phake;
|
2017-02-10 04:05:13 +00:00
|
|
|
|
2017-07-20 22:36:03 +00:00
|
|
|
/** @covers \JKingWeb\Arsse\AbstractException */
|
2017-07-08 01:06:38 +00:00
|
|
|
class TestException extends Test\AbstractTest {
|
2017-08-29 14:50:31 +00:00
|
|
|
public function setUp() {
|
2017-03-28 22:50:00 +00:00
|
|
|
$this->clearData(false);
|
2017-03-29 00:30:40 +00:00
|
|
|
// create a mock Lang object so as not to create a dependency loop
|
2017-07-17 11:47:57 +00:00
|
|
|
Arsse::$lang = Phake::mock(Lang::class);
|
|
|
|
Phake::when(Arsse::$lang)->msg->thenReturn("");
|
2017-02-16 20:29:42 +00:00
|
|
|
}
|
2017-02-10 04:05:13 +00:00
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function tearDown() {
|
2017-03-29 00:30:40 +00:00
|
|
|
// verify calls to the mock Lang object
|
2017-07-17 11:47:57 +00:00
|
|
|
Phake::verify(Arsse::$lang, Phake::atLeast(0))->msg($this->isType("string"), $this->anything());
|
|
|
|
Phake::verifyNoOtherInteractions(Arsse::$lang);
|
2017-03-29 00:30:40 +00:00
|
|
|
// clean up
|
2017-03-28 22:50:00 +00:00
|
|
|
$this->clearData(true);
|
2017-02-16 20:29:42 +00:00
|
|
|
}
|
2017-04-07 01:41:21 +00:00
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function testBaseClass() {
|
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
|
|
|
*/
|
2017-08-29 14:50:31 +00:00
|
|
|
public function testBaseClassWithoutMessage() {
|
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
|
|
|
*/
|
2017-08-29 14:50:31 +00:00
|
|
|
public function testDerivedClass() {
|
2017-02-16 20:29:42 +00:00
|
|
|
$this->assertException("fileMissing", "Lang");
|
|
|
|
throw new Lang\Exception("fileMissing");
|
|
|
|
}
|
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
|
|
|
*/
|
2017-08-29 14:50:31 +00:00
|
|
|
public function testDerivedClassWithMessageParameters() {
|
2017-02-16 20:29:42 +00:00
|
|
|
$this->assertException("fileMissing", "Lang");
|
|
|
|
throw new Lang\Exception("fileMissing", "en");
|
|
|
|
}
|
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
|
|
|
|
*/
|
2017-08-29 14:50:31 +00:00
|
|
|
public function testBaseClassWithUnknownCode() {
|
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
|
|
|
|
*/
|
2017-08-29 14:50:31 +00:00
|
|
|
public function testDerivedClassWithMissingMessage() {
|
2017-02-16 20:29:42 +00:00
|
|
|
$this->assertException("uncoded");
|
|
|
|
throw new Lang\Exception("testThisExceptionMessageDoesNotExist");
|
|
|
|
}
|
2017-02-10 04:05:13 +00:00
|
|
|
}
|