Skip to content

Commit

Permalink
Test existing cookies
Browse files Browse the repository at this point in the history
  • Loading branch information
WyriHaximus committed Jan 22, 2018
1 parent 1b449af commit 2ed547a
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions tests/SessionMiddlewareTest.php
@@ -0,0 +1,41 @@
<?php declare(strict_types=1);

namespace WyriHaximus\React\Tests\Http\Middleware;

use ApiClients\Tools\TestUtilities\TestCase;
use Psr\Http\Message\ServerRequestInterface;
use React\Cache\ArrayCache;
use RingCentral\Psr7\Response;
use RingCentral\Psr7\ServerRequest;
use WyriHaximus\React\Http\Middleware\SessionMiddleware;

final class SessionMiddlewareTest extends TestCase
{
public function testSessionExists()
{
$contents = ['Sand'];
$cookieName = 'CookieMonster';
$cache = new ArrayCache();
$cache->set('cookies', ['Chocolate Chip']);
$middleware = new SessionMiddleware($cookieName, $cache);

$request = (new ServerRequest(
'GET',
'https://www.example.com/'
))->withCookieParams([
'CookieMonster' => 'cookies',
]);

$next = function (ServerRequestInterface $request) use ($contents) {
$request->getAttribute(SessionMiddleware::ATTRIBUTE_NAME)->setContents($contents);

return new Response();
};

$middleware($request, $next);

$sandCoookies = $this->await($cache->get('cookies'));

self::assertSame($contents, $sandCoookies);
}
}

0 comments on commit 2ed547a

Please sign in to comment.