Skip to content

Instantly share code, notes, and snippets.

@dennis-fedco
Created December 9, 2013 21:52
Show Gist options
  • Save dennis-fedco/7881658 to your computer and use it in GitHub Desktop.
Save dennis-fedco/7881658 to your computer and use it in GitHub Desktop.
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/FedcoUser for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
$additionalNamespaces = $additionalModulePaths = $moduleDependencies = null;
$rootPath = realpath(dirname(__DIR__));
$testsPath = "$rootPath/tests";
if (is_readable($testsPath . '/TestConfiguration.php')) {
require_once $testsPath . '/TestConfiguration.php';
} else {
require_once $testsPath . '/TestConfiguration.php.dist';
}
$path = array(
ZF2_PATH,
get_include_path(),
);
set_include_path(implode(PATH_SEPARATOR, $path));
require_once 'Zend/Loader/AutoloaderFactory.php';
require_once 'Zend/Loader/StandardAutoloader.php';
use Zend\Loader\AutoloaderFactory;
use Zend\Loader\StandardAutoloader;
// setup autoloader
AutoloaderFactory::factory(
array(
'Zend\Loader\StandardAutoloader' => array(
StandardAutoloader::AUTOREGISTER_ZF => true,
StandardAutoloader::ACT_AS_FALLBACK => false,
StandardAutoloader::LOAD_NS => $additionalNamespaces,
)
)
);
// The module name is obtained using directory name or constant
$moduleName = pathinfo($rootPath, PATHINFO_BASENAME);
if (defined('MODULE_NAME')) {
$moduleName = MODULE_NAME;
}
// A locator will be set to this class if available
$moduleTestCaseClassname = '\\'.$moduleName.'Test\\Framework\\TestCase';
// This module's path plus additionally defined paths are used $modulePaths
$modulePaths = array(dirname($rootPath));
if (isset($additionalModulePaths)) {
$modulePaths = array_merge($modulePaths, $additionalModulePaths);
}
// Load this module and defined dependencies
$modules = array($moduleName);
if (isset($moduleDependencies)) {
$modules = array_merge($modules, $moduleDependencies);
}
$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();
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));
}
// When this is in global scope, PHPUnit catches exception:
// Exception: Zend\Stdlib\PriorityQueue::serialize() must return a string or NULL
unset($moduleManager, $sharedEvents);
<phpunit bootstrap="./bootstrap.php" colors="true">
<testsuites>
<testsuite name="FedcoUser Test Suite">
<directory>./</directory>
</testsuite>
</testsuites>
</phpunit>
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/ZendSkeletonModule for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* This file defines configuration for running this module's unit tests.
* Modules are usually located inside a ZF2 application, so a sane default
* for ZEND_FRAMEWORK_PATH is the vendor folder in the application.
*
* If testing outside of a ZF2 application, do not edit this file. Instead,
* create a TestConfiguration.php file that will be used in it's place.
* TestConfiguration.php is ignored by git so that environment specific
* configuration is not committed.
*
* Never commit plaintext passwords to the source code repository.
*/
define('ZF2_PATH', realpath(__DIR__ . '/../../../vendor/zendframework/zendframework/library/'));
/**
* The bootstrap supports several more options, however most modules will
* not need to define these.
*/
// Override the module name (usually because the namespace is something besides the root foldername)
// define('MODULE_NAME', 'SomeModuleName');
// Add additional paths where additional modules can be found
// $additionalModulePaths = array(
// '/usr/share/lib/php/',
// 'SomeVendor' => realpath('/path/for/some/vendor/library'),
// );
// Add dependencies, for example a vendor may create several modules that all depend on a common library
// $moduleDependencies = array('SomeVendor');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment