Skip to content

Commit

Permalink
Merge pull request #4 from sinbonders/master
Browse files Browse the repository at this point in the history
Changing event to listen to EVENT_LOAD_MODULE
  • Loading branch information
abacaphiliac authored Jun 30, 2016
2 parents 275137b + 915519e commit e82e672
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/ZendPhpDotEnv/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function init(ModuleManager $moduleManager)
{
$events = $moduleManager->getEventManager();

$events->attach(ModuleEvent::EVENT_MERGE_CONFIG, array($this, 'loadEnvironmentVariables'), 2000);
$events->attach(ModuleEvent::EVENT_LOAD_MODULE, array($this, 'loadEnvironmentVariables'), -1);
}

/**
Expand Down
15 changes: 10 additions & 5 deletions tests/ZendPhpDotEnv/ModuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Abacaphiliac\ZendPhpDotEnv\DotEnvLoader;
use Abacaphiliac\ZendPhpDotEnv\Module;
use Zend\EventManager\SharedEventManager;
use Zend\ModuleManager\ModuleEvent;
use Zend\Mvc\Service\EventManagerFactory;
use Zend\Mvc\Service\ModuleManagerFactory;
use Zend\ServiceManager\ServiceManager;
Expand Down Expand Up @@ -45,9 +46,9 @@ public function testModuleLoadsEnvironmentVariablesFromWorkingDirectory()
}

/**
* @expectedException \Dotenv\Exception\InvalidPathException
* @expectedException \Abacaphiliac\ZendPhpDotEnv\Exception\InvalidWorkingDirectoryPathException
*/
public function testLoadModule()
public function testInitLoadsEnvironmentVariablesFromWorkingDirectory()
{
$serviceLocator = new ServiceManager();
$serviceLocator->setService('ApplicationConfig', array(
Expand All @@ -59,10 +60,14 @@ public function testLoadModule()
$serviceLocator->setFactory('EventManager', new EventManagerFactory());
$serviceLocator->setService('SharedEventManager', new SharedEventManager());
$serviceLocator->setFactory('ServiceListener', '\Zend\Mvc\Service\ServiceListenerFactory');

$moduleManagerFactory = new ModuleManagerFactory();
$moduleManager = $moduleManagerFactory->createService($serviceLocator);

$moduleManager->loadModules();

$module = new Module($constant = null, $variable = null, $file = '.testEnv');

$module->init($moduleManager);

$moduleManager->getEventManager()->trigger(new ModuleEvent(ModuleEvent::EVENT_LOAD_MODULE));
}
}

0 comments on commit e82e672

Please sign in to comment.