HeaderFactoryTest::testSimpleHeaderSplitting()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

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