|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Tests\Koded\Http; |
|
4
|
|
|
|
|
5
|
|
|
use Koded\Http\ClientRequest; |
|
6
|
|
|
use Koded\Http\Interfaces\HttpMethod; |
|
7
|
|
|
use Koded\Http\Interfaces\HttpStatus; |
|
8
|
|
|
use PHPUnit\Framework\TestCase; |
|
9
|
|
|
|
|
10
|
|
|
class ClientRequestHeadersTest extends TestCase |
|
11
|
|
|
{ |
|
12
|
|
|
const URI = 'https://example.org'; |
|
13
|
|
|
|
|
14
|
|
|
public function test_should_set_the_associative_header_array() |
|
15
|
|
|
{ |
|
16
|
|
|
$request = new ClientRequest(HttpMethod::POST, self::URI, null, [ |
|
17
|
|
|
'Authorization' => 'Bearer 1234567890', |
|
18
|
|
|
'X_CUSTOM_CRAP' => 'Hello', |
|
19
|
|
|
'Other-Creative-Junk' => 'Useless value' |
|
20
|
|
|
]); |
|
21
|
|
|
|
|
22
|
|
|
$this->assertSame(['Bearer 1234567890'], $request->getHeader('authOriZAtioN')); |
|
23
|
|
|
$this->assertSame(['Hello'], $request->getHeader('X-Custom-Crap')); |
|
24
|
|
|
$this->assertSame(['Useless value'], $request->getHeader('other-creative-junk')); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function test_should_throw_exception_for_invalid_header_array() |
|
28
|
|
|
{ |
|
29
|
|
|
$this->expectException(\InvalidArgumentException::class); |
|
30
|
|
|
$this->expectExceptionCode(HttpStatus::BAD_REQUEST); |
|
31
|
|
|
$this->expectExceptionMessage('must be of type string, int given'); |
|
32
|
|
|
|
|
33
|
|
|
new ClientRequest(HttpMethod::POST, self::URI, null, [ |
|
34
|
|
|
'Authorization: Bearer 1234567890', |
|
35
|
|
|
'X_CUSTOM_CRAP: Hello' |
|
36
|
|
|
]); |
|
37
|
|
|
} |
|
38
|
|
|
} |
|
39
|
|
|
|