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

Commit

Permalink
Tests for marshalHeadersFromSapi function
Browse files Browse the repository at this point in the history
- integer keys should be ignored
- `_` should be changed to `-` in key (also for `CONTENT_*` headers)
  • Loading branch information
michalbundyra authored and weierophinney committed Oct 8, 2019
1 parent aaf7c43 commit 3a045fe
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions test/functions/MarshalHeadersFromSapiTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php
/**
* @see https://github.com/zendframework/zend-diactoros for the canonical source repository
* @copyright Copyright (c) 2019 Zend Technologies USA Inc. (https://www.zend.com)
* @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
*/

declare(strict_types=1);

namespace ZendTest\Diactoros\functions;

use PHPUnit\Framework\TestCase;

use function Zend\Diactoros\marshalHeadersFromSapi;

class MarshalHeadersFromSapiTest extends TestCase
{
public function testReturnsHeaders() : void
{
$server = [
'REDIRECT_CONTENT_FOO' => 'redirect-foo',
'CONTENT_FOO' => null,
'REDIRECT_CONTENT_BAR' => 'redirect-bar',
'CONTENT_BAR' => '',
'REDIRECT_CONTENT_BAZ' => 'redirect-baz',
'CONTENT_BAZ' => 'baz',
'REDIRECT_CONTENT_VAR' => 'redirect-var',

'REDIRECT_HTTP_ABC' => 'redirect-abc',
'HTTP_ABC' => null,
'REDIRECT_HTTP_DEF' => 'redirect-def',
'HTTP_DEF' => '',
'REDIRECT_HTTP_GHI' => 'redirect-ghi',
'HTTP_GHI' => 'ghi',
'REDIRECT_HTTP_JKL' => 'redirect-jkl',

'HTTP_TEST_MNO' => 'mno',
'HTTP_TEST_PQR' => '',
'HTTP_TEST_STU' => null,
'CONTENT_TEST_VW' => 'vw',
'CONTENT_TEST_XY' => '',
'CONTENT_TEST_ZZ' => null,

123 => 'integer',
];

$expectedHeaders = [
'content-foo' => null,
'content-baz' => 'baz',
'content-var' => 'redirect-var',

'abc' => null,
'ghi' => 'ghi',
'jkl' => 'redirect-jkl',

'test-mno' => 'mno',
'test-stu' => null,
'content-test-vw' => 'vw',
'content-test-zz' => null,
];

$headers = marshalHeadersFromSapi($server);

self::assertSame($expectedHeaders, $headers);
}
}

0 comments on commit 3a045fe

Please sign in to comment.