HttpExceptionTest::providerForTestHttpException()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
dl 0
loc 10
c 1
b 0
f 0
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Elmage\TextNg\Test\Unit\Exception;
4
5
use Elmage\TextNg\Client;
6
use Elmage\TextNg\Exception\BadRequestException;
7
use Elmage\TextNg\Exception\HttpException;
8
use Elmage\TextNg\Exception\InternalServerException;
9
use Elmage\TextNg\Exception\NotFoundException;
10
use Elmage\TextNg\Exception\ServiceUnavailableException;
11
use Elmage\TextNg\Exception\UnauthorizedException;
12
use Elmage\TextNg\Exception\ValidationException;
13
use Elmage\TextNg\HttpClient;
14
use Elmage\TextNg\Test\TestCase;
15
use GuzzleHttp\Exception\RequestException;
16
use GuzzleHttp\Psr7\Request;
17
use GuzzleHttp\Psr7\Response;
18
use Psr\Http\Message\RequestInterface;
19
20
class HttpExceptionTest extends TestCase
21
{
22
23
    /**
24
     * @dataProvider providerForTestHttpException
25
     */
26
    public function testHttpException($statusCode)
27
    {
28
        $request = new Request('GET', "http://example.com");
29
        $response = new Response($statusCode);
30
31
        $exception = RequestException::create($request, $response);
32
33
        $e = HttpException::wrap($exception);
34
35
        switch ($statusCode) {
36
            case 400:
37
                $this->assertInstanceOf(BadRequestException::class, $e);
38
                break;
39
            case 401:
40
                $this->assertInstanceOf(UnauthorizedException::class, $e);
41
                break;
42
            case 404:
43
                $this->assertInstanceOf(NotFoundException::class, $e);
44
                break;
45
            case 422:
46
                $this->assertInstanceOf(ValidationException::class, $e);
47
                break;
48
            case 500:
49
                $this->assertInstanceOf(InternalServerException::class, $e);
50
                break;
51
            case 503:
52
                $this->assertInstanceOf(ServiceUnavailableException::class, $e);
53
                break;
54
            default:
55
                $this->assertInstanceOf(HttpException::class, $e);
56
                break;
57
        }
58
59
        $this->assertEquals($request, $e->getRequest());
60
        $this->assertEquals($response, $e->getResponse());
61
        $this->assertEquals($statusCode, $e->getStatusCode());
62
    }
63
64
    public function providerForTestHttpException()
65
    {
66
        return [
67
            [400],
68
            [401],
69
            [404],
70
            [422],
71
            [500],
72
            [503],
73
            [505]
74
        ];
75
    }
76
}
77