Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Merge ebe16df into 5c370e7
Browse files Browse the repository at this point in the history
  • Loading branch information
Maks3w committed Sep 18, 2015
2 parents 5c370e7 + ebe16df commit 8b6a0a7
Show file tree
Hide file tree
Showing 19 changed files with 277 additions and 367 deletions.
12 changes: 6 additions & 6 deletions src/Listener/LocatorRegistrationListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@

namespace Zend\ModuleManager\Listener;

use Zend\EventManager\Event;
use Zend\EventManager\EventManagerInterface;
use Zend\EventManager\ListenerAggregateInterface;
use Zend\ModuleManager\Feature\LocatorRegisteredInterface;
use Zend\ModuleManager\ModuleEvent;
use Zend\ModuleManager\ModuleManager;
use Zend\Mvc\MvcEvent;

/**
* Locator registration listener
Expand Down Expand Up @@ -54,10 +54,10 @@ public function onLoadModule(ModuleEvent $e)
*
* Once all the modules are loaded, loop
*
* @param Event $e
* @param ModuleEvent $e
* @return void
*/
public function onLoadModules(Event $e)
public function onLoadModules(ModuleEvent $e)
{
$moduleManager = $e->getTarget();
$events = $moduleManager->getEventManager()->getSharedManager();
Expand All @@ -67,7 +67,7 @@ public function onLoadModules(Event $e)
}

// Shared instance for module manager
$events->attach('Zend\Mvc\Application', ModuleManager::EVENT_BOOTSTRAP, function ($e) use ($moduleManager) {
$events->attach('Zend\Mvc\Application', ModuleManager::EVENT_BOOTSTRAP, function (MvcEvent $e) use ($moduleManager) {
$moduleClassName = get_class($moduleManager);
$moduleClassNameArray = explode('\\', $moduleClassName);
$moduleClassNameAlias = end($moduleClassNameArray);
Expand All @@ -94,10 +94,10 @@ public function onLoadModules(Event $e)
*
* @TODO: Check the application / locator / etc a bit better to make sure
* the env looks how we're expecting it to?
* @param Event $e
* @param MvcEvent $e
* @return void
*/
public function onBootstrap(Event $e)
public function onBootstrap(MvcEvent $e)
{
$application = $e->getApplication();
$services = $application->getServiceManager();
Expand Down
2 changes: 2 additions & 0 deletions src/ModuleEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
/**
* Custom event for use with module manager
* Composes Module objects
*
* @method ModuleManager getTarget
*/
class ModuleEvent extends Event
{
Expand Down
4 changes: 2 additions & 2 deletions src/ModuleManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,11 @@ public function loadModule($module)

/**
* Load a module with the name
* @param \Zend\EventManager\EventInterface $event
* @param ModuleEvent $event
* @return mixed module instance
* @throws Exception\RuntimeException
*/
protected function loadModuleByName($event)
protected function loadModuleByName(ModuleEvent $event)
{
$result = $this->getEventManager()->trigger(ModuleEvent::EVENT_LOAD_MODULE_RESOLVE, $this, $event, function ($r) {
return (is_object($r));
Expand Down
33 changes: 33 additions & 0 deletions test/Listener/AbstractListenerTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace ZendTest\ModuleManager\Listener;

use PHPUnit_Framework_TestCase as TestCase;
use Zend\Loader\ModuleAutoloader;
use ZendTest\ModuleManager\ResetAutoloadFunctionsTrait;

/**
* Common test methods for all AbstractListener children.
*/
class AbstractListenerTestCase extends TestCase
{
use ResetAutoloadFunctionsTrait;

/**
* @before
*/
protected function registerTestAssetsOnModuleAutoloader()
{
$autoloader = new ModuleAutoloader([
dirname(__DIR__) . '/TestAsset',
]);
$autoloader->register();
}
}
44 changes: 6 additions & 38 deletions test/Listener/AutoloaderListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,57 +9,25 @@

namespace ZendTest\ModuleManager\Listener;

use PHPUnit_Framework_TestCase as TestCase;
use Zend\Loader\ModuleAutoloader;
use Zend\Loader\AutoloaderFactory;
use Zend\ModuleManager\Listener\AutoloaderListener;
use Zend\ModuleManager\Listener\ModuleResolverListener;
use Zend\ModuleManager\ModuleManager;
use Zend\ModuleManager\ModuleEvent;

class AutoloaderListenerTest extends TestCase
class AutoloaderListenerTest extends AbstractListenerTestCase
{
/**
* @var ModuleManager
*/
protected $moduleManager;

public function setUp()
{
$this->loaders = spl_autoload_functions();
if (!is_array($this->loaders)) {
// spl_autoload_functions does not return empty array when no
// autoloaders registered...
$this->loaders = [];
}

// Store original include_path
$this->includePath = get_include_path();

$autoloader = new ModuleAutoloader([
dirname(__DIR__) . '/TestAsset',
]);
$autoloader->register();

$this->moduleManager = new ModuleManager([]);
$this->moduleManager->getEventManager()->attach(ModuleEvent::EVENT_LOAD_MODULE_RESOLVE, new ModuleResolverListener, 1000);
$this->moduleManager->getEventManager()->attach(ModuleEvent::EVENT_LOAD_MODULE, new AutoloaderListener, 2000);
}

public function tearDown()
{
// Restore original autoloaders
AutoloaderFactory::unregisterAutoloaders();
$loaders = spl_autoload_functions();
if (is_array($loaders)) {
foreach ($loaders as $loader) {
spl_autoload_unregister($loader);
}
}

foreach ($this->loaders as $loader) {
spl_autoload_register($loader);
}

// Restore original include_path
set_include_path($this->includePath);
}

public function testAutoloadersRegisteredByAutoloaderListener()
{
$moduleManager = $this->moduleManager;
Expand Down
54 changes: 9 additions & 45 deletions test/Listener/ConfigListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,64 +11,28 @@

use ArrayObject;
use InvalidArgumentException;
use PHPUnit_Framework_TestCase as TestCase;
use Zend\Loader\AutoloaderFactory;
use Zend\Loader\ModuleAutoloader;
use Zend\ModuleManager\Listener\ConfigListener;
use Zend\ModuleManager\Listener\ModuleResolverListener;
use Zend\ModuleManager\Listener\ListenerOptions;
use Zend\ModuleManager\ModuleManager;
use Zend\ModuleManager\ModuleEvent;
use ZendTest\ModuleManager\SetUpCacheDirTrait;

class ConfigListenerTest extends TestCase
class ConfigListenerTest extends AbstractListenerTestCase
{
use SetUpCacheDirTrait;

/**
* @var ModuleManager
*/
protected $moduleManager;

public function setUp()
{
$this->tmpdir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'zend_module_cache_dir';
@mkdir($this->tmpdir);
$this->configCache = $this->tmpdir . DIRECTORY_SEPARATOR . 'config.cache.php';
// Store original autoloaders
$this->loaders = spl_autoload_functions();
if (!is_array($this->loaders)) {
// spl_autoload_functions does not return empty array when no
// autoloaders registered...
$this->loaders = [];
}

// Store original include_path
$this->includePath = get_include_path();

$autoloader = new ModuleAutoloader([
dirname(__DIR__) . '/TestAsset',
]);
$autoloader->register();

$this->moduleManager = new ModuleManager([]);
$this->moduleManager->getEventManager()->attach(ModuleEvent::EVENT_LOAD_MODULE_RESOLVE, new ModuleResolverListener, 1000);
}

public function tearDown()
{
$file = glob($this->tmpdir . DIRECTORY_SEPARATOR . '*');
@unlink($file[0]); // change this if there's ever > 1 file
@rmdir($this->tmpdir);
// Restore original autoloaders
AutoloaderFactory::unregisterAutoloaders();
$loaders = spl_autoload_functions();
if (is_array($loaders)) {
foreach ($loaders as $loader) {
spl_autoload_unregister($loader);
}
}

foreach ($this->loaders as $loader) {
spl_autoload_register($loader);
}

// Restore original include_path
set_include_path($this->includePath);
}

public function testMultipleConfigsAreMerged()
{
$configListener = new ConfigListener;
Expand Down
39 changes: 6 additions & 33 deletions test/Listener/DefaultListenerAggregateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,19 @@

namespace ZendTest\ModuleManager\Listener;

use PHPUnit_Framework_TestCase as TestCase;
use Zend\Loader\AutoloaderFactory;
use Zend\ModuleManager\Listener\ListenerOptions;
use Zend\ModuleManager\Listener\DefaultListenerAggregate;
use Zend\ModuleManager\ModuleManager;

class DefaultListenerAggregateTest extends TestCase
class DefaultListenerAggregateTest extends AbstractListenerTestCase
{
/**
* @var DefaultListenerAggregate
*/
protected $defaultListeners;

public function setUp()
{
// Store original autoloaders
$this->loaders = spl_autoload_functions();
if (!is_array($this->loaders)) {
// spl_autoload_functions does not return empty array when no
// autoloaders registered...
$this->loaders = [];
}

// Store original include_path
$this->includePath = get_include_path();

$this->defaultListeners = new DefaultListenerAggregate(
new ListenerOptions([
'module_paths' => [
Expand All @@ -39,25 +31,6 @@ public function setUp()
);
}

public function tearDown()
{
// Restore original autoloaders
AutoloaderFactory::unregisterAutoloaders();
$loaders = spl_autoload_functions();
if (is_array($loaders)) {
foreach ($loaders as $loader) {
spl_autoload_unregister($loader);
}
}

foreach ($this->loaders as $loader) {
spl_autoload_register($loader);
}

// Restore original include_path
set_include_path($this->includePath);
}

public function testDefaultListenerAggregateCanAttachItself()
{
$moduleManager = new ModuleManager(['ListenerTestModule']);
Expand Down
44 changes: 6 additions & 38 deletions test/Listener/InitTriggerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,57 +9,25 @@

namespace ZendTest\ModuleManager\Listener;

use PHPUnit_Framework_TestCase as TestCase;
use Zend\Loader\AutoloaderFactory;
use Zend\Loader\ModuleAutoloader;
use Zend\ModuleManager\Listener\InitTrigger;
use Zend\ModuleManager\Listener\ModuleResolverListener;
use Zend\ModuleManager\ModuleManager;
use Zend\ModuleManager\ModuleEvent;

class InitTriggerTest extends TestCase
class InitTriggerTest extends AbstractListenerTestCase
{
/**
* @var ModuleManager
*/
protected $moduleManager;

public function setUp()
{
$this->loaders = spl_autoload_functions();
if (!is_array($this->loaders)) {
// spl_autoload_functions does not return empty array when no
// autoloaders registered...
$this->loaders = [];
}

// Store original include_path
$this->includePath = get_include_path();

$autoloader = new ModuleAutoloader([
dirname(__DIR__) . '/TestAsset',
]);
$autoloader->register();

$this->moduleManager = new ModuleManager([]);
$this->moduleManager->getEventManager()->attach(ModuleEvent::EVENT_LOAD_MODULE_RESOLVE, new ModuleResolverListener, 1000);
$this->moduleManager->getEventManager()->attach(ModuleEvent::EVENT_LOAD_MODULE, new InitTrigger, 2000);
}

public function tearDown()
{
// Restore original autoloaders
AutoloaderFactory::unregisterAutoloaders();
$loaders = spl_autoload_functions();
if (is_array($loaders)) {
foreach ($loaders as $loader) {
spl_autoload_unregister($loader);
}
}

foreach ($this->loaders as $loader) {
spl_autoload_register($loader);
}

// Restore original include_path
set_include_path($this->includePath);
}

public function testInitMethodCalledByInitTriggerListener()
{
$moduleManager = $this->moduleManager;
Expand Down

0 comments on commit 8b6a0a7

Please sign in to comment.