Skip to content

Commit 40949c1

Browse files
author
Greg Bowler
committed
Test cookie params
1 parent 5ec85f0 commit 40949c1

File tree

3 files changed

+45
-5
lines changed

3 files changed

+45
-5
lines changed

composer.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ServerRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function getServerParams():array {
5656
* @return array
5757
*/
5858
public function getCookieParams():array {
59-
return $this->cookieHandler->getAllAsArray();
59+
return $this->cookieHandler->asArray();
6060
}
6161

6262
/**

test/unit/ServerRequestTest.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,44 @@ public function testGetServerParams() {
2626
self::assertEquals($serverParams, $sut->getServerParams());
2727
}
2828

29+
public function testGetCookieParams() {
30+
$cookieParams = [
31+
"COOKIE1" => "VALUE1",
32+
"COOKIE2" => "VALUE2",
33+
];
34+
$sut = self::getServerRequest(
35+
null,
36+
null,
37+
[],
38+
[],
39+
[],
40+
$cookieParams
41+
);
42+
self::assertEquals($cookieParams, $sut->getCookieParams());
43+
}
44+
45+
public function testWithCookieParams() {
46+
$cookieParams1 = [
47+
"COOKIE1" => "VALUE1",
48+
"COOKIE2" => "VALUE2",
49+
];
50+
$cookieParams2 = [
51+
"COOKIE3" => "VALUE3",
52+
"COOKIE4" => "VALUE4",
53+
];
54+
$sut1 = self::getServerRequest(
55+
null,
56+
null,
57+
[],
58+
[],
59+
[],
60+
$cookieParams1
61+
);
62+
$sut2 = $sut1->withCookieParams($cookieParams2);
63+
self::assertEquals($cookieParams1, $sut1->getCookieParams());
64+
self::assertEquals($cookieParams2, $sut2->getCookieParams());
65+
}
66+
2967
protected function getServerRequest(
3068
string $method = null,
3169
string $uri = null,
@@ -82,6 +120,8 @@ protected function getMockInput(array $input = []):MockObject {
82120
/** @return MockObject|CookieHandler */
83121
protected function getMockCookieHandler(array $cookies = []):MockObject {
84122
$mock = self::createMock(CookieHandler::class);
123+
$mock->method("asArray")
124+
->willReturn($cookies);
85125
return $mock;
86126
}
87127
}

0 commit comments

Comments
 (0)