Fix test suite
This commit is contained in:
parent
618328a4c1
commit
00ef5c3706
@ -16,8 +16,8 @@
|
||||
|
||||
namespace Aviat\Ion\View;
|
||||
|
||||
use Zend\Diactoros\Response;
|
||||
use Zend\HttpHandlerRunner\Emitter\SapiEmitter;
|
||||
use Laminas\Diactoros\Response;
|
||||
use Laminas\HttpHandlerRunner\Emitter\SapiEmitter;
|
||||
|
||||
use Aviat\Ion\Exception\DoubleRenderException;
|
||||
use Aviat\Ion\View as BaseView;
|
||||
|
@ -16,22 +16,16 @@
|
||||
|
||||
namespace Aviat\AnimeClient\Tests;
|
||||
|
||||
use const Aviat\AnimeClient\SRC_DIR;
|
||||
|
||||
use function Aviat\Ion\_dir;
|
||||
|
||||
use Aviat\Ion\Json;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Spatie\Snapshots\MatchesSnapshots;
|
||||
use Zend\Diactoros\{
|
||||
use Laminas\Diactoros\{
|
||||
Response as HttpResponse,
|
||||
ServerRequestFactory
|
||||
};
|
||||
|
||||
\define('ROOT_DIR', realpath(__DIR__ . '/../'));
|
||||
\define('TEST_DATA_DIR', __DIR__ . '/test_data');
|
||||
\define('TEST_VIEW_DIR', __DIR__ . '/test_views');
|
||||
|
||||
/**
|
||||
* Base class for TestCases
|
||||
*/
|
||||
@ -39,10 +33,10 @@ class AnimeClientTestCase extends TestCase {
|
||||
use MatchesSnapshots;
|
||||
|
||||
// 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;
|
||||
public const ROOT_DIR = ROOT_DIR;
|
||||
public const SRC_DIR = SRC_DIR;
|
||||
public const TEST_DATA_DIR = __DIR__ . '/test_data';
|
||||
public const TEST_VIEW_DIR = __DIR__ . '/test_views';
|
||||
|
||||
protected $container;
|
||||
protected static $staticContainer;
|
||||
@ -56,7 +50,7 @@ class AnimeClientTestCase extends TestCase {
|
||||
//self::$session_handler = $session_handler;
|
||||
|
||||
// Remove test cache files
|
||||
$files = glob(_dir(TEST_DATA_DIR, 'cache', '*.json'));
|
||||
$files = glob(_dir(self::TEST_DATA_DIR, 'cache', '*.json'));
|
||||
array_map('unlink', $files);
|
||||
}
|
||||
|
||||
@ -64,13 +58,10 @@ class AnimeClientTestCase extends TestCase {
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$ROOT_DIR = realpath(_dir(__DIR__, '/../'));
|
||||
$APP_DIR = _dir($ROOT_DIR, 'app');
|
||||
|
||||
$config_array = [
|
||||
'asset_path' => '/assets',
|
||||
'img_cache_path' => _dir(ROOT_DIR, 'public/images'),
|
||||
'data_cache_path' => _dir(TEST_DATA_DIR, 'cache'),
|
||||
'data_cache_path' => _dir(self::TEST_DATA_DIR, 'cache'),
|
||||
'cache' => [
|
||||
'driver' => 'null',
|
||||
'connection' => []
|
||||
@ -103,11 +94,11 @@ class AnimeClientTestCase extends TestCase {
|
||||
];
|
||||
|
||||
// Set up DI container
|
||||
$di = require _dir($APP_DIR, 'bootstrap.php');
|
||||
$di = require _dir(self::ROOT_DIR, 'app', 'bootstrap.php');
|
||||
$container = $di($config_array);
|
||||
|
||||
// Use mock session handler
|
||||
$container->set('session-handler', function() {
|
||||
$container->set('session-handler', static function() {
|
||||
$session_handler = new TestSessionHandler();
|
||||
session_set_save_handler($session_handler, TRUE);
|
||||
return $session_handler;
|
||||
@ -152,7 +143,7 @@ class AnimeClientTestCase extends TestCase {
|
||||
public function getMockFile(): string
|
||||
{
|
||||
$args = func_get_args();
|
||||
array_unshift($args, TEST_DATA_DIR);
|
||||
array_unshift($args, self::TEST_DATA_DIR);
|
||||
$filePath = implode(DIRECTORY_SEPARATOR, $args);
|
||||
|
||||
return file_get_contents($filePath);
|
||||
|
@ -18,7 +18,7 @@ namespace Aviat\Ion\Tests;
|
||||
|
||||
use Aviat\Ion\Model as BaseModel;
|
||||
|
||||
class BaseModelTest extends Ion_TestCase {
|
||||
class BaseModelTest extends IonTestCase {
|
||||
|
||||
public function testBaseModelSanity()
|
||||
{
|
||||
|
@ -18,7 +18,7 @@ namespace Aviat\Ion\Tests;
|
||||
|
||||
use Aviat\Ion\Config;
|
||||
|
||||
class ConfigTest extends Ion_TestCase {
|
||||
class ConfigTest extends IonTestCase {
|
||||
|
||||
protected $config;
|
||||
|
||||
|
@ -17,7 +17,7 @@
|
||||
namespace Aviat\Ion\Tests\Di;
|
||||
|
||||
use Aviat\Ion\Di\{Container, ContainerAware, ContainerInterface};
|
||||
use Aviat\Ion\Tests\Ion_TestCase;
|
||||
use Aviat\Ion\Tests\IonTestCase;
|
||||
|
||||
class Aware {
|
||||
use ContainerAware;
|
||||
@ -29,7 +29,7 @@ class Aware {
|
||||
}
|
||||
|
||||
|
||||
class ContainerAwareTest extends Ion_TestCase {
|
||||
class ContainerAwareTest extends IonTestCase {
|
||||
|
||||
protected $aware;
|
||||
|
||||
|
@ -18,7 +18,7 @@ namespace Aviat\Ion\Tests\Di;
|
||||
|
||||
use Aviat\Ion\Di\{Container, ContainerAware};
|
||||
use Aviat\Ion\Di\Exception\ContainerException;
|
||||
use Aviat\Ion\Tests\Ion_TestCase;
|
||||
use Aviat\Ion\Tests\IonTestCase;
|
||||
use Monolog\Logger;
|
||||
use Monolog\Handler\{TestHandler, NullHandler};
|
||||
use Aviat\Ion\Di\ContainerInterface;
|
||||
@ -37,7 +37,7 @@ class FooTest2 {
|
||||
use ContainerAware;
|
||||
}
|
||||
|
||||
class ContainerTest extends Ion_TestCase {
|
||||
class ContainerTest extends IonTestCase {
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
|
@ -18,7 +18,7 @@ namespace Aviat\Ion\Tests;
|
||||
|
||||
use Aviat\Ion\Enum;
|
||||
|
||||
class EnumTest extends Ion_TestCase {
|
||||
class EnumTest extends IonTestCase {
|
||||
|
||||
protected $expectedConstList = [
|
||||
'FOO' => 'bar',
|
||||
|
@ -17,9 +17,9 @@
|
||||
namespace Aviat\Ion\Tests\Exception;
|
||||
|
||||
use Aviat\Ion\Exception\DoubleRenderException;
|
||||
use Aviat\Ion\Tests\Ion_TestCase;
|
||||
use Aviat\Ion\Tests\IonTestCase;
|
||||
|
||||
class DoubleRenderExceptionTest extends Ion_TestCase {
|
||||
class DoubleRenderExceptionTest extends IonTestCase {
|
||||
|
||||
public function testDefaultMessage()
|
||||
{
|
||||
|
@ -19,7 +19,7 @@ namespace Aviat\Ion\Tests;
|
||||
use Aviat\Ion\Friend;
|
||||
use Aviat\Ion\Tests\FriendTestClass;
|
||||
|
||||
class FriendTest extends Ion_TestCase {
|
||||
class FriendTest extends IonTestCase {
|
||||
|
||||
public function setUp(): void {
|
||||
parent::setUp();
|
||||
|
@ -19,22 +19,17 @@ namespace Aviat\Ion\Tests;
|
||||
use function Aviat\Ion\_dir;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Zend\Diactoros\ServerRequestFactory;
|
||||
|
||||
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');
|
||||
use Laminas\Diactoros\ServerRequestFactory;
|
||||
|
||||
/**
|
||||
* Base class for TestCases
|
||||
*/
|
||||
class Ion_TestCase extends TestCase {
|
||||
class IonTestCase extends TestCase {
|
||||
// Test directory constants
|
||||
public const ROOT_DIR = ROOT_DIR;
|
||||
public const SRC_DIR = SRC_DIR;
|
||||
public const TEST_DATA_DIR = TEST_DATA_DIR;
|
||||
public const TEST_VIEW_DIR = TEST_VIEW_DIR;
|
||||
public const TEST_DATA_DIR = __DIR__ . '/test_data';
|
||||
public const TEST_VIEW_DIR = __DIR__ . '/test_views';
|
||||
|
||||
protected $container;
|
||||
protected static $staticContainer;
|
||||
@ -130,4 +125,4 @@ class Ion_TestCase extends TestCase {
|
||||
$this->container->setInstance('request', $request);
|
||||
}
|
||||
}
|
||||
// End of Ion_TestCase.php
|
||||
// End of IonTestCase.php
|
@ -20,7 +20,7 @@ use function Aviat\Ion\_dir;
|
||||
|
||||
use Aviat\Ion\{Json, JsonException};
|
||||
|
||||
class JsonTest extends Ion_TestCase {
|
||||
class JsonTest extends IonTestCase {
|
||||
|
||||
public function testEncode()
|
||||
{
|
||||
|
@ -17,9 +17,9 @@
|
||||
namespace Aviat\Ion\Tests\Model;
|
||||
|
||||
use Aviat\Ion\Model\DB as BaseDBModel;
|
||||
use Aviat\Ion\Tests\Ion_TestCase;
|
||||
use Aviat\Ion\Tests\IonTestCase;
|
||||
|
||||
class BaseDBModelTest extends Ion_TestCase {
|
||||
class BaseDBModelTest extends IonTestCase {
|
||||
|
||||
public function testBaseDBModelSanity()
|
||||
{
|
||||
|
@ -16,10 +16,10 @@
|
||||
|
||||
namespace Aviat\Ion\Tests\Transformer;
|
||||
|
||||
use Aviat\Ion\Tests\Ion_TestCase;
|
||||
use Aviat\Ion\Tests\IonTestCase;
|
||||
use Aviat\Ion\Tests\{TestTransformer, TestTransformerUntransform};
|
||||
|
||||
class AbstractTransformerTest extends Ion_TestCase {
|
||||
class AbstractTransformerTest extends IonTestCase {
|
||||
|
||||
protected $transformer;
|
||||
protected $untransformer;
|
||||
|
@ -17,9 +17,9 @@
|
||||
namespace Aviat\Ion\Tests\Type;
|
||||
|
||||
use Aviat\Ion\ArrayWrapper;
|
||||
use Aviat\Ion\Tests\Ion_TestCase;
|
||||
use Aviat\Ion\Tests\IonTestCase;
|
||||
|
||||
class ArrayTypeTest extends Ion_TestCase {
|
||||
class ArrayTypeTest extends IonTestCase {
|
||||
use ArrayWrapper;
|
||||
|
||||
public function setUp(): void {
|
||||
|
@ -17,9 +17,9 @@
|
||||
namespace Aviat\Ion\Tests\Type;
|
||||
|
||||
use Aviat\Ion\StringWrapper;
|
||||
use Aviat\Ion\Tests\Ion_TestCase;
|
||||
use Aviat\Ion\Tests\IonTestCase;
|
||||
|
||||
class StringTypeTest extends Ion_TestCase {
|
||||
class StringTypeTest extends IonTestCase {
|
||||
use StringWrapper;
|
||||
|
||||
|
||||
|
@ -18,10 +18,10 @@ namespace Aviat\Ion\Tests\View;
|
||||
|
||||
use Aviat\Ion\Friend;
|
||||
use Aviat\Ion\Exception\DoubleRenderException;
|
||||
use Aviat\Ion\Tests\Ion_TestCase;
|
||||
use Aviat\Ion\Tests\IonTestCase;
|
||||
use Aviat\Ion\Tests\TestHttpView;
|
||||
|
||||
class HttpViewTest extends Ion_TestCase {
|
||||
class HttpViewTest extends IonTestCase {
|
||||
|
||||
protected $view;
|
||||
protected $friend;
|
||||
|
@ -15,7 +15,7 @@ if ($timezone === '' || $timezone === FALSE)
|
||||
// -----------------------------------------------------------------------------
|
||||
// Composer autoload
|
||||
require realpath(__DIR__ . '/../vendor/autoload.php');
|
||||
require 'Ion_TestCase.php';
|
||||
require 'IonTestCase.php';
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Ini Settings
|
||||
|
@ -2,8 +2,8 @@
|
||||
|
||||
use Aura\Html\HelperLocatorFactory;
|
||||
use Aura\Session\SessionFactory;
|
||||
use Zend\Diactoros\ServerRequestFactory;
|
||||
use Zend\Diactoros\Response;
|
||||
use Laminas\Diactoros\ServerRequestFactory;
|
||||
use Laminas\Diactoros\Response;
|
||||
|
||||
use Aviat\Ion\Config;
|
||||
use Aviat\Ion\Di\Container;
|
||||
|
45
tests/bootstrap.php
Normal file
45
tests/bootstrap.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php declare(strict_types=1);
|
||||
/**
|
||||
* Global setup for unit tests
|
||||
*/
|
||||
|
||||
// Work around the silly timezone error
|
||||
$timezone = ini_get('date.timezone');
|
||||
if ($timezone === '' || $timezone === FALSE)
|
||||
{
|
||||
ini_set('date.timezone', 'GMT');
|
||||
}
|
||||
|
||||
define('ROOT_DIR', realpath(__DIR__ . '/../') . '/');
|
||||
define('SRC_DIR', ROOT_DIR . 'src/');
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Autoloading
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
require_once __DIR__ . '/AnimeClient/AnimeClientTestCase.php';
|
||||
require_once __DIR__ . '/Ion/IonTestCase.php';
|
||||
require_once __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Ini Settings
|
||||
// -----------------------------------------------------------------------------
|
||||
ini_set('session.use_cookies', '0');
|
||||
ini_set('session.use_only_cookies', '0');
|
||||
ini_set('session.use_trans_sid', '1');
|
||||
// Start session here to supress error about headers not sent
|
||||
session_start();
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Load base test case and mocks
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// Pre-define some superglobals
|
||||
$_SESSION = [];
|
||||
$_COOKIE = [];
|
||||
|
||||
// Request base test case and mocks
|
||||
require_once __DIR__ . '/AnimeClient/mocks.php';
|
||||
require_once __DIR__ . '/Ion/mocks.php';
|
||||
|
||||
// End of bootstrap.php
|
Loading…
Reference in New Issue
Block a user