From 1523f399562195e923f5bb29f2f1e47840545fae Mon Sep 17 00:00:00 2001 From: Chris Boden Date: Thu, 11 Feb 2016 18:30:35 -0500 Subject: [PATCH] Fixed Session unit tests from PSR-7 --- src/Ratchet/Session/SessionProvider.php | 4 ++-- tests/unit/Session/SessionComponentTest.php | 14 ++++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/Ratchet/Session/SessionProvider.php b/src/Ratchet/Session/SessionProvider.php index 392a13d..44276c5 100644 --- a/src/Ratchet/Session/SessionProvider.php +++ b/src/Ratchet/Session/SessionProvider.php @@ -38,7 +38,7 @@ class SessionProvider implements HttpServerInterface { protected $_serializer; /** - * @param \Ratchet\HttpServerInterface $app + * @param \Ratchet\Http\HttpServerInterface $app * @param \SessionHandlerInterface $handler * @param array $options * @param \Ratchet\Session\Serialize\HandlerInterface $serializer @@ -80,7 +80,7 @@ class SessionProvider implements HttpServerInterface { $crumbs = $this->parseCookie($cookie); - return isset($crumbs[$sessionName]) ? $crumbs[$sessionName] : false; + return isset($crumbs['cookies'][$sessionName]) ? $crumbs['cookies'][$sessionName] : false; }, false); if (null === $request || false === $id) { diff --git a/tests/unit/Session/SessionComponentTest.php b/tests/unit/Session/SessionComponentTest.php index e889637..ebfdde4 100644 --- a/tests/unit/Session/SessionComponentTest.php +++ b/tests/unit/Session/SessionComponentTest.php @@ -1,7 +1,6 @@ getMock($this->getComponentClassString()), $pdoHandler, array('auto_start' => 1)); $connection = $this->getMock('Ratchet\\ConnectionInterface'); - $headers = $this->getMock('Guzzle\\Http\\Message\\Request', array('getCookie'), array('POST', '/', array())); - $headers->expects($this->once())->method('getCookie', array(ini_get('session.name')))->will($this->returnValue($sessionId)); + $headers = $this->getMock('Psr\Http\Message\RequestInterface'); + $headers->expects($this->once())->method('getHeader')->will($this->returnValue([ini_get('session.name') . "={$sessionId};"])); $component->onOpen($connection, $headers); @@ -94,7 +93,7 @@ class SessionProviderTest extends AbstractMessageComponentTestCase { protected function newConn() { $conn = $this->getMock('Ratchet\ConnectionInterface'); - $headers = $this->getMock('Guzzle\Http\Message\Request', array('getCookie'), array('POST', '/', array())); + $headers = $this->getMock('Psr\Http\Message\Request', array('getCookie'), array('POST', '/', array())); $headers->expects($this->once())->method('getCookie', array(ini_get('session.name')))->will($this->returnValue(null)); return $conn; @@ -115,4 +114,11 @@ class SessionProviderTest extends AbstractMessageComponentTestCase { $this->setExpectedException('\RuntimeException'); new SessionProvider($this->getMock($this->getComponentClassString()), $this->getMock('\SessionHandlerInterface')); } + + protected function doOpen($conn) { + $request = $this->getMock('Psr\Http\Message\RequestInterface'); + $request->expects($this->any())->method('getHeader')->will($this->returnValue([])); + + $this->_serv->onOpen($conn, $request); + } }