Skip to content

Commit

Permalink
Fixes #55
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Aug 29, 2016
1 parent 872d2bd commit d4911c6
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 4 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ return [
],
```

> **Note** : for better ouput format, you need to have Xdebug installed in your system.
> **Note** :
- for better ouput format, you need to have Xdebug installed in your system.
- for zend-mvc v3 usage, if you want to get FlashMessenger data, you need to install zendframework/zend-mvc-plugin-flashmessenger

Contributing
------------
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"zendframework/zend-developer-tools": "^1.0.0 || ^1.1.0"
},
"suggest": {
"ext-xdebug": "For better output format of session data, Xdebug should already installed"
"ext-xdebug": "For better output format of session data, Xdebug should already installed",
"zendframework/zend-mvc-plugin-flashmessenger": "^1.0 for zend-mvc ^3.0 usage to be able to use flashMessenger"
},
"autoload": {
"psr-4": {
Expand Down
5 changes: 4 additions & 1 deletion src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,11 @@ public function onBootstrap(MvcEvent $e)
public function flashMessengerHandler(EventInterface $e)
{
$controller = $e->getTarget();
$flash = $controller->plugin('flashMessenger');
if (!$controller->getPluginManager()->has('flashMessenger')) {
return;
}

$flash = $controller->plugin('flashMessenger');
$container = new Container('FlashMessenger');
$reCreateFlash = $container->getArrayCopy();

Expand Down
50 changes: 49 additions & 1 deletion test/ModuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,12 @@ public function testOnBootstrap($hasMessages)
$module = $this->module;
$abstractActionController = $this->prophesize('Zend\Mvc\Controller\AbstractActionController');
$flashMessenger = $this->prophesize('Zend\Mvc\Controller\Plugin\FlashMessenger');
$pluginManager = $this->prophesize('Zend\Mvc\Controller\PluginManager');

$sharedEvmAttach->will(function() use ($module, $e, $hasMessages, $abstractActionController, $flashMessenger) {
$sharedEvmAttach->will(function() use ($module, $e, $hasMessages, $abstractActionController, $flashMessenger, $pluginManager) {
$abstractActionController->getPluginManager()->willReturn($pluginManager)->shouldBeCalled();
$pluginManager->has('flashMessenger')->willReturn(true)->shouldBeCalled();

if ($hasMessages) {
$namespace = 'flash';
$message = 'a message';
Expand Down Expand Up @@ -116,6 +120,50 @@ public function testOnBootstrap($hasMessages)

$this->module->onBootstrap($e->reveal());
}

public function testOnBootstrapWithDoesntHasFlashMessenger()
{
$e = $this->prophesize('Zend\Mvc\MvcEvent');

$application = $this->prophesize('Zend\Mvc\Application');
$eventManager = $this->prophesize('Zend\EventManager\EventManager');
$sharedEvm = $this->prophesize('Zend\EventManager\SharedEventManager');
$sharedEvmAttach = $sharedEvm->attach(
'Zend\Mvc\Controller\AbstractActionController',
'dispatch',
[$this->module, 'flashMessengerHandler'],
2
);
$module = $this->module;
$abstractActionController = $this->prophesize('Zend\Mvc\Controller\AbstractActionController');
$flashMessenger = $this->prophesize('Zend\Mvc\Controller\Plugin\FlashMessenger');
$pluginManager = $this->prophesize('Zend\Mvc\Controller\PluginManager');

$sharedEvmAttach->will(function() use ($module, $e, $abstractActionController, $flashMessenger, $pluginManager) {
$abstractActionController->getPluginManager()->willReturn($pluginManager)->shouldBeCalled();
$pluginManager->has('flashMessenger')->willReturn(false)->shouldBeCalled();

$e->getTarget()
->willReturn($abstractActionController)
->shouldBeCalled();

$module->flashMessengerHandler($e->reveal());
});
$sharedEvmAttach->shouldBeCalled();

$eventManager->getSharedManager()
->willReturn($sharedEvm)
->shouldBeCalled();
$application->getEventManager()
->willReturn($eventManager)
->shouldBeCalled();

$e->getApplication()
->willReturn($application)
->shouldBeCalled();

$this->module->onBootstrap($e->reveal());
}

/**
* @covers SanSessionToolbar\Module::getConfig()
Expand Down

0 comments on commit d4911c6

Please sign in to comment.