Fix test suite
This commit is contained in:
parent
618328a4c1
commit
00ef5c3706
@ -16,8 +16,8 @@
|
|||||||
|
|
||||||
namespace Aviat\Ion\View;
|
namespace Aviat\Ion\View;
|
||||||
|
|
||||||
use Zend\Diactoros\Response;
|
use Laminas\Diactoros\Response;
|
||||||
use Zend\HttpHandlerRunner\Emitter\SapiEmitter;
|
use Laminas\HttpHandlerRunner\Emitter\SapiEmitter;
|
||||||
|
|
||||||
use Aviat\Ion\Exception\DoubleRenderException;
|
use Aviat\Ion\Exception\DoubleRenderException;
|
||||||
use Aviat\Ion\View as BaseView;
|
use Aviat\Ion\View as BaseView;
|
||||||
|
@ -16,22 +16,16 @@
|
|||||||
|
|
||||||
namespace Aviat\AnimeClient\Tests;
|
namespace Aviat\AnimeClient\Tests;
|
||||||
|
|
||||||
use const Aviat\AnimeClient\SRC_DIR;
|
|
||||||
|
|
||||||
use function Aviat\Ion\_dir;
|
use function Aviat\Ion\_dir;
|
||||||
|
|
||||||
use Aviat\Ion\Json;
|
use Aviat\Ion\Json;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Spatie\Snapshots\MatchesSnapshots;
|
use Spatie\Snapshots\MatchesSnapshots;
|
||||||
use Zend\Diactoros\{
|
use Laminas\Diactoros\{
|
||||||
Response as HttpResponse,
|
Response as HttpResponse,
|
||||||
ServerRequestFactory
|
ServerRequestFactory
|
||||||
};
|
};
|
||||||
|
|
||||||
\define('ROOT_DIR', realpath(__DIR__ . '/../'));
|
|
||||||
\define('TEST_DATA_DIR', __DIR__ . '/test_data');
|
|
||||||
\define('TEST_VIEW_DIR', __DIR__ . '/test_views');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for TestCases
|
* Base class for TestCases
|
||||||
*/
|
*/
|
||||||
@ -39,10 +33,10 @@ class AnimeClientTestCase extends TestCase {
|
|||||||
use MatchesSnapshots;
|
use MatchesSnapshots;
|
||||||
|
|
||||||
// Test directory constants
|
// Test directory constants
|
||||||
const ROOT_DIR = ROOT_DIR;
|
public const ROOT_DIR = ROOT_DIR;
|
||||||
const SRC_DIR = SRC_DIR;
|
public const SRC_DIR = SRC_DIR;
|
||||||
const TEST_DATA_DIR = TEST_DATA_DIR;
|
public const TEST_DATA_DIR = __DIR__ . '/test_data';
|
||||||
const TEST_VIEW_DIR = TEST_VIEW_DIR;
|
public const TEST_VIEW_DIR = __DIR__ . '/test_views';
|
||||||
|
|
||||||
protected $container;
|
protected $container;
|
||||||
protected static $staticContainer;
|
protected static $staticContainer;
|
||||||
@ -56,7 +50,7 @@ class AnimeClientTestCase extends TestCase {
|
|||||||
//self::$session_handler = $session_handler;
|
//self::$session_handler = $session_handler;
|
||||||
|
|
||||||
// Remove test cache files
|
// 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);
|
array_map('unlink', $files);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,13 +58,10 @@ class AnimeClientTestCase extends TestCase {
|
|||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
$ROOT_DIR = realpath(_dir(__DIR__, '/../'));
|
|
||||||
$APP_DIR = _dir($ROOT_DIR, 'app');
|
|
||||||
|
|
||||||
$config_array = [
|
$config_array = [
|
||||||
'asset_path' => '/assets',
|
'asset_path' => '/assets',
|
||||||
'img_cache_path' => _dir(ROOT_DIR, 'public/images'),
|
'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' => [
|
'cache' => [
|
||||||
'driver' => 'null',
|
'driver' => 'null',
|
||||||
'connection' => []
|
'connection' => []
|
||||||
@ -103,11 +94,11 @@ class AnimeClientTestCase extends TestCase {
|
|||||||
];
|
];
|
||||||
|
|
||||||
// Set up DI container
|
// Set up DI container
|
||||||
$di = require _dir($APP_DIR, 'bootstrap.php');
|
$di = require _dir(self::ROOT_DIR, 'app', 'bootstrap.php');
|
||||||
$container = $di($config_array);
|
$container = $di($config_array);
|
||||||
|
|
||||||
// Use mock session handler
|
// Use mock session handler
|
||||||
$container->set('session-handler', function() {
|
$container->set('session-handler', static function() {
|
||||||
$session_handler = new TestSessionHandler();
|
$session_handler = new TestSessionHandler();
|
||||||
session_set_save_handler($session_handler, TRUE);
|
session_set_save_handler($session_handler, TRUE);
|
||||||
return $session_handler;
|
return $session_handler;
|
||||||
@ -152,7 +143,7 @@ class AnimeClientTestCase extends TestCase {
|
|||||||
public function getMockFile(): string
|
public function getMockFile(): string
|
||||||
{
|
{
|
||||||
$args = func_get_args();
|
$args = func_get_args();
|
||||||
array_unshift($args, TEST_DATA_DIR);
|
array_unshift($args, self::TEST_DATA_DIR);
|
||||||
$filePath = implode(DIRECTORY_SEPARATOR, $args);
|
$filePath = implode(DIRECTORY_SEPARATOR, $args);
|
||||||
|
|
||||||
return file_get_contents($filePath);
|
return file_get_contents($filePath);
|
||||||
|
@ -17,16 +17,16 @@
|
|||||||
namespace Aviat\AnimeClient\Tests;
|
namespace Aviat\AnimeClient\Tests;
|
||||||
|
|
||||||
class TestSessionHandler implements \SessionHandlerInterface {
|
class TestSessionHandler implements \SessionHandlerInterface {
|
||||||
|
|
||||||
public $data = [];
|
public $data = [];
|
||||||
public $savePath = './test_data/sessions';
|
public $savePath = './test_data/sessions';
|
||||||
|
|
||||||
public function close()
|
public function close()
|
||||||
{
|
{
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function destroy($id)
|
public function destroy($id)
|
||||||
{
|
{
|
||||||
$file = "$this->savePath/$id";
|
$file = "$this->savePath/$id";
|
||||||
if (file_exists($file))
|
if (file_exists($file))
|
||||||
@ -36,13 +36,13 @@ class TestSessionHandler implements \SessionHandlerInterface {
|
|||||||
$this->data[$id] = [];
|
$this->data[$id] = [];
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function gc($maxLifetime)
|
public function gc($maxLifetime)
|
||||||
{
|
{
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function open($savePath, $name)
|
public function open($savePath, $name)
|
||||||
{
|
{
|
||||||
/*if ( ! array_key_exists($savePath, $this->data))
|
/*if ( ! array_key_exists($savePath, $this->data))
|
||||||
{
|
{
|
||||||
@ -51,19 +51,19 @@ class TestSessionHandler implements \SessionHandlerInterface {
|
|||||||
}*/
|
}*/
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function read($id)
|
public function read($id)
|
||||||
{
|
{
|
||||||
return json_decode(@file_get_contents("$this->savePath/$id"), TRUE);
|
return json_decode(@file_get_contents("$this->savePath/$id"), TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function write($id, $data)
|
public function write($id, $data)
|
||||||
{
|
{
|
||||||
$file = "$this->savePath/$id";
|
$file = "$this->savePath/$id";
|
||||||
file_put_contents($file, json_encode($data));
|
file_put_contents($file, json_encode($data));
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
// End of TestSessionHandler.php
|
// End of TestSessionHandler.php
|
@ -18,7 +18,7 @@ namespace Aviat\Ion\Tests;
|
|||||||
|
|
||||||
use Aviat\Ion\Model as BaseModel;
|
use Aviat\Ion\Model as BaseModel;
|
||||||
|
|
||||||
class BaseModelTest extends Ion_TestCase {
|
class BaseModelTest extends IonTestCase {
|
||||||
|
|
||||||
public function testBaseModelSanity()
|
public function testBaseModelSanity()
|
||||||
{
|
{
|
||||||
|
@ -18,7 +18,7 @@ namespace Aviat\Ion\Tests;
|
|||||||
|
|
||||||
use Aviat\Ion\Config;
|
use Aviat\Ion\Config;
|
||||||
|
|
||||||
class ConfigTest extends Ion_TestCase {
|
class ConfigTest extends IonTestCase {
|
||||||
|
|
||||||
protected $config;
|
protected $config;
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
namespace Aviat\Ion\Tests\Di;
|
namespace Aviat\Ion\Tests\Di;
|
||||||
|
|
||||||
use Aviat\Ion\Di\{Container, ContainerAware, ContainerInterface};
|
use Aviat\Ion\Di\{Container, ContainerAware, ContainerInterface};
|
||||||
use Aviat\Ion\Tests\Ion_TestCase;
|
use Aviat\Ion\Tests\IonTestCase;
|
||||||
|
|
||||||
class Aware {
|
class Aware {
|
||||||
use ContainerAware;
|
use ContainerAware;
|
||||||
@ -29,7 +29,7 @@ class Aware {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class ContainerAwareTest extends Ion_TestCase {
|
class ContainerAwareTest extends IonTestCase {
|
||||||
|
|
||||||
protected $aware;
|
protected $aware;
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ namespace Aviat\Ion\Tests\Di;
|
|||||||
|
|
||||||
use Aviat\Ion\Di\{Container, ContainerAware};
|
use Aviat\Ion\Di\{Container, ContainerAware};
|
||||||
use Aviat\Ion\Di\Exception\ContainerException;
|
use Aviat\Ion\Di\Exception\ContainerException;
|
||||||
use Aviat\Ion\Tests\Ion_TestCase;
|
use Aviat\Ion\Tests\IonTestCase;
|
||||||
use Monolog\Logger;
|
use Monolog\Logger;
|
||||||
use Monolog\Handler\{TestHandler, NullHandler};
|
use Monolog\Handler\{TestHandler, NullHandler};
|
||||||
use Aviat\Ion\Di\ContainerInterface;
|
use Aviat\Ion\Di\ContainerInterface;
|
||||||
@ -37,7 +37,7 @@ class FooTest2 {
|
|||||||
use ContainerAware;
|
use ContainerAware;
|
||||||
}
|
}
|
||||||
|
|
||||||
class ContainerTest extends Ion_TestCase {
|
class ContainerTest extends IonTestCase {
|
||||||
|
|
||||||
public function setUp(): void
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
|
@ -18,7 +18,7 @@ namespace Aviat\Ion\Tests;
|
|||||||
|
|
||||||
use Aviat\Ion\Enum;
|
use Aviat\Ion\Enum;
|
||||||
|
|
||||||
class EnumTest extends Ion_TestCase {
|
class EnumTest extends IonTestCase {
|
||||||
|
|
||||||
protected $expectedConstList = [
|
protected $expectedConstList = [
|
||||||
'FOO' => 'bar',
|
'FOO' => 'bar',
|
||||||
|
@ -17,9 +17,9 @@
|
|||||||
namespace Aviat\Ion\Tests\Exception;
|
namespace Aviat\Ion\Tests\Exception;
|
||||||
|
|
||||||
use Aviat\Ion\Exception\DoubleRenderException;
|
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()
|
public function testDefaultMessage()
|
||||||
{
|
{
|
||||||
|
@ -19,7 +19,7 @@ namespace Aviat\Ion\Tests;
|
|||||||
use Aviat\Ion\Friend;
|
use Aviat\Ion\Friend;
|
||||||
use Aviat\Ion\Tests\FriendTestClass;
|
use Aviat\Ion\Tests\FriendTestClass;
|
||||||
|
|
||||||
class FriendTest extends Ion_TestCase {
|
class FriendTest extends IonTestCase {
|
||||||
|
|
||||||
public function setUp(): void {
|
public function setUp(): void {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
@ -19,22 +19,17 @@ namespace Aviat\Ion\Tests;
|
|||||||
use function Aviat\Ion\_dir;
|
use function Aviat\Ion\_dir;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Zend\Diactoros\ServerRequestFactory;
|
use Laminas\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');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for TestCases
|
* Base class for TestCases
|
||||||
*/
|
*/
|
||||||
class Ion_TestCase extends TestCase {
|
class IonTestCase extends TestCase {
|
||||||
// Test directory constants
|
// Test directory constants
|
||||||
public const ROOT_DIR = ROOT_DIR;
|
public const ROOT_DIR = ROOT_DIR;
|
||||||
public const SRC_DIR = SRC_DIR;
|
public const SRC_DIR = SRC_DIR;
|
||||||
public const TEST_DATA_DIR = TEST_DATA_DIR;
|
public const TEST_DATA_DIR = __DIR__ . '/test_data';
|
||||||
public const TEST_VIEW_DIR = TEST_VIEW_DIR;
|
public const TEST_VIEW_DIR = __DIR__ . '/test_views';
|
||||||
|
|
||||||
protected $container;
|
protected $container;
|
||||||
protected static $staticContainer;
|
protected static $staticContainer;
|
||||||
@ -130,4 +125,4 @@ class Ion_TestCase extends TestCase {
|
|||||||
$this->container->setInstance('request', $request);
|
$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};
|
use Aviat\Ion\{Json, JsonException};
|
||||||
|
|
||||||
class JsonTest extends Ion_TestCase {
|
class JsonTest extends IonTestCase {
|
||||||
|
|
||||||
public function testEncode()
|
public function testEncode()
|
||||||
{
|
{
|
||||||
|
@ -17,9 +17,9 @@
|
|||||||
namespace Aviat\Ion\Tests\Model;
|
namespace Aviat\Ion\Tests\Model;
|
||||||
|
|
||||||
use Aviat\Ion\Model\DB as BaseDBModel;
|
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()
|
public function testBaseDBModelSanity()
|
||||||
{
|
{
|
||||||
|
@ -16,10 +16,10 @@
|
|||||||
|
|
||||||
namespace Aviat\Ion\Tests\Transformer;
|
namespace Aviat\Ion\Tests\Transformer;
|
||||||
|
|
||||||
use Aviat\Ion\Tests\Ion_TestCase;
|
use Aviat\Ion\Tests\IonTestCase;
|
||||||
use Aviat\Ion\Tests\{TestTransformer, TestTransformerUntransform};
|
use Aviat\Ion\Tests\{TestTransformer, TestTransformerUntransform};
|
||||||
|
|
||||||
class AbstractTransformerTest extends Ion_TestCase {
|
class AbstractTransformerTest extends IonTestCase {
|
||||||
|
|
||||||
protected $transformer;
|
protected $transformer;
|
||||||
protected $untransformer;
|
protected $untransformer;
|
||||||
|
@ -17,9 +17,9 @@
|
|||||||
namespace Aviat\Ion\Tests\Type;
|
namespace Aviat\Ion\Tests\Type;
|
||||||
|
|
||||||
use Aviat\Ion\ArrayWrapper;
|
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;
|
use ArrayWrapper;
|
||||||
|
|
||||||
public function setUp(): void {
|
public function setUp(): void {
|
||||||
|
@ -17,9 +17,9 @@
|
|||||||
namespace Aviat\Ion\Tests\Type;
|
namespace Aviat\Ion\Tests\Type;
|
||||||
|
|
||||||
use Aviat\Ion\StringWrapper;
|
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;
|
use StringWrapper;
|
||||||
|
|
||||||
|
|
||||||
|
@ -18,10 +18,10 @@ namespace Aviat\Ion\Tests\View;
|
|||||||
|
|
||||||
use Aviat\Ion\Friend;
|
use Aviat\Ion\Friend;
|
||||||
use Aviat\Ion\Exception\DoubleRenderException;
|
use Aviat\Ion\Exception\DoubleRenderException;
|
||||||
use Aviat\Ion\Tests\Ion_TestCase;
|
use Aviat\Ion\Tests\IonTestCase;
|
||||||
use Aviat\Ion\Tests\TestHttpView;
|
use Aviat\Ion\Tests\TestHttpView;
|
||||||
|
|
||||||
class HttpViewTest extends Ion_TestCase {
|
class HttpViewTest extends IonTestCase {
|
||||||
|
|
||||||
protected $view;
|
protected $view;
|
||||||
protected $friend;
|
protected $friend;
|
||||||
|
@ -15,7 +15,7 @@ if ($timezone === '' || $timezone === FALSE)
|
|||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Composer autoload
|
// Composer autoload
|
||||||
require realpath(__DIR__ . '/../vendor/autoload.php');
|
require realpath(__DIR__ . '/../vendor/autoload.php');
|
||||||
require 'Ion_TestCase.php';
|
require 'IonTestCase.php';
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Ini Settings
|
// Ini Settings
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
use Aura\Html\HelperLocatorFactory;
|
use Aura\Html\HelperLocatorFactory;
|
||||||
use Aura\Session\SessionFactory;
|
use Aura\Session\SessionFactory;
|
||||||
use Zend\Diactoros\ServerRequestFactory;
|
use Laminas\Diactoros\ServerRequestFactory;
|
||||||
use Zend\Diactoros\Response;
|
use Laminas\Diactoros\Response;
|
||||||
|
|
||||||
use Aviat\Ion\Config;
|
use Aviat\Ion\Config;
|
||||||
use Aviat\Ion\Di\Container;
|
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