-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExceptionsTest.php
More file actions
54 lines (44 loc) · 1.66 KB
/
Copy pathExceptionsTest.php
File metadata and controls
54 lines (44 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
namespace Tests\Koded\Stdlib;
use Koded\Exceptions\{KodedException, SerializerException};
use PHPUnit\Framework\TestCase;
class ExceptionsTest extends TestCase
{
public function testSerializerExceptionForMissingModule()
{
$this->expectException(SerializerException::class);
$this->expectExceptionMessage('[Dependency error] "fubar" module is not installed on this machine');
$this->expectExceptionCode(424);
throw SerializerException::forMissingModule('fubar');
}
public function testSerializerExceptionForCreate()
{
$this->expectException(SerializerException::class);
$this->expectExceptionMessage('Failed to create a serializer for "fubar"');
$this->expectExceptionCode(409);
throw SerializerException::forCreateSerializer('fubar');
}
public function testGenericException()
{
$this->expectException(KodedException::class);
$this->expectExceptionMessage('hello');
$this->expectExceptionCode(1003);
throw KodedException::generic('hello');
}
public function testCreateExceptionFromOtherException()
{
$this->expectException(KodedException::class);
$this->expectExceptionMessage('test');
$this->expectExceptionCode(123);
$other = new \OutOfBoundsException('test', 123);
throw KodedException::from($other);
}
public function testCreateExceptionFromError()
{
$this->expectException(KodedException::class);
$this->expectExceptionMessage('test');
$this->expectExceptionCode(1);
$other = new \Error('test', 1);
throw KodedException::from($other);
}
}