2020-03-11 23:04:01 -04:00
|
|
|
<?php declare(strict_types=1);
|
|
|
|
/**
|
2020-03-12 11:45:11 -04:00
|
|
|
* Hummingbird Anime List Client
|
2020-03-11 23:04:01 -04:00
|
|
|
*
|
2020-03-12 11:45:11 -04:00
|
|
|
* An API client for Kitsu to manage anime and manga watch lists
|
2020-03-11 23:04:01 -04:00
|
|
|
*
|
2021-02-04 11:57:01 -05:00
|
|
|
* PHP version 8
|
2020-03-11 23:04:01 -04:00
|
|
|
*
|
2020-03-12 11:45:11 -04:00
|
|
|
* @package HummingbirdAnimeClient
|
2020-03-11 23:04:01 -04:00
|
|
|
* @author Timothy J. Warren <tim@timshomepage.net>
|
2021-01-13 01:52:03 -05:00
|
|
|
* @copyright 2015 - 2021 Timothy J. Warren
|
2020-03-11 23:04:01 -04:00
|
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
2020-12-10 17:06:50 -05:00
|
|
|
* @version 5.2
|
2020-03-12 11:45:11 -04:00
|
|
|
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
|
2020-03-11 23:04:01 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Aviat\Ion\Tests;
|
|
|
|
|
|
|
|
use function Aviat\Ion\_dir;
|
|
|
|
|
2020-04-10 16:35:01 -04:00
|
|
|
use Aviat\Ion\Di\ContainerInterface;
|
2020-03-11 23:04:01 -04:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2020-03-12 09:52:45 -04:00
|
|
|
use Laminas\Diactoros\ServerRequestFactory;
|
2020-03-11 23:04:01 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Base class for TestCases
|
|
|
|
*/
|
2020-03-12 09:52:45 -04:00
|
|
|
class IonTestCase extends TestCase {
|
2020-03-11 23:04:01 -04:00
|
|
|
// Test directory constants
|
2021-02-03 10:27:04 -05:00
|
|
|
public const ROOT_DIR = AC_TEST_ROOT_DIR;
|
2020-03-11 23:04:01 -04:00
|
|
|
public const SRC_DIR = SRC_DIR;
|
2020-03-12 09:52:45 -04:00
|
|
|
public const TEST_DATA_DIR = __DIR__ . '/test_data';
|
|
|
|
public const TEST_VIEW_DIR = __DIR__ . '/test_views';
|
2020-03-11 23:04:01 -04:00
|
|
|
|
2020-04-10 16:35:01 -04:00
|
|
|
protected ContainerInterface $container;
|
2020-03-11 23:04:01 -04:00
|
|
|
protected static $staticContainer;
|
|
|
|
protected static $session_handler;
|
|
|
|
|
|
|
|
/*public static function setUpBeforeClass()
|
|
|
|
{
|
|
|
|
// Use mock session handler
|
|
|
|
$session_handler = new TestSessionHandler();
|
|
|
|
session_set_save_handler($session_handler, TRUE);
|
|
|
|
self::$session_handler = $session_handler;
|
|
|
|
}*/
|
|
|
|
|
|
|
|
public function setUp(): void
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
$container->set('session-handler', static function() {
|
|
|
|
// Use mock session handler
|
|
|
|
$session_handler = new TestSessionHandler();
|
|
|
|
session_set_save_handler($session_handler, TRUE);
|
|
|
|
return $session_handler;
|
|
|
|
});
|
|
|
|
|
|
|
|
$this->container = $container;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set arbitrary superglobal values for testing purposes
|
|
|
|
*
|
|
|
|
* @param array $supers
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function setSuperGlobals(array $supers = []): void
|
|
|
|
{
|
|
|
|
$default = [
|
2020-12-11 14:26:54 -05:00
|
|
|
'_SERVER' => $GLOBALS['_SERVER'],
|
2020-03-11 23:04:01 -04:00
|
|
|
'_GET' => $_GET,
|
|
|
|
'_POST' => $_POST,
|
|
|
|
'_COOKIE' => $_COOKIE,
|
|
|
|
'_FILES' => $_FILES
|
|
|
|
];
|
|
|
|
|
|
|
|
$request = call_user_func_array(
|
|
|
|
[ServerRequestFactory::class, 'fromGlobals'],
|
|
|
|
array_merge($default, $supers)
|
|
|
|
);
|
|
|
|
$this->container->setInstance('request', $request);
|
|
|
|
}
|
|
|
|
}
|
2020-03-12 09:52:45 -04:00
|
|
|
// End of IonTestCase.php
|