Skip to content
Permalink
Browse files

Allow PSR7 requests to store the session as an attribute.

By allowing the session to exist on the PSR7 request, it will be easier
to implement integration test case flows and more importantly let people
access the session from their psr7 requests.
  • Loading branch information...
markstory committed Jun 18, 2016
1 parent fc6cfe8 commit da39cd36cba237c5c1375ae287340059945093de
Showing with 18 additions and 0 deletions.
  1. +1 −0 src/Http/RequestTransformer.php
  2. +17 −0 tests/TestCase/Http/RequestTransformerTest.php
@@ -57,6 +57,7 @@ public static function toCake(PsrRequest $request)
'url' => $request->getUri()->getPath(),
'base' => $request->getAttribute('base', ''),
'webroot' => $request->getAttribute('webroot', '/'),
'session' => $request->getAttribute('session', null),
]);
}
@@ -18,6 +18,7 @@
use Cake\Http\RequestTransformer;
use Cake\Http\ServerRequestFactory;
use Cake\Network\Request;
use Cake\Network\Session;
use Cake\TestSuite\TestCase;
/**
@@ -259,4 +260,20 @@ public function testToCakeBaseSessionPath()
$this->assertEquals('/thisapp', ini_get('session.cookie_path'));
}
/**
* Test transforming session objects
*
* @return void
*/
public function testToCakeSession()
{
$psr = ServerRequestFactory::fromGlobals();
$session = new Session(['defaults' => 'php']);
$session->write('test', 'value');
$psr = $psr->withAttribute('session', $session);
$cake = RequestTransformer::toCake($psr);
$this->assertSame($session, $cake->session());
}
}

0 comments on commit da39cd3

Please sign in to comment.
You can’t perform that action at this time.