Skip to content

Commit 5e206e7

Browse files
Added some missing tests for Headers class
1 parent 6c0fee2 commit 5e206e7

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"lint": "php-cs-fixer fix",
3232
"pr": [
3333
"php-cs-fixer fix --dry-run -vvv",
34-
"psalm --stats",
34+
"psalm --no-cache --stats",
3535
"phpunit --testdox --coverage-text"
3636
]
3737
},

tests/HeadersTest.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
namespace MNC\Http;
4+
5+
use PHPUnit\Framework\TestCase;
6+
7+
/**
8+
* Class HeadersTest
9+
* @package MNC\Http
10+
*/
11+
class HeadersTest extends TestCase
12+
{
13+
public function testItConvertsToArrayProperly(): void
14+
{
15+
$headers = Headers::fromMap([
16+
'Content-Type' => 'application/json',
17+
'Content-Length' => '3532',
18+
'Server' => 'nginx'
19+
]);
20+
21+
$lines = $headers->toArray();
22+
23+
self::assertSame('content-type: application/json', $lines[0]);
24+
self::assertSame('content-length: 3532', $lines[1]);
25+
self::assertSame('server: nginx', $lines[2]);
26+
self::assertCount(3, $lines);
27+
}
28+
29+
public function testFilter(): void
30+
{
31+
$headers = Headers::fromMap([
32+
'Content-Type' => 'application/json',
33+
'Content-Length' => '3532',
34+
'Server' => 'nginx'
35+
]);
36+
37+
$headers = $headers->filter(fn($value, $name) => $name !== 'server');
38+
39+
self::assertCount(2, $headers);
40+
self::assertArrayHasKey('content-type', $headers);
41+
self::assertArrayHasKey('content-length', $headers);
42+
self::assertArrayNotHasKey('server', $headers);
43+
}
44+
}

0 commit comments

Comments
 (0)