Skip to content
This repository was archived by the owner on Dec 7, 2019. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/ZendSkeletonModule/SampleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ class SampleTest extends Framework\TestCase

public function testSample()
{
$this->assertInstanceOf('Zend\Di\LocatorInterface', $this->getLocator());
$this->assertInstanceOf('Zend\ServiceManager\ServiceLocatorInterface', $this->getLocator());
}
}
51 changes: 15 additions & 36 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
// setup autoloader
AutoloaderFactory::factory(
array(
'Zend\Loader\StandardAutoloader' => array(
'Zend\Loader\StandardAutoloader' => array(
StandardAutoloader::AUTOREGISTER_ZF => true,
StandardAutoloader::ACT_AS_FALLBACK => false,
StandardAutoloader::LOAD_NS => $additionalNamespaces,
Expand Down Expand Up @@ -62,45 +62,24 @@
$modules = array_merge($modules, $moduleDependencies);
}

$config = array(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use TestConfiguration.php.dist or TestConfiguration.php for this?
Also, I'd stop instantiating the service manager here and instead use something like https://github.com/Ocramius/OcraDiCompiler/blob/master/tests/OcraDiCompilerTest/ServiceManagerTestCase.php

'module_listener_options' => array(
'module_paths' => $modulePaths,
),
'modules' => $modules,
);

$listenerOptions = new Zend\ModuleManager\Listener\ListenerOptions(array('module_paths' => $modulePaths));
$defaultListeners = new Zend\ModuleManager\Listener\DefaultListenerAggregate($listenerOptions);
$sharedEvents = new Zend\EventManager\SharedEventManager();
$moduleManager = new \Zend\ModuleManager\ModuleManager($modules);
$moduleManager->getEventManager()->setSharedManager($sharedEvents);
$moduleManager->getEventManager()->attachAggregate($defaultListeners);
$moduleManager->loadModules();
$serviceManager = new \Zend\ServiceManager\ServiceManager(
new \Zend\Mvc\Service\ServiceManagerConfig()
);
$serviceManager->setService('ApplicationConfig', $config);
$serviceManager->get('ModuleManager')->loadModules();

if (method_exists($moduleTestCaseClassname, 'setLocator')) {
$config = $defaultListeners->getConfigListener()->getMergedConfig();

$di = new \Zend\Di\Di;
$di->instanceManager()->addTypePreference('Zend\Di\LocatorInterface', $di);

if (isset($config['di'])) {
$diConfig = new \Zend\Di\Config($config['di']);
$diConfig->configure($di);
}

$routerDiConfig = new \Zend\Di\Config(
array(
'definition' => array(
'class' => array(
'Zend\Mvc\Router\RouteStackInterface' => array(
'instantiator' => array(
'Zend\Mvc\Router\Http\TreeRouteStack',
'factory'
),
),
),
),
)
);
$routerDiConfig->configure($di);

call_user_func_array($moduleTestCaseClassname.'::setLocator', array($di));
call_user_func_array($moduleTestCaseClassname.'::setLocator', array($serviceManager));
}

// When this is in global scope, PHPUnit catches exception:
// Exception: Zend\Stdlib\PriorityQueue::serialize() must return a string or NULL
unset($moduleManager, $sharedEvents);
unset($serviceManager);