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
|
|
|
|