Skip to content

Commit

Permalink
Test cookie params
Browse files Browse the repository at this point in the history
  • Loading branch information
g105b committed Jan 25, 2019
1 parent 5ec85f0 commit 40949c1
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
8 changes: 4 additions & 4 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/ServerRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function getServerParams():array {
* @return array
*/
public function getCookieParams():array {
return $this->cookieHandler->getAllAsArray();
return $this->cookieHandler->asArray();
}

/**
Expand Down
40 changes: 40 additions & 0 deletions test/unit/ServerRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,44 @@ public function testGetServerParams() {
self::assertEquals($serverParams, $sut->getServerParams());
}

public function testGetCookieParams() {
$cookieParams = [
"COOKIE1" => "VALUE1",
"COOKIE2" => "VALUE2",
];
$sut = self::getServerRequest(
null,
null,
[],
[],
[],
$cookieParams
);
self::assertEquals($cookieParams, $sut->getCookieParams());
}

public function testWithCookieParams() {
$cookieParams1 = [
"COOKIE1" => "VALUE1",
"COOKIE2" => "VALUE2",
];
$cookieParams2 = [
"COOKIE3" => "VALUE3",
"COOKIE4" => "VALUE4",
];
$sut1 = self::getServerRequest(
null,
null,
[],
[],
[],
$cookieParams1
);
$sut2 = $sut1->withCookieParams($cookieParams2);
self::assertEquals($cookieParams1, $sut1->getCookieParams());
self::assertEquals($cookieParams2, $sut2->getCookieParams());
}

protected function getServerRequest(
string $method = null,
string $uri = null,
Expand Down Expand Up @@ -82,6 +120,8 @@ protected function getMockInput(array $input = []):MockObject {
/** @return MockObject|CookieHandler */
protected function getMockCookieHandler(array $cookies = []):MockObject {
$mock = self::createMock(CookieHandler::class);
$mock->method("asArray")
->willReturn($cookies);
return $mock;
}
}

0 comments on commit 40949c1

Please sign in to comment.