|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Spiral Framework. |
|
5
|
|
|
* |
|
6
|
|
|
* @license MIT |
|
7
|
|
|
* @author Anton Titov (Wolfy-J) |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
declare(strict_types=1); |
|
11
|
|
|
|
|
12
|
|
|
namespace Spiral\Tests\Http; |
|
13
|
|
|
|
|
14
|
|
|
use PHPUnit\Framework\TestCase; |
|
15
|
|
|
use Spiral\Http\Exception; |
|
16
|
|
|
use Spiral\Http\Exception\ClientException; |
|
17
|
|
|
use Spiral\Http\Exception\ClientException\BadRequestException; |
|
18
|
|
|
use Spiral\Http\Exception\ClientException\ForbiddenException; |
|
19
|
|
|
use Spiral\Http\Exception\ClientException\NotFoundException; |
|
20
|
|
|
use Spiral\Http\Exception\ClientException\ServerErrorException; |
|
21
|
|
|
use Spiral\Http\Exception\ClientException\UnauthorizedException; |
|
22
|
|
|
use Spiral\Http\Exception\HttpException; |
|
23
|
|
|
|
|
24
|
|
|
class ExceptionsTest extends TestCase |
|
25
|
|
|
{ |
|
26
|
|
|
public function testClientException(): void |
|
27
|
|
|
{ |
|
28
|
|
|
$e = new ClientException(); |
|
29
|
|
|
$this->assertSame(400, $e->getCode()); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function testNotFound(): void |
|
33
|
|
|
{ |
|
34
|
|
|
$e = new NotFoundException(); |
|
35
|
|
|
$this->assertSame(404, $e->getCode()); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function testBadRequest(): void |
|
39
|
|
|
{ |
|
40
|
|
|
$e = new BadRequestException(); |
|
41
|
|
|
$this->assertSame(400, $e->getCode()); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function testForbidden(): void |
|
45
|
|
|
{ |
|
46
|
|
|
$e = new ForbiddenException(); |
|
47
|
|
|
$this->assertSame(403, $e->getCode()); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function testUnauthorized(): void |
|
51
|
|
|
{ |
|
52
|
|
|
$e = new UnauthorizedException(); |
|
53
|
|
|
$this->assertSame(401, $e->getCode()); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function testServerError(): void |
|
57
|
|
|
{ |
|
58
|
|
|
$e = new ServerErrorException(); |
|
59
|
|
|
$this->assertSame(500, $e->getCode()); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @dataProvider allExceptionsWithPreviousSet |
|
64
|
|
|
*/ |
|
65
|
|
|
public function testPreviousSetter(\Throwable $exception): void |
|
66
|
|
|
{ |
|
67
|
|
|
$this->assertInstanceOf(\Throwable::class, $exception->getPrevious()); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function allExceptionsWithPreviousSet(): \Generator |
|
71
|
|
|
{ |
|
72
|
|
|
yield [new Exception\ClientException\BadRequestException('', new \Exception())]; |
|
73
|
|
|
yield [new Exception\ClientException\ForbiddenException('', new \Exception())]; |
|
74
|
|
|
yield [new Exception\ClientException\NotFoundException('', new \Exception())]; |
|
75
|
|
|
yield [new Exception\ClientException\ServerErrorException('', new \Exception())]; |
|
76
|
|
|
yield [new Exception\ClientException\UnauthorizedException('', new \Exception())]; |
|
77
|
|
|
yield [new Exception\ClientException(0, '', new \Exception())]; |
|
78
|
|
|
yield [new Exception\DotNotFoundException('', 0, new \Exception())]; |
|
79
|
|
|
yield [new Exception\EmitterException('', 0, new \Exception())]; |
|
80
|
|
|
yield [new Exception\HttpException('', 0, new \Exception())]; |
|
81
|
|
|
yield [new Exception\InputException('', 0, new \Exception())]; |
|
82
|
|
|
yield [new Exception\PipelineException('', 0, new \Exception())]; |
|
83
|
|
|
yield [new Exception\ResponseException('', 0, new \Exception())]; |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|