Skip to content

Commit f88442e

Browse files
committed
Updated to 1.1.3 version
1 parent 1dda3f2 commit f88442e

File tree

3 files changed

+49
-20
lines changed

3 files changed

+49
-20
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
* Added `Cookie/_config.yml` file.
1515
* Added `Cookie/.travis.yml` file.
1616

17+
* Deleted `Josantonius\Cookie\Cookie::display()` method.
18+
1719
* Deleted `Josantonius\Cookie\Tests\CookieTest` class.
1820
* Deleted `Josantonius\Cookie\Tests\CookieTest::testSetCookie()` method.
1921
* Deleted `Josantonius\Cookie\Tests\CookieTest::testPullCookie()` method.
@@ -27,6 +29,8 @@
2729
* Added `Josantonius\Cookie\Test\CookieTest::testPullCookie()` method.
2830
* Added `Josantonius\Cookie\Test\CookieTest::testPullCookieNonExistent()` method.
2931
* Added `Josantonius\Cookie\Test\CookieTest::testGetCookie()` method.
32+
* Added `Josantonius\Cookie\Tests\CookieTest::testGetAllCookiesNonExistents()()` method.
33+
* Added `Josantonius\Cookie\Tests\CookieTest::testGetAllCookiesNonExistents()` method.
3034
* Added `Josantonius\Cookie\Test\CookieTest::testDisplayCookies()` method.
3135
* Added `Josantonius\Cookie\Test\CookieTest::testDestroyOneCookie()` method.
3236
* Added `Josantonius\Cookie\Test\CookieTest::testDestroyOneCookieNonExistent()` method.

src/Cookie/Cookie.php

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,16 @@ public static function set($key, $value, $time = 365) {
5252
*
5353
* @param string $key → item to look for in cookie
5454
*
55-
* @return string|null → returns key value, or null if key doesn't exists
55+
* @return mixed|false → returns cookie value, cookies array or false
5656
*/
57-
public static function get($key) {
57+
public static function get($key = '') {
5858

59-
$cookieName = self::$_prefix . $key;
59+
if (isset($_COOKIE[self::$_prefix . $key])) {
60+
61+
return $_COOKIE[self::$_prefix . $key];
62+
}
6063

61-
return isset($_COOKIE[$cookieName]) ? $_COOKIE[$cookieName] : null;
64+
return isset($_COOKIE) && count($_COOKIE) ? $_COOKIE : false;
6265
}
6366

6467
/**
@@ -112,17 +115,4 @@ public static function destroy($key = '') {
112115

113116
return false;
114117
}
115-
116-
/**
117-
* Return cookies array.
118-
*
119-
* @since 1.0.0
120-
*
121-
* @return array|null → of cookie indexes
122-
*/
123-
public static function display() {
124-
125-
return isset($_COOKIE) ? $_COOKIE : null;
126-
127-
}
128118
}

tests/Cookie/Test/CookieTest.php

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,41 @@ public function testGetCookie() {
5151
$this->assertContains(Cookie::get('cookie_name'), 'value');
5252
}
5353

54+
/**
55+
* Return cookies array.
56+
*
57+
* @runInSeparateProcess
58+
*
59+
* @since 1.1.3
60+
*
61+
* @return void
62+
*/
63+
public function testGetAllCookies() {
64+
65+
$_COOKIE[Cookie::$_prefix . 'cookie_name_one'] = 'value';
66+
$_COOKIE[Cookie::$_prefix . 'cookie_name_two'] = 'value';
67+
68+
$this->assertArrayHasKey(
69+
70+
Cookie::$_prefix . 'cookie_name_two',
71+
Cookie::get()
72+
);
73+
}
74+
75+
/**
76+
* Return cookies array non-existent.
77+
*
78+
* @runInSeparateProcess
79+
*
80+
* @since 1.1.3
81+
*
82+
* @return void
83+
*/
84+
public function testGetAllCookiesNonExistents() {
85+
86+
$this->assertFalse(Cookie::get());
87+
}
88+
5489
/**
5590
* Extract item from cookie then delete cookie and return the item.
5691
*
@@ -68,7 +103,7 @@ public function testPullCookie() {
68103
}
69104

70105
/**
71-
* Extract item from cookie then delete cookie and return the item.
106+
* Extract item from cookie non-existent.
72107
*
73108
* @runInSeparateProcess
74109
*
@@ -98,7 +133,7 @@ public function testDestroyOneCookie() {
98133
}
99134

100135
/**
101-
* Destroy one cookie.
136+
* Destroy one cookie non-existent.
102137
*
103138
* @runInSeparateProcess
104139
*
@@ -129,7 +164,7 @@ public function testDestroyAllCookies() {
129164
}
130165

131166
/**
132-
* Destroy all cookies.
167+
* Destroy all cookies non-existents.
133168
*
134169
* @runInSeparateProcess
135170
*

0 commit comments

Comments
 (0)