2015-06-25 17:00:29 -04:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Global setup for unit tests
|
|
|
|
*/
|
2015-10-09 14:34:55 -04:00
|
|
|
use Aura\Web\WebFactory;
|
2015-06-25 17:00:29 -04:00
|
|
|
|
2015-09-15 13:19:29 -04:00
|
|
|
use Aviat\AnimeClient\Config;
|
2015-09-25 13:41:12 -04:00
|
|
|
use Aviat\Ion\Di\Container;
|
2015-09-17 23:11:18 -04:00
|
|
|
use Aviat\AnimeClient\UrlGenerator;
|
2015-06-26 16:39:10 -04:00
|
|
|
|
2015-06-25 17:00:29 -04:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Autoloaders
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
2015-09-14 10:54:50 -04:00
|
|
|
/**
|
|
|
|
* 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
|
2015-09-25 13:41:12 -04:00
|
|
|
define('ROOT_DIR', realpath(_dir(__DIR__, "/../")));
|
2015-06-25 17:00:29 -04:00
|
|
|
define('APP_DIR', _dir(ROOT_DIR, 'app'));
|
|
|
|
define('CONF_DIR', _dir(APP_DIR, 'config'));
|
2015-09-14 10:54:50 -04:00
|
|
|
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');
|
2015-10-09 14:34:55 -04:00
|
|
|
require _dir(SRC_DIR, '/functions.php');
|
2015-09-14 10:54:50 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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-06-25 17:00:29 -04:00
|
|
|
|
2015-09-17 23:11:18 -04:00
|
|
|
if (file_exists($ns_path))
|
|
|
|
{
|
|
|
|
require_once($ns_path);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
});
|
2015-06-26 12:03:42 -04:00
|
|
|
|
|
|
|
// Pre-define some superglobals
|
|
|
|
$_SESSION = [];
|
|
|
|
$_COOKIE = [];
|
2015-06-25 17:00:29 -04:00
|
|
|
|
2015-10-09 14:34:55 -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_array = [
|
|
|
|
'asset_path' => '//localhost/assets/',
|
|
|
|
'databaase' => [],
|
|
|
|
'routing' => [
|
|
|
|
|
|
|
|
],
|
|
|
|
'routes' => [
|
|
|
|
'convention' => [
|
|
|
|
'default_controller' => '',
|
|
|
|
'default_method' => '',
|
|
|
|
],
|
|
|
|
'common' => [],
|
|
|
|
'anime' => [],
|
|
|
|
'manga' => []
|
|
|
|
]
|
|
|
|
];
|
|
|
|
|
|
|
|
$di = require _dir(APP_DIR, 'bootstrap.php');
|
|
|
|
$container = $di($config_array);
|
|
|
|
$container->set('error-handler', new MockErrorHandler());
|
|
|
|
|
|
|
|
$this->container = $container;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set arbitrary superglobal values for testing purposes
|
|
|
|
*
|
|
|
|
* @param array $supers
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function setSuperGlobals($supers = [])
|
|
|
|
{
|
|
|
|
$default = [
|
|
|
|
'_GET' => $_GET,
|
|
|
|
'_POST' => $_POST,
|
|
|
|
'_COOKIE' => $_COOKIE,
|
|
|
|
'_SERVER' => $_SERVER,
|
|
|
|
'_FILES' => $_FILES
|
|
|
|
];
|
|
|
|
$web_factory = new WebFactory(array_merge($default,$supers));
|
|
|
|
$this->container->set('request', $web_factory->newRequest());
|
|
|
|
$this->container->set('response', $web_factory->newResponse());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// End of bootstrap.php
|