Passed
Pull Request — master (#17)
by Mihail
15:10
created

test_should_set_the_associative_header_array()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 7
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 11
rs 10
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