-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathHttpStatusCodeTest.php
More file actions
92 lines (73 loc) · 2.44 KB
/
HttpStatusCodeTest.php
File metadata and controls
92 lines (73 loc) · 2.44 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
/*
* This file is part of https://github.com/josantonius/php-http-status-code repository.
*
* (c) Josantonius <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
*/
namespace Josantonius\HttpStatusCode\Tests;
use PHPUnit\Framework\TestCase;
use Josantonius\HttpStatusCode\HttpStatusCode;
use Josantonius\HttpStatusCode\Exceptions\UnsupportedLanguageException;
class HttpStatusCodeTest extends TestCase
{
protected $httpStatusCodeEs;
protected $httpStatusCodeEn;
public function setUp(): void
{
parent::setUp();
$this->httpStatusCodeEn = new HttpStatusCode();
$this->httpStatusCodeEs = new HttpStatusCode('es');
}
public function test_should_fail_if_unsupported_language_is_used()
{
$this->expectException(UnsupportedLanguageException::class);
new HttpStatusCode('fr');
}
public function test_should_get_message()
{
$this->assertEquals(
'Request Time-out',
$this->httpStatusCodeEn->getMessage(408)
);
$this->assertEquals(
'Solicitud de tiempo de espera',
$this->httpStatusCodeEs->getMessage(408)
);
}
public function test_should_get_messages()
{
$messages = $this->httpStatusCodeEn->getMessages();
$this->assertIsArray($messages);
$this->assertArrayHasKey(408, $messages);
}
public function test_should_get_definition()
{
$this->assertStringContainsString(
'The server timed out waiting for the request.',
$this->httpStatusCodeEn->getDefinition(408)
);
$this->assertStringContainsString(
'El cliente falló al continuar la petición',
$this->httpStatusCodeEs->getDefinition(408)
);
}
public function test_should_get_definitions()
{
$definitions = $this->httpStatusCodeEn->getDefinitions();
$this->assertIsArray($definitions);
$this->assertArrayHasKey(408, $definitions);
}
public function test_should_get_all()
{
$all = $this->httpStatusCodeEn->getAll();
$this->assertIsArray($all);
$this->assertArrayHasKey(408, $all);
$this->assertArrayHasKey('message', $all[408]);
$this->assertArrayHasKey('definition', $all[408]);
}
}