2016-08-04 14:55:37 -04:00
|
|
|
<?php
|
|
|
|
|
2016-10-19 13:24:08 -04:00
|
|
|
namespace Aviat\Ion\Tests;
|
|
|
|
|
2016-08-04 14:55:37 -04:00
|
|
|
use Aura\Web\WebFactory;
|
2016-10-19 13:24:08 -04:00
|
|
|
use Aviat\Ion\Json;
|
2016-08-04 14:55:37 -04:00
|
|
|
use GuzzleHttp\Client;
|
|
|
|
use GuzzleHttp\Handler\MockHandler;
|
|
|
|
use GuzzleHttp\HandlerStack;
|
|
|
|
use GuzzleHttp\Psr7\Response;
|
2016-10-19 13:24:08 -04:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2016-08-04 14:55:37 -04:00
|
|
|
use Zend\Diactoros\ServerRequestFactory;
|
|
|
|
use Zend\Diactoros\Response as HttpResponse;
|
|
|
|
|
|
|
|
define('ROOT_DIR', realpath(__DIR__ . '/../') . '/');
|
|
|
|
define('SRC_DIR', ROOT_DIR . 'src/');
|
|
|
|
define('TEST_DATA_DIR', __DIR__ . '/test_data');
|
|
|
|
define('TEST_VIEW_DIR', __DIR__ . '/test_views');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Base class for TestCases
|
|
|
|
*/
|
2016-10-19 13:24:08 -04:00
|
|
|
class Ion_TestCase extends TestCase {
|
2016-08-04 14:55:37 -04:00
|
|
|
// Test directory constants
|
|
|
|
const ROOT_DIR = ROOT_DIR;
|
|
|
|
const SRC_DIR = SRC_DIR;
|
|
|
|
const TEST_DATA_DIR = TEST_DATA_DIR;
|
|
|
|
const TEST_VIEW_DIR = TEST_VIEW_DIR;
|
|
|
|
|
|
|
|
protected $container;
|
|
|
|
protected static $staticContainer;
|
|
|
|
protected static $session_handler;
|
|
|
|
|
2016-08-29 12:51:40 -04:00
|
|
|
/*public static function setUpBeforeClass()
|
2016-08-04 14:55:37 -04:00
|
|
|
{
|
|
|
|
// Use mock session handler
|
|
|
|
$session_handler = new TestSessionHandler();
|
|
|
|
session_set_save_handler($session_handler, TRUE);
|
|
|
|
self::$session_handler = $session_handler;
|
2016-08-29 12:51:40 -04:00
|
|
|
}*/
|
2016-08-04 14:55:37 -04:00
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$ROOT_DIR = realpath(_dir(__DIR__, '/../'));
|
|
|
|
$APP_DIR = _dir($ROOT_DIR, 'app');
|
|
|
|
|
|
|
|
$config_array = [
|
|
|
|
'asset_path' => '//localhost/assets/',
|
|
|
|
'img_cache_path' => _dir(ROOT_DIR, 'public/images'),
|
|
|
|
'database' => [
|
|
|
|
'collection' => [
|
|
|
|
'type' => 'sqlite',
|
|
|
|
'host' => '',
|
|
|
|
'user' => '',
|
|
|
|
'pass' => '',
|
|
|
|
'port' => '',
|
|
|
|
'name' => 'default',
|
|
|
|
'database' => '',
|
|
|
|
'file' => ':memory:',
|
|
|
|
],
|
|
|
|
'cache' => [
|
|
|
|
'type' => 'sqlite',
|
|
|
|
'host' => '',
|
|
|
|
'user' => '',
|
|
|
|
'pass' => '',
|
|
|
|
'port' => '',
|
|
|
|
'name' => 'default',
|
|
|
|
'database' => '',
|
|
|
|
'file' => ':memory:',
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'routes' => [
|
|
|
|
'route_config' => [
|
|
|
|
'asset_path' => '/assets'
|
|
|
|
],
|
|
|
|
'routes' => [
|
|
|
|
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'redis' => [
|
|
|
|
'host' => (array_key_exists('REDIS_HOST', $_ENV)) ? $_ENV['REDIS_HOST'] : 'localhost',
|
|
|
|
'database' => 13
|
|
|
|
]
|
|
|
|
];
|
|
|
|
|
|
|
|
// Set up DI container
|
|
|
|
$di = require('di.php');
|
|
|
|
$container = $di($config_array);
|
2016-08-29 12:51:40 -04:00
|
|
|
$container->set('session-handler', function() {
|
|
|
|
// Use mock session handler
|
|
|
|
$session_handler = new TestSessionHandler();
|
|
|
|
session_set_save_handler($session_handler, TRUE);
|
|
|
|
return $session_handler;
|
|
|
|
});
|
2016-08-04 14:55:37 -04:00
|
|
|
|
|
|
|
$this->container = $container;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set arbitrary superglobal values for testing purposes
|
|
|
|
*
|
|
|
|
* @param array $supers
|
|
|
|
* @return void
|
|
|
|
*/
|
2016-10-19 13:24:08 -04:00
|
|
|
public function setSuperGlobals(array $supers = [])
|
2016-08-04 14:55:37 -04:00
|
|
|
{
|
|
|
|
$default = [
|
|
|
|
'_SERVER' => $_SERVER,
|
|
|
|
'_GET' => $_GET,
|
|
|
|
'_POST' => $_POST,
|
|
|
|
'_COOKIE' => $_COOKIE,
|
|
|
|
'_FILES' => $_FILES
|
|
|
|
];
|
|
|
|
|
|
|
|
$request = call_user_func_array(
|
|
|
|
['Zend\Diactoros\ServerRequestFactory', 'fromGlobals'],
|
|
|
|
array_merge($default, $supers)
|
|
|
|
);
|
2016-08-29 12:51:40 -04:00
|
|
|
$this->container->setInstance('request', $request);
|
2016-08-04 14:55:37 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// End of Ion_TestCase.php
|