From 4308418414fb3f2c7bebde24370324c1a5c51f59 Mon Sep 17 00:00:00 2001 From: Timothy J Warren Date: Thu, 12 Mar 2020 09:52:45 -0400 Subject: [PATCH] Fix test suite --- src/Ion/View/HttpView.php | 4 +- tests/AnimeClient/AnimeClientTestCase.php | 29 +++++------- tests/AnimeClient/TestSessionHandler.php | 28 ++++++------ tests/Ion/BaseModelTest.php | 2 +- tests/Ion/ConfigTest.php | 2 +- tests/Ion/Di/ContainerAwareTest.php | 4 +- tests/Ion/Di/ContainerTest.php | 4 +- tests/Ion/EnumTest.php | 2 +- .../Exception/DoubleRenderExceptionTest.php | 4 +- tests/Ion/FriendTest.php | 2 +- .../Ion/{Ion_TestCase.php => IonTestCase.php} | 15 +++---- tests/Ion/JsonTest.php | 2 +- tests/Ion/Model/BaseDBModelTest.php | 4 +- .../Transformer/AbstractTransformerTest.php | 4 +- tests/Ion/Type/ArrayTypeTest.php | 4 +- tests/Ion/Type/StringTypeTest.php | 4 +- tests/Ion/View/HttpViewTest.php | 4 +- tests/Ion/bootstrap.php | 2 +- tests/Ion/di.php | 4 +- tests/bootstrap.php | 45 +++++++++++++++++++ 20 files changed, 100 insertions(+), 69 deletions(-) rename tests/Ion/{Ion_TestCase.php => IonTestCase.php} (87%) create mode 100644 tests/bootstrap.php diff --git a/src/Ion/View/HttpView.php b/src/Ion/View/HttpView.php index 15c43a89..ed3f7779 100644 --- a/src/Ion/View/HttpView.php +++ b/src/Ion/View/HttpView.php @@ -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; diff --git a/tests/AnimeClient/AnimeClientTestCase.php b/tests/AnimeClient/AnimeClientTestCase.php index 5b283e4a..c9c6a8a9 100644 --- a/tests/AnimeClient/AnimeClientTestCase.php +++ b/tests/AnimeClient/AnimeClientTestCase.php @@ -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); diff --git a/tests/AnimeClient/TestSessionHandler.php b/tests/AnimeClient/TestSessionHandler.php index 72867dd6..403bcf26 100644 --- a/tests/AnimeClient/TestSessionHandler.php +++ b/tests/AnimeClient/TestSessionHandler.php @@ -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 \ No newline at end of file diff --git a/tests/Ion/BaseModelTest.php b/tests/Ion/BaseModelTest.php index e5e6ea61..0db922ee 100644 --- a/tests/Ion/BaseModelTest.php +++ b/tests/Ion/BaseModelTest.php @@ -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() { diff --git a/tests/Ion/ConfigTest.php b/tests/Ion/ConfigTest.php index f009c575..f9996dbf 100644 --- a/tests/Ion/ConfigTest.php +++ b/tests/Ion/ConfigTest.php @@ -18,7 +18,7 @@ namespace Aviat\Ion\Tests; use Aviat\Ion\Config; -class ConfigTest extends Ion_TestCase { +class ConfigTest extends IonTestCase { protected $config; diff --git a/tests/Ion/Di/ContainerAwareTest.php b/tests/Ion/Di/ContainerAwareTest.php index 89236807..9f0ef39b 100644 --- a/tests/Ion/Di/ContainerAwareTest.php +++ b/tests/Ion/Di/ContainerAwareTest.php @@ -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; diff --git a/tests/Ion/Di/ContainerTest.php b/tests/Ion/Di/ContainerTest.php index ac73416d..0e352854 100644 --- a/tests/Ion/Di/ContainerTest.php +++ b/tests/Ion/Di/ContainerTest.php @@ -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 { diff --git a/tests/Ion/EnumTest.php b/tests/Ion/EnumTest.php index 6254e938..7c297cc3 100644 --- a/tests/Ion/EnumTest.php +++ b/tests/Ion/EnumTest.php @@ -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', diff --git a/tests/Ion/Exception/DoubleRenderExceptionTest.php b/tests/Ion/Exception/DoubleRenderExceptionTest.php index 4be0ba5d..2d70a8f9 100644 --- a/tests/Ion/Exception/DoubleRenderExceptionTest.php +++ b/tests/Ion/Exception/DoubleRenderExceptionTest.php @@ -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() { diff --git a/tests/Ion/FriendTest.php b/tests/Ion/FriendTest.php index 861f175a..d91b6cec 100644 --- a/tests/Ion/FriendTest.php +++ b/tests/Ion/FriendTest.php @@ -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(); diff --git a/tests/Ion/Ion_TestCase.php b/tests/Ion/IonTestCase.php similarity index 87% rename from tests/Ion/Ion_TestCase.php rename to tests/Ion/IonTestCase.php index 7b80da12..587ee9a1 100644 --- a/tests/Ion/Ion_TestCase.php +++ b/tests/Ion/IonTestCase.php @@ -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 \ No newline at end of file +// End of IonTestCase.php \ No newline at end of file diff --git a/tests/Ion/JsonTest.php b/tests/Ion/JsonTest.php index cc45dcf7..5d48b123 100644 --- a/tests/Ion/JsonTest.php +++ b/tests/Ion/JsonTest.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() { diff --git a/tests/Ion/Model/BaseDBModelTest.php b/tests/Ion/Model/BaseDBModelTest.php index f72ede4b..6b2f6577 100644 --- a/tests/Ion/Model/BaseDBModelTest.php +++ b/tests/Ion/Model/BaseDBModelTest.php @@ -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() { diff --git a/tests/Ion/Transformer/AbstractTransformerTest.php b/tests/Ion/Transformer/AbstractTransformerTest.php index 0e6adf97..a0c8bb6d 100644 --- a/tests/Ion/Transformer/AbstractTransformerTest.php +++ b/tests/Ion/Transformer/AbstractTransformerTest.php @@ -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; diff --git a/tests/Ion/Type/ArrayTypeTest.php b/tests/Ion/Type/ArrayTypeTest.php index fbbc96da..db49cc33 100644 --- a/tests/Ion/Type/ArrayTypeTest.php +++ b/tests/Ion/Type/ArrayTypeTest.php @@ -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 { diff --git a/tests/Ion/Type/StringTypeTest.php b/tests/Ion/Type/StringTypeTest.php index 4872108b..14b01066 100644 --- a/tests/Ion/Type/StringTypeTest.php +++ b/tests/Ion/Type/StringTypeTest.php @@ -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; diff --git a/tests/Ion/View/HttpViewTest.php b/tests/Ion/View/HttpViewTest.php index 8305e9b2..4a9090eb 100644 --- a/tests/Ion/View/HttpViewTest.php +++ b/tests/Ion/View/HttpViewTest.php @@ -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; diff --git a/tests/Ion/bootstrap.php b/tests/Ion/bootstrap.php index 5cd54140..8e802ad7 100644 --- a/tests/Ion/bootstrap.php +++ b/tests/Ion/bootstrap.php @@ -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 diff --git a/tests/Ion/di.php b/tests/Ion/di.php index b0c65b8e..13caf6f0 100644 --- a/tests/Ion/di.php +++ b/tests/Ion/di.php @@ -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; diff --git a/tests/bootstrap.php b/tests/bootstrap.php new file mode 100644 index 00000000..f7f942a0 --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,45 @@ +