HeaderFactoryTest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testSplittingBadValue() 0 5 1
A testSimpleHeaderSplitting() 0 8 1
A testValuelessHeader() 0 5 1
A testMissingHeaderCreation() 0 5 1
A testInstantiatedHeader() 0 5 1
A provideInstantiatedHeader() 0 17 1
1
<?php
2
3
4
namespace Fracture\Http;
5
6
use Exception;
7
use ReflectionClass;
8
use PHPUnit_Framework_TestCase;
9
10
class HeaderFactoryTest extends PHPUnit_Framework_TestCase
11
{
12
13
14
15
16
17
    /**
18
     * @covers Fracture\Http\HeaderFactory::splitEntry
19
     */
20
    public function testSplittingBadValue()
21
    {
22
        $factory = new HeaderFactory;
23
        $this->assertFalse($factory->splitEntry('Random text'));
24
    }
25
26
27
    /**
28
     * @covers Fracture\Http\HeaderFactory::splitEntry
29
     */
30
    public function testSimpleHeaderSplitting()
31
    {
32
        $factory = new HeaderFactory;
33
        $this->assertEquals([
34
            'Content-Type',
35
            'text/plain',
36
        ], $factory->splitEntry('Content-Type: text/plain'));
37
    }
38
39
40
41
    /**
42
     * @covers Fracture\Http\HeaderFactory::create
43
     */
44
    public function testValuelessHeader()
45
    {
46
        $factory = new HeaderFactory;
47
        $this->assertNull($factory->create('Muahahahaha'));
48
    }
49
50
51
    /**
52
     * @covers Fracture\Http\HeaderFactory::create
53
     */
54
    public function testMissingHeaderCreation()
55
    {
56
        $factory = new HeaderFactory;
57
        $this->assertNull($factory->create('Bad: cookie'));
58
    }
59
60
61
    /**
62
     * @dataProvider provideInstantiatedHeader
63
     *
64
     * @covers Fracture\Http\HeaderFactory::create
65
     */
66
    public function testInstantiatedHeader($expected, $parameter)
67
    {
68
        $factory = new HeaderFactory;
69
        $this->assertInstanceOf('' . $expected, $factory->create($parameter));
70
    }
71
72
73
    public function provideInstantiatedHeader()
74
    {
75
        return [
76
            [
77
                'expected' => '\Fracture\Http\Headers\Location',
78
                'parameter' => 'Location: /alpha/beta',
79
            ],
80
            [
81
                'expected' => '\Fracture\Http\Headers\ContentType',
82
                'parameter' => 'Content-Type: text/plain',
83
            ],
84
            [
85
                'expected' => '\Fracture\Http\Headers\ContentDisposition',
86
                'parameter' => 'Content-Disposition: form-data; name="text"',
87
            ],
88
        ];
89
    }
90
}
91