1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* This file is part of the Numverify API Client for PHP. |
7
|
|
|
* |
8
|
|
|
* (c) 2024 Eric Sizemore <[email protected]> |
9
|
|
|
* (c) 2018-2021 Mark Rogoyski <[email protected]> |
10
|
|
|
* |
11
|
|
|
* This source file is subject to the MIT license. For the full copyright, |
12
|
|
|
* license information, and credits/acknowledgements, please view the LICENSE |
13
|
|
|
* and README files that were distributed with this source code. |
14
|
|
|
*/ |
15
|
|
|
|
16
|
|
|
namespace Numverify\Tests\Exception; |
17
|
|
|
|
18
|
|
|
use GuzzleHttp\Psr7\Response; |
19
|
|
|
use Numverify\Exception\NumverifyApiFailureException; |
20
|
|
|
use PHPUnit\Framework\Attributes\CoversClass; |
21
|
|
|
use PHPUnit\Framework\Attributes\TestDox; |
22
|
|
|
use PHPUnit\Framework\TestCase; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @internal |
26
|
|
|
*/ |
27
|
|
|
#[CoversClass(NumverifyApiFailureException::class)] |
28
|
|
|
class NumverifyApiFailureExceptionTest extends TestCase |
29
|
|
|
{ |
30
|
|
|
private const BODY = 'server error'; |
31
|
|
|
|
32
|
|
|
private const REASON_PHRASE = 'Internal Server Error'; |
33
|
|
|
private const STATUS_CODE = 500; |
34
|
|
|
|
35
|
|
|
private Response $response; |
36
|
|
|
|
37
|
|
|
protected function setUp(): void |
38
|
|
|
{ |
39
|
|
|
$this->response = new Response(self::STATUS_CODE, body: self::BODY, reason: self::REASON_PHRASE); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
#[TestDox('NumverifyApiFailureException can return body.')] |
43
|
|
|
public function testGetBody(): void |
44
|
|
|
{ |
45
|
|
|
$numverifyApiFailureException = new NumverifyApiFailureException($this->response); |
46
|
|
|
|
47
|
|
|
$body = $numverifyApiFailureException->getBody(); |
48
|
|
|
self::assertSame(self::BODY, $body); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
#[TestDox('NumverifyApiFailureException can return reason phrase.')] |
52
|
|
|
public function testGetReasonPhrase(): void |
53
|
|
|
{ |
54
|
|
|
$numverifyApiFailureException = new NumverifyApiFailureException($this->response); |
55
|
|
|
|
56
|
|
|
$reasonPhrase = $numverifyApiFailureException->getReasonPhrase(); |
57
|
|
|
self::assertSame(self::REASON_PHRASE, $reasonPhrase); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
#[TestDox('NumverifyApiFailureException can return status code.')] |
61
|
|
|
public function testGetStatusCode(): void |
62
|
|
|
{ |
63
|
|
|
$numverifyApiFailureException = new NumverifyApiFailureException($this->response); |
64
|
|
|
|
65
|
|
|
$statusCode = $numverifyApiFailureException->getStatusCode(); |
66
|
|
|
self::assertSame(self::STATUS_CODE, $statusCode); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|