1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Koded\Exceptions; |
4
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
6
|
|
|
|
7
|
|
|
class ExceptionsTest extends TestCase |
8
|
|
|
{ |
9
|
|
|
|
10
|
|
|
public function testSerializerExceptionForMissingModule() |
11
|
|
|
{ |
12
|
|
|
$this->expectException(SerializerException::class); |
13
|
|
|
$this->expectExceptionMessage('[Dependency error] "fubar" module is not installed on this machine'); |
14
|
|
|
$this->expectExceptionCode(424); |
15
|
|
|
throw SerializerException::forMissingModule('fubar'); |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
public function testSerializerExceptionForCreate() |
19
|
|
|
{ |
20
|
|
|
$this->expectException(SerializerException::class); |
21
|
|
|
$this->expectExceptionMessage('Failed to create a serializer for "fubar"'); |
22
|
|
|
$this->expectExceptionCode(409); |
23
|
|
|
throw SerializerException::forCreateSerializer('fubar'); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function testGenericException() |
27
|
|
|
{ |
28
|
|
|
$this->expectException(KodedException::class); |
29
|
|
|
$this->expectExceptionMessage('hello'); |
30
|
|
|
$this->expectExceptionCode(1002); |
31
|
|
|
throw KodedException::generic('hello'); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function testCreateExceptionFromOtherException() |
35
|
|
|
{ |
36
|
|
|
$this->expectException(KodedException::class); |
37
|
|
|
$this->expectExceptionMessage('test'); |
38
|
|
|
$this->expectExceptionCode(123); |
39
|
|
|
|
40
|
|
|
$other = new \OutOfBoundsException('test', 123); |
41
|
|
|
throw KodedException::from($other); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function testCreateExceptionFromError() |
45
|
|
|
{ |
46
|
|
|
$this->expectException(KodedException::class); |
47
|
|
|
$this->expectExceptionMessage('test'); |
48
|
|
|
$this->expectExceptionCode(1); |
49
|
|
|
|
50
|
|
|
$other = new \Error('test', 1); |
51
|
|
|
throw KodedException::from($other); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|