Skip to content

Commit

Permalink
Merge pull request #53 from samsonasik/feature/sm3
Browse files Browse the repository at this point in the history
Support zend-servicemanager v3 and fixes check sessions exists bug on reload session
  • Loading branch information
samsonasik committed May 4, 2016
2 parents 167a708 + b6d5d54 commit cb59b76
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 6 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"zendframework/zend-debug": "~2.3"
},
"require-dev": {
"container-interop/container-interop": "^1.1",
"satooshi/php-coveralls": "^1.0",
"phpunit/phpcov": "~2.0",
"zendframework/zend-test": "~2.3",
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/SessionToolbarController.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function removesessionAction()
*/
public function reloadsessionAction()
{
$sessionData = $this->sessionManager->getSessionData();
$sessionData = $this->sessionManager->getSessionData(false);

$renderedContent = $this->viewRenderer
->render('zend-developer-tools/toolbar/session-data-list', array('sessionData' => $sessionData));
Expand Down
9 changes: 9 additions & 0 deletions src/Factory/Collector/SessionCollectorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
namespace SanSessionToolbar\Factory\Collector;

use Interop\Container\ContainerInterface;
use SanSessionToolbar\Collector\SessionCollector;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
Expand All @@ -36,4 +37,12 @@ public function createService(ServiceLocatorInterface $serviceLocator)
{
return new SessionCollector((object) $serviceLocator->get('SanSessionManager'));
}

/**
* {@inheritdoc}
*/
public function __invoke(ContainerInterface $serviceLocator, $requestedName, array $options = null)
{
return $this->createService($serviceLocator);
}
}
9 changes: 9 additions & 0 deletions src/Factory/Controller/SessionToolbarControllerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
namespace SanSessionToolbar\Factory\Controller;

use Interop\Container\ContainerInterface;
use SanSessionToolbar\Controller\SessionToolbarController;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorAwareInterface;
Expand Down Expand Up @@ -58,4 +59,12 @@ private function getParentServiceLocator(ServiceLocatorInterface $serviceLocator

return $serviceLocator;
}

/**
* {@inheritdoc}
*/
public function __invoke(ContainerInterface $serviceLocator, $requestedName, array $options = null)
{
return $this->createService($serviceLocator);
}
}
10 changes: 6 additions & 4 deletions src/Manager/SessionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ final class SessionManager implements SessionManagerInterface
/**
* {@inheritdoc}
*/
public function getSessionData()
public function getSessionData($checkExists = true)
{
$manager = Container::getDefaultManager();
if (!$manager->sessionExists()) {
return;
if ($checkExists) {
$manager = Container::getDefaultManager();
if (!$manager->sessionExists()) {
return;
}
}

$container = new Container();
Expand Down
4 changes: 3 additions & 1 deletion src/Manager/SessionManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ interface SessionManagerInterface
/**
* Get Session Data.
*
* @param bool $checkExists
*
* @return array|null
*/
public function getSessionData();
public function getSessionData($checkExists = true);

/**
* Set/Unset Session by Container and its key.
Expand Down
18 changes: 18 additions & 0 deletions test/Factory/Collector/SessionCollectorFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

namespace SanSessionToolbarTest\Factory\Collector;

use Interop\Container\ContainerInterface;
use PHPUnit_Framework_TestCase;
use SanSessionToolbar\Factory\Collector\SessionCollectorFactory;
use Zend\ServiceManager\ServiceLocatorInterface;
Expand Down Expand Up @@ -60,4 +61,21 @@ public function testCreateService()
$result = $this->factory->createService($this->serviceLocator);
$this->assertInstanceOf('SanSessionToolbar\Collector\SessionCollector', $result);
}

/**
* @covers SanSessionToolbar\Factory\Collector\SessionCollectorFactory::__invoke
*/
public function testInvoke()
{
if ($this->serviceLocator instanceof ContainerInterface) {
$sessionManager = $this->getMock('SanSessionToolbar\Manager\SessionManagerInterface');
$this->serviceLocator->expects($this->once())
->method('get')
->with('SanSessionManager')
->willReturn($sessionManager);

$result = $this->factory->__invoke($this->serviceLocator, '');
$this->assertInstanceOf('SanSessionToolbar\Collector\SessionCollector', $result);
}
}
}
25 changes: 25 additions & 0 deletions test/Factory/Controller/SessionToolbarControllerFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

namespace SanSessionToolbarTest\Factory\Controller;

use Interop\Container\ContainerInterface;
use PHPUnit_Framework_TestCase;
use SanSessionToolbar\Factory\Controller\SessionToolbarControllerFactory;
use Zend\Mvc\Controller\ControllerManager;
Expand Down Expand Up @@ -95,4 +96,28 @@ private function doTestCreateService(ServiceLocatorInterface $serviceLocator)
$result = $this->factory->createService($serviceLocator);
$this->assertInstanceOf('SanSessionToolbar\Controller\SessionToolbarController', $result);
}

/**
* @covers SanSessionToolbar\Factory\Controller\SessionToolbarControllerFactory::getParentServiceLocator
* @covers SanSessionToolbar\Factory\Controller\SessionToolbarControllerFactory::__invoke
*/
public function testInvoke()
{
if ($this->serviceLocator instanceof ContainerInterface) {
$mockViewRenderer = $this->getMock('Zend\View\Renderer\RendererInterface');
$this->serviceLocator->expects($this->at(0))
->method('get')
->with('ViewRenderer')
->willReturn($mockViewRenderer);

$sessionManager = $this->getMock('SanSessionToolbar\Manager\SessionManagerInterface');
$this->serviceLocator->expects($this->at(1))
->method('get')
->with('SanSessionManager')
->willReturn($sessionManager);

$result = $this->factory->__invoke($this->serviceLocator, '');
$this->assertInstanceOf('SanSessionToolbar\Controller\SessionToolbarController', $result);
}
}
}

0 comments on commit cb59b76

Please sign in to comment.