Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit 3a045fe

Browse files
michalbundyraweierophinney
authored andcommitted
Tests for marshalHeadersFromSapi function
- integer keys should be ignored - `_` should be changed to `-` in key (also for `CONTENT_*` headers)
1 parent aaf7c43 commit 3a045fe

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
/**
3+
* @see https://github.com/zendframework/zend-diactoros for the canonical source repository
4+
* @copyright Copyright (c) 2019 Zend Technologies USA Inc. (https://www.zend.com)
5+
* @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace ZendTest\Diactoros\functions;
11+
12+
use PHPUnit\Framework\TestCase;
13+
14+
use function Zend\Diactoros\marshalHeadersFromSapi;
15+
16+
class MarshalHeadersFromSapiTest extends TestCase
17+
{
18+
public function testReturnsHeaders() : void
19+
{
20+
$server = [
21+
'REDIRECT_CONTENT_FOO' => 'redirect-foo',
22+
'CONTENT_FOO' => null,
23+
'REDIRECT_CONTENT_BAR' => 'redirect-bar',
24+
'CONTENT_BAR' => '',
25+
'REDIRECT_CONTENT_BAZ' => 'redirect-baz',
26+
'CONTENT_BAZ' => 'baz',
27+
'REDIRECT_CONTENT_VAR' => 'redirect-var',
28+
29+
'REDIRECT_HTTP_ABC' => 'redirect-abc',
30+
'HTTP_ABC' => null,
31+
'REDIRECT_HTTP_DEF' => 'redirect-def',
32+
'HTTP_DEF' => '',
33+
'REDIRECT_HTTP_GHI' => 'redirect-ghi',
34+
'HTTP_GHI' => 'ghi',
35+
'REDIRECT_HTTP_JKL' => 'redirect-jkl',
36+
37+
'HTTP_TEST_MNO' => 'mno',
38+
'HTTP_TEST_PQR' => '',
39+
'HTTP_TEST_STU' => null,
40+
'CONTENT_TEST_VW' => 'vw',
41+
'CONTENT_TEST_XY' => '',
42+
'CONTENT_TEST_ZZ' => null,
43+
44+
123 => 'integer',
45+
];
46+
47+
$expectedHeaders = [
48+
'content-foo' => null,
49+
'content-baz' => 'baz',
50+
'content-var' => 'redirect-var',
51+
52+
'abc' => null,
53+
'ghi' => 'ghi',
54+
'jkl' => 'redirect-jkl',
55+
56+
'test-mno' => 'mno',
57+
'test-stu' => null,
58+
'content-test-vw' => 'vw',
59+
'content-test-zz' => null,
60+
];
61+
62+
$headers = marshalHeadersFromSapi($server);
63+
64+
self::assertSame($expectedHeaders, $headers);
65+
}
66+
}

0 commit comments

Comments
 (0)