This repository was archived by the owner on Dec 31, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathHeaderCustomTest.php
More file actions
94 lines (69 loc) · 2.44 KB
/
HeaderCustomTest.php
File metadata and controls
94 lines (69 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php declare(strict_types=1);
namespace Sunrise\Http\Header\Tests;
use PHPUnit\Framework\TestCase;
use Sunrise\Http\Header\HeaderInterface;
use Sunrise\Http\Header\HeaderCustom;
class HeaderCustomTest extends TestCase
{
public function testContracts()
{
$header = new HeaderCustom('foo', 'bar');
$this->assertInstanceOf(HeaderInterface::class, $header);
}
public function testFieldName()
{
$header = new HeaderCustom('foo', 'bar');
$this->assertSame('foo', $header->getFieldName());
}
public function testFieldValue()
{
$header = new HeaderCustom('foo', 'bar');
$this->assertSame('bar', $header->getFieldValue());
}
public function testInvalidFieldName()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Header field-name is invalid');
new HeaderCustom('@', 'value');
}
public function testInvalidFieldNameType()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Header field-name must be a string');
new HeaderCustom([], 'value');
}
public function testEmptyFieldValue()
{
$header = new HeaderCustom('foo', '');
$this->assertSame('', $header->getFieldValue());
}
public function testInvalidFieldValue()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Header field-value is invalid');
new HeaderCustom('foo', "\0");
}
public function testInvalidFieldValueType()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Header field-value must be a string');
new HeaderCustom('foo', []);
}
public function testBuild()
{
$header = new HeaderCustom('foo', 'bar');
$expected = \sprintf('%s: %s', $header->getFieldName(), $header->getFieldValue());
$this->assertSame($expected, $header->__toString());
}
public function testIterator()
{
$header = new HeaderCustom('foo', 'bar');
$iterator = $header->getIterator();
$iterator->rewind();
$this->assertSame($header->getFieldName(), $iterator->current());
$iterator->next();
$this->assertSame($header->getFieldValue(), $iterator->current());
$iterator->next();
$this->assertFalse($iterator->valid());
}
}