Fix test suite
Some checks failed
timw4mail/HummingBirdAnimeClient/pipeline/head There was a failure building this commit

This commit is contained in:
Timothy Warren 2020-03-12 09:52:45 -04:00
parent 52fc6d8391
commit 4308418414
20 changed files with 100 additions and 69 deletions

View File

@ -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;

View File

@ -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);

View File

@ -17,16 +17,16 @@
namespace Aviat\AnimeClient\Tests;
class TestSessionHandler implements \SessionHandlerInterface {
public $data = [];
public $savePath = './test_data/sessions';
public function close()
public function close()
{
return TRUE;
}
public function destroy($id)
public function destroy($id)
{
$file = "$this->savePath/$id";
if (file_exists($file))
@ -36,13 +36,13 @@ class TestSessionHandler implements \SessionHandlerInterface {
$this->data[$id] = [];
return TRUE;
}
public function gc($maxLifetime)
{
return TRUE;
}
public function open($savePath, $name)
public function open($savePath, $name)
{
/*if ( ! array_key_exists($savePath, $this->data))
{
@ -51,19 +51,19 @@ class TestSessionHandler implements \SessionHandlerInterface {
}*/
return TRUE;
}
public function read($id)
public function read($id)
{
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_put_contents($file, json_encode($data));
return TRUE;
}
}
// End of TestSessionHandler.php

View File

@ -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()
{

View File

@ -18,7 +18,7 @@ namespace Aviat\Ion\Tests;
use Aviat\Ion\Config;
class ConfigTest extends Ion_TestCase {
class ConfigTest extends IonTestCase {
protected $config;

View File

@ -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;

View File

@ -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
{

View File

@ -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',

View File

@ -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()
{

View File

@ -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();

View File

@ -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

View File

@ -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()
{

View File

@ -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()
{

View File

@ -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;

View File

@ -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 {

View File

@ -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;

View File

@ -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;

View File

@ -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

View File

@ -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
View 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