Skip to content

Commit d8f8bf1

Browse files
author
Greg Bowler
committed
Test case insensitive functions, closes #20
1 parent 09c1573 commit d8f8bf1

File tree

4 files changed

+76
-0
lines changed

4 files changed

+76
-0
lines changed

src/FormData.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
namespace Gt\Http;
3+
4+
class FormData {
5+
/** @var array */
6+
protected $data;
7+
8+
public function __construct(array $data = []) {
9+
$this->data = $data;
10+
}
11+
12+
public function append(
13+
string $key,
14+
string $value,
15+
string $filename = null
16+
):void {
17+
18+
}
19+
20+
public function set(
21+
string $name,
22+
string $value,
23+
string $filename = null
24+
):void {
25+
26+
}
27+
28+
public function delete(string $name):void {
29+
30+
}
31+
32+
public function entries():array {
33+
34+
}
35+
36+
public function get(string $name):?string {
37+
38+
}
39+
40+
public function getAll(string $name):array {
41+
42+
}
43+
44+
/** For consistency with naming of other Web APIs. */
45+
public function contains(string $name):bool {
46+
47+
}
48+
49+
public function has(string $name):bool {
50+
51+
}
52+
53+
public function keys():array {
54+
55+
}
56+
57+
public function values():array {
58+
59+
}
60+
}

src/ServerInfo.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public function getHttpHeadersArray():array {
2828

2929
$headerName = substr($key, strlen("HTTP_"));
3030
$headerName = strtoupper($headerName);
31+
$headerName = str_replace("_", "-", $headerName);
3132
$headers[$headerName] = $value;
3233
}
3334

test/unit/Header/HeadersTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,18 @@ public function testIterator() {
150150
self::assertEquals($expectedValue, $kvp[$expectedKey]);
151151
}
152152
}
153+
154+
public function testCaseInsensitive() {
155+
$headers = new Headers(self::HEADER_ARRAY);
156+
self::assertTrue($headers->contains("date"));
157+
self::assertTrue($headers->contains("Date"));
158+
self::assertTrue($headers->contains("DATE"));
159+
160+
self::assertEquals(
161+
self::HEADER_ARRAY["Date"],
162+
$headers->get("dAtE")
163+
);
164+
165+
self::assertTrue($headers->contains("ConTent-Type"));
166+
}
153167
}

test/unit/ServerInfoTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public function testGetHttpHeadersArray() {
2929

3030
foreach($httpHeaders as $key => $value) {
3131
$httplessKey = substr($key, strlen("HTTP_"));
32+
$httplessKey = str_replace("_", "-", $httplessKey);
3233
self::assertArrayHasKey($httplessKey, $httpHeadersArray);
3334
self::assertEquals($value, $httpHeadersArray[$httplessKey]);
3435
}

0 commit comments

Comments
 (0)