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

ClientRequestHeadersTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 15
c 1
b 0
f 1
dl 0
loc 26
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A test_should_throw_exception_for_invalid_header_array() 0 9 1
A test_should_set_the_associative_header_array() 0 11 1
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