From 87f7388aeb16e446cc04310517b7e69cc76f5c0f Mon Sep 17 00:00:00 2001 From: lifinsky Date: Tue, 24 Nov 2020 12:21:18 +0200 Subject: [PATCH] Improve SwoftTest\Http\Server\Testing\MockResponse::cookie() method: Swoole 4.5.8. --- composer.json | 3 ++- test/testing/MockResponse.php | 36 ++++++++++++++++++++--------------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/composer.json b/composer.json index b0c903f..f9fbc01 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,8 @@ } }, "require-dev": { - "phpunit/phpunit": "^7.5" + "phpunit/phpunit": "^7.5", + "swoole/ide-helper": "dev-master" }, "scripts": { "test": "./vendor/bin/phpunit -c phpunit.xml" diff --git a/test/testing/MockResponse.php b/test/testing/MockResponse.php index 3a3c1ea..0983cb9 100644 --- a/test/testing/MockResponse.php +++ b/test/testing/MockResponse.php @@ -80,14 +80,15 @@ public function header($key, $value, $ucwords = null) } /** - * @param string $name - * @param string $value - * @param int|string $expires - * @param string|null $path - * @param string $domain - * @param bool $secure - * @param bool $httpOnly - * @param null $samesite + * @param string $name + * @param string|null $value + * @param int|string|null $expires + * @param string|null $path + * @param string|null $domain + * @param bool|null $secure + * @param bool|null $httpOnly + * @param string|null $samesite + * @param string|null $priority */ public function cookie( $name, @@ -97,7 +98,8 @@ public function cookie( $domain = null, $secure = null, $httpOnly = null, - $samesite = null + $samesite = null, + $priority = null ) { $result = \urlencode($name) . '=' . \urlencode($value); @@ -117,22 +119,26 @@ public function cookie( } if ($timestamp !== 0) { - $result .= '; expires=' . \gmdate('D, d-M-Y H:i:s e', $timestamp); + $result .= '; Expires=' . \gmdate('D, d-M-Y H:i:s e', $timestamp); } } if ($secure) { - $result .= '; secure'; + $result .= '; Secure'; } - // if ($hostOnly) { - // $result .= '; HostOnly'; - // } - if ($httpOnly) { $result .= '; HttpOnly'; } + if ($samesite) { + $result .= '; SameSite=' . $samesite; + } + + if ($priority) { + $result .= '; Priority=' . $priority; + } + $this->cookie[$name] = $result; }