Skip to content

Commit 1a5e5fb

Browse files
committed
code coverage updates
1 parent 36275a2 commit 1a5e5fb

File tree

3 files changed

+41
-28
lines changed

3 files changed

+41
-28
lines changed

Http/RequestCookies.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ public static function set(RequestInterface $request, Cookie $cookie) : RequestI
3232

3333
public static function modify(RequestInterface $request, string $name, callable $modify) : RequestInterface
3434
{
35-
if (! \is_callable($modify)) {
36-
throw new \InvalidArgumentException('$modify must be callable.');
37-
}
38-
3935
$cookies = Cookies::fromRequest($request);
4036
$cookie = $modify($cookies->has($name)
4137
? $cookies->get($name)

Http/ResponseCookies.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ public static function expire(ResponseInterface $response, string $cookieName) :
3737

3838
public static function modify(ResponseInterface $response, string $name, callable $modify) : ResponseInterface
3939
{
40-
if (! \is_callable($modify)) {
41-
throw new \InvalidArgumentException('$modify must be callable.');
42-
}
43-
4440
$setCookies = SetCookies::fromResponse($response);
4541
$setCookie = $modify($setCookies->has($name)
4642
? $setCookies->get($name)

tests/ResponseCookiesTest.php

Lines changed: 41 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010

1111
class ResponseCookiesTest extends TestCase
1212
{
13-
/**
14-
* @test
15-
*/
16-
public function it_gets_cookies() : void
13+
public function testGet() : void
1714
{
1815
$response = (new Response());
1916

@@ -23,16 +20,46 @@ public function it_gets_cookies() : void
2320
->withAddedHeader(SetCookies::SET_COOKIE_HEADER, SetCookie::create('hello', 'world'))
2421
;
2522

26-
self::assertEquals(
23+
$this->assertEquals(
2724
'ENCRYPTED',
2825
ResponseCookies::get($response, 'sessionToken')->getValue()
2926
);
3027
}
3128

32-
/**
33-
* @test
34-
*/
35-
public function it_sets_cookies() : void
29+
public function testGetNull() : void
30+
{
31+
$response = (new Response());
32+
33+
$response = $response
34+
->withAddedHeader(SetCookies::SET_COOKIE_HEADER, SetCookie::create('theme', 'light'))
35+
->withAddedHeader(SetCookies::SET_COOKIE_HEADER, SetCookie::create('hello', 'world'))
36+
;
37+
38+
$this->assertEquals(
39+
'ENCRYPTED',
40+
ResponseCookies::get($response, 'sessionToken', 'ENCRYPTED')->getValue()
41+
);
42+
}
43+
44+
public function testExpire() : void
45+
{
46+
$response = (new Response());
47+
48+
$response = $response
49+
->withAddedHeader(SetCookies::SET_COOKIE_HEADER, SetCookie::create('theme', 'light'))
50+
->withAddedHeader(SetCookies::SET_COOKIE_HEADER, SetCookie::create('sessionToken', 'ENCRYPTED'))
51+
->withAddedHeader(SetCookies::SET_COOKIE_HEADER, SetCookie::create('hello', 'world'))
52+
;
53+
54+
$response = ResponseCookies::expire($response, 'sessionToken');
55+
56+
$this->assertEquals(
57+
'',
58+
ResponseCookies::get($response, 'sessionToken')->getValue()
59+
);
60+
}
61+
62+
public function testSet() : void
3663
{
3764
$response = (new Response());
3865

@@ -44,16 +71,13 @@ public function it_sets_cookies() : void
4471

4572
$response = ResponseCookies::set($response, SetCookie::create('hello', 'WORLD!'));
4673

47-
self::assertEquals(
74+
$this->assertEquals(
4875
'theme=light,sessionToken=ENCRYPTED,hello=WORLD%21',
4976
$response->getHeaderLine('Set-Cookie')
5077
);
5178
}
5279

53-
/**
54-
* @test
55-
*/
56-
public function it_modifies_cookies() : void
80+
public function testModify() : void
5781
{
5882
$response = (new Response());
5983

@@ -67,16 +91,13 @@ public function it_modifies_cookies() : void
6791
return $setCookie->withValue(strtoupper($setCookie->getName()));
6892
});
6993

70-
self::assertEquals(
94+
$this->assertEquals(
7195
'theme=light,sessionToken=ENCRYPTED,hello=HELLO',
7296
$response->getHeaderLine('Set-Cookie')
7397
);
7498
}
7599

76-
/**
77-
* @test
78-
*/
79-
public function it_removes_cookies() : void
100+
public function testRemove() : void
80101
{
81102
$response = (new Response());
82103

@@ -88,7 +109,7 @@ public function it_removes_cookies() : void
88109

89110
$response = ResponseCookies::remove($response, 'sessionToken');
90111

91-
self::assertEquals(
112+
$this->assertEquals(
92113
'theme=light,hello=world',
93114
$response->getHeaderLine('Set-Cookie')
94115
);

0 commit comments

Comments
 (0)