AbstractMessageTest   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 1
c 4
b 0
f 0
lcom 1
cbo 1
dl 0
loc 47
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B testAllHeaders() 0 36 1
1
<?php
2
/**
3
 * This file is part of the beebot package.
4
 * For the full copyright and license information, please view the LICENSE
5
 * file that was distributed with this source code.
6
 *
7
 * @copyright Bee4 2015
8
 * @author    Stephane HULARD <[email protected]>
9
 * @package   Bee4\Test\Transport\Message
10
 */
11
12
namespace Bee4\Test\Transport\Message;
13
14
use Bee4\PHPUnit\HttpClientTestCase;
15
16
/**
17
 * AbstractMessage unit test definition
18
 * @package Bee4\Test\Transport\Message
19
 */
20
class AbstractMessageTest extends HttpClientTestCase
21
{
22
    /**
23
     * @var \Bee4\Transport\Message\AbstractMessage
24
     */
25
    protected $object;
26
27
    /**
28
     * Test all headers collection manipulation function
29
     */
30
    public function testAllHeaders()
31
    {
32
        $mock = $this->getMockForAbstractClass(
33
            '\Bee4\Transport\Message\AbstractMessage'
34
        );
35
36
        $mock->addHeader('Content-Type', 'text/html');
37
        $this->assertTrue($mock->hasHeader('Content-Type'));
38
        $this->assertFalse($mock->hasHeader('Content-Length'));
39
40
        $this->assertNull($mock->getHeader('Content-Length'));
41
        $this->assertEquals('text/html', $mock->getHeader('Content-Type'));
42
43
        $headers = [
44
            'Content-Type' => 'application/json',
45
            'Content-Length' => 0,
46
            'X-Test: Value'
47
        ];
48
        $mock->addHeaders($headers);
49
50
        unset($headers[0]);
51
        $headers['X-Test'] = "Value";
52
        $this->assertEquals($headers, $mock->getHeaders());
53
        $this->assertEquals("Value", $mock->getHeader('X-Test'));
54
55
        $this->assertEquals([
56
            "Content-Type: application/json",
57
            "Content-Length: 0",
58
            'X-Test: Value'
59
        ], $mock->getHeaderLines());
60
61
        $mock->removeHeader('Content-Type');
62
        $this->assertNull($mock->getHeader('Content-Type'));
63
        $mock->removeHeaders();
64
        $this->assertCount(0, $mock->getHeaders());
65
    }
66
}
67