-
Notifications
You must be signed in to change notification settings - Fork 63
Expand file tree
/
Copy pathHeaderTest.php
More file actions
53 lines (41 loc) · 1.41 KB
/
HeaderTest.php
File metadata and controls
53 lines (41 loc) · 1.41 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
<?php declare(strict_types=1);
namespace App\Tests\Unit\HttpClient;
use App\HttpClient\Exception\InvalidHeaderKey;
use App\HttpClient\Exception\InvalidHeaderValue;
use App\HttpClient\Header;
use PHPUnit\Framework\TestCase;
class HeaderTest extends TestCase
{
public function testCreateFromStringCorrectlyParsesAHeaderString(): void
{
$header = Header::createFromString('Foo: Bar');
$this->assertSame('Foo', $header->getKey());
$this->assertSame('Bar', $header->getValue());
}
public function testKeyMaintainsOriginalCasing(): void
{
$this->assertSame('fOo', (new Header('fOo', 'bar'))->getKey());
}
public function testKeyGetsNormalized(): void
{
$this->assertSame('foo-foo', (new Header('fOo-FOO', 'bar'))->getNormalizedKey());
}
public function testGetValue(): void
{
$this->assertSame('bar', (new Header('foo', 'bar'))->getValue());
}
public function testHeaderInjectionIsPreventedOnTheKey(): void
{
$this->expectException(InvalidHeaderKey::class);
new Header("foo\r\nbar", 'bar');
}
public function testHeaderInjectionIsPreventedOnTheValue(): void
{
$this->expectException(InvalidHeaderValue::class);
new Header('Foo', "foo\r\nbar");
}
public function testToString(): void
{
$this->assertSame("Foo: Bar\r\n", (new Header('Foo', 'Bar'))->toString());
}
}