HummingBirdAnimeClient/tests/bootstrap.php

98 lines
2.2 KiB
PHP
Raw Normal View History

<?php
/**
* Global setup for unit tests
*/
2015-09-15 13:19:29 -04:00
use Aviat\AnimeClient\Config;
use Aviat\AnimeClient\Container;
2015-09-17 23:11:18 -04:00
use Aviat\AnimeClient\UrlGenerator;
2015-06-26 16:39:10 -04:00
// -----------------------------------------------------------------------------
// Mock the default error handler
// -----------------------------------------------------------------------------
class MockErrorHandler {
public function addDataTable($name, Array $values) {}
}
// -----------------------------------------------------------------------------
// Define a base testcase class
// -----------------------------------------------------------------------------
/**
* Base class for TestCases
*/
class AnimeClient_TestCase extends PHPUnit_Framework_TestCase {
protected $container;
public function setUp()
{
parent::setUp();
$config = new Config([
'asset_path' => '//localhost/assets/',
'databaase' => [],
'routes' => [
'common' => [],
'anime' => [],
'manga' => []
]
]);
$container = new Container([
2015-09-17 23:11:18 -04:00
'config' => $config,
'error-handler' => new MockErrorHandler()
]);
2015-09-17 23:11:18 -04:00
$container->set('url-generator', new UrlGenerator($container));
$this->container = $container;
}
}
// -----------------------------------------------------------------------------
// Autoloaders
// -----------------------------------------------------------------------------
/**
* Joins paths together. Variadic to take an
* arbitrary number of arguments
*
* @return string
*/
function _dir()
{
return implode(DIRECTORY_SEPARATOR, func_get_args());
}
2015-09-17 23:11:18 -04:00
// Define base path constants
define('ROOT_DIR', realpath(__DIR__ . DIRECTORY_SEPARATOR . "/../"));
define('APP_DIR', _dir(ROOT_DIR, 'app'));
define('CONF_DIR', _dir(APP_DIR, 'config'));
define('SRC_DIR', _dir(ROOT_DIR, 'src'));
define('BASE_DIR', _dir(SRC_DIR, 'Base'));
2015-09-17 23:11:18 -04:00
require _dir(ROOT_DIR, '/vendor/autoload.php');
require _dir(SRC_DIR, 'functions.php');
/**
* Set up autoloaders
*
* @codeCoverageIgnore
* @return void
*/
2015-09-17 23:11:18 -04:00
spl_autoload_register(function ($class) {
$class_parts = explode('\\', $class);
$ns_path = SRC_DIR . '/' . implode('/', $class_parts) . ".php";
2015-09-17 23:11:18 -04:00
if (file_exists($ns_path))
{
require_once($ns_path);
return;
}
});
// Pre-define some superglobals
$_SESSION = [];
$_COOKIE = [];
// End of bootstrap.php