Skip to content

Commit

Permalink
use "listeners" key in module config instead of call in onBootstrap()
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Jan 1, 2017
1 parent 3258e7b commit beee247
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 37 deletions.
4 changes: 4 additions & 0 deletions config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
],
],

'listeners' => [
Listener\Mvc::class,
],

'view_manager' => [
'template_map' => [
'error-hero-module/error-default' => __DIR__.'/../view/error-hero-module/error-default.phtml',
Expand Down
26 changes: 0 additions & 26 deletions spec/ModuleSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver\PDOMySql\Driver;
use Doctrine\ORM\EntityManager;
use ErrorHeroModule\Listener\Mvc;
use ErrorHeroModule\Module;
use Kahlan\Plugin\Double;
use Zend\EventManager\EventManagerInterface;
use Zend\ModuleManager\Listener\ConfigListener;
use Zend\ModuleManager\ModuleEvent;
use Zend\ModuleManager\ModuleManager;
use Zend\Mvc\Application;
use Zend\Mvc\MvcEvent;
use Zend\ServiceManager\ServiceLocatorInterface;

describe('Module', function () {
Expand Down Expand Up @@ -161,27 +158,4 @@

});

describe('->onBootstrap()', function () {

it('pull Mvc Listener and use it to attach with EventManager', function () {

$application = Double::instance(['extends' => Application::class, 'methods' => '__construct']);
$mvcListener = Double::instance(['extends' => Mvc::class, 'methods' => '__construct']);
$serviceManager = Double::instance(['implements' => ServiceLocatorInterface::class]);
$eventManager = Double::instance(['implements' => EventManagerInterface::class]);
$mvcEvent = Double::instance(['extends' => MvcEvent::class]);

expect($mvcListener)->toReceive('attach')->with($eventManager);

allow($application)->toReceive('getServiceManager')->andReturn($serviceManager);
allow($application)->toReceive('getEventManager')->andReturn($eventManager);
allow($serviceManager)->toReceive('get')->with(Mvc::class)->andReturn($mvcListener);
allow($mvcEvent)->toReceive('getApplication')->andReturn($application);

$this->module->onBootstrap($mvcEvent);

});

});

});
11 changes: 0 additions & 11 deletions src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Doctrine\ORM\EntityManager;
use Zend\ModuleManager\ModuleEvent;
use Zend\ModuleManager\ModuleManager;
use Zend\Mvc\MvcEvent;

class Module
{
Expand Down Expand Up @@ -64,16 +63,6 @@ public function convertDoctrineToZendDbConfig(ModuleEvent $event)
$services->setAllowOverride($allowOverride);
}

public function onBootstrap(MvcEvent $e)
{
$app = $e->getApplication();
$services = $app->getServiceManager();
$eventManager = $app->getEventManager();

$mvcListenerAggregate = $services->get(Listener\Mvc::class);
$mvcListenerAggregate->attach($eventManager);
}

public function getConfig()
{
return include __DIR__.'/../config/module.config.php';
Expand Down

0 comments on commit beee247

Please sign in to comment.