1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2025-01-24 20:10:34 +00:00
Arsse/tests/Exception/TestException.php

69 lines
1.9 KiB
PHP
Raw Normal View History

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