Version 5.1 - All the GraphQL #32

Closed
timw4mail wants to merge 1160 commits from develop into master
8 changed files with 97 additions and 13 deletions
Showing only changes of commit bfe46fbbd1 - Show all commits

View File

@ -13,6 +13,8 @@
namespace Aviat\AnimeClient;
define('SRC_DIR', realpath(__DIR__ . '/../../'));
/**
* Odds and Ends class
*/
@ -26,7 +28,7 @@ class AnimeClient {
const DEFAULT_CONTROLLER_METHOD = 'index';
const NOT_FOUND_METHOD = 'not_found';
const ERROR_MESSAGE_METHOD = 'error_page';
const SRC_DIR = __DIR__ . '/../../';
const SRC_DIR = SRC_DIR;
private static $form_pages = [
'edit',

View File

@ -203,8 +203,7 @@ class Dispatcher extends RoutingBase {
$default_namespace = AnimeClient::DEFAULT_CONTROLLER_NAMESPACE;
$path = str_replace('\\', '/', $default_namespace);
$path = trim($path, '/');
$actual_path = \_dir(AnimeClient::SRC_DIR, $path);
$actual_path = realpath(\_dir(AnimeClient::SRC_DIR, $path));
$class_files = glob("{$actual_path}/*.php");
$controllers = [];
@ -238,6 +237,10 @@ class Dispatcher extends RoutingBase {
unset($route['path']);
$controller_map = $this->get_controller_list();
$controller_class = (array_key_exists($route_type, $controller_map))
? $controller_map[$route_type]
: AnimeClient::DEFAULT_CONTROLLER;
if (array_key_exists($route_type, $controller_map))
{
$controller_class = $controller_map[$route_type];

View File

@ -128,8 +128,8 @@ class DispatcherTest extends AnimeClient_TestCase {
)
];
$data['manga_default_routing_anime']['config']['routing']['default_list'] = 'manga';
$data['manga_default_routing_manga']['config']['routing']['default_list'] = 'manga';
$data['manga_default_routing_anime']['config']['routes']['route_config']['default_list'] = 'manga';
$data['manga_default_routing_manga']['config']['routes']['route_config']['default_list'] = 'manga';
return $data;
}

View File

@ -6,17 +6,22 @@ use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response;
use Aviat\AnimeClient\AnimeClient;
use Aviat\AnimeClient\Config;
define('ROOT_DIR', __DIR__ . '/../');
define('TEST_DATA_DIR', __DIR__ . '/test_data');
define('TEST_VIEW_DIR', __DIR__ . '/test_views');
/**
* Base class for TestCases
*/
class AnimeClient_TestCase extends PHPUnit_Framework_TestCase {
// Test directory constants
const ROOT_DIR = __DIR__ . '/../';
const SRC_DIR = __DIR__ . '/../src';
const TEST_DATA_DIR = __DIR__ . '/test_data';
const TEST_VIEW_DIR = __DIR__ . '/test_views';
const ROOT_DIR = ROOT_DIR;
const SRC_DIR = AnimeClient::SRC_DIR;
const TEST_DATA_DIR = TEST_DATA_DIR;
const TEST_VIEW_DIR = TEST_VIEW_DIR;
protected $container;
protected static $staticContainer;
@ -30,7 +35,7 @@ class AnimeClient_TestCase extends PHPUnit_Framework_TestCase {
self::$session_handler = $session_handler;
// Remove test cache files
$files = glob(_dir(self::TEST_DATA_DIR, 'cache', '*.json'));
$files = glob(_dir(TEST_DATA_DIR, 'cache', '*.json'));
array_map('unlink', $files);
}
@ -43,8 +48,8 @@ class AnimeClient_TestCase extends PHPUnit_Framework_TestCase {
$config_array = [
'asset_path' => '//localhost/assets/',
'img_cache_path' => _dir(self::ROOT_DIR, 'public/images'),
'data_cache_path' => _dir(self::TEST_DATA_DIR, 'cache'),
'img_cache_path' => _dir(ROOT_DIR, 'public/images'),
'data_cache_path' => _dir(TEST_DATA_DIR, 'cache'),
'database' => [
'collection' => [
'type' => 'sqlite',

68
tests/Ion/JsonTest.php Normal file
View File

@ -0,0 +1,68 @@
<?php
use Aviat\Ion\Json;
use Aviat\Ion\JsonException;
class JsonTest extends AnimeClient_TestCase {
public function testEncode()
{
$data = (object) [
'foo' => [1, 2, 3, 4]
];
$expected = '{"foo":[1,2,3,4]}';
$this->assertEquals($expected, Json::encode($data));
}
public function dataEncodeDecode()
{
return [
'set1' => [
'data' => [
'apple' => [
'sauce' => ['foo','bar','baz']
]
],
'expected_size' => 39,
'expected_json' => '{"apple":{"sauce":["foo","bar","baz"]}}'
]
];
}
/**
* @dataProvider dataEncodeDecode
*/
public function testEncodeDecodeFile($data, $expected_size, $expected_json)
{
$target_file = _dir(self::TEST_DATA_DIR, 'json_write.json');
$actual_size = Json::encodeFile($target_file, $data);
$actual_json = file_get_contents($target_file);
$this->assertTrue(Json::isJson($actual_json));
$this->assertEquals($expected_size, $actual_size);
$this->assertEquals($expected_json, $actual_json);
$this->assertEquals($data, Json::decodeFile($target_file));
unlink($target_file);
}
public function testDecode()
{
$json = '{"foo":[1,2,3,4]}';
$expected = [
'foo' => [1, 2, 3, 4]
];
$this->assertEquals($expected, Json::decode($json));
$this->assertEquals((object)$expected, Json::decode($json, false));
$badJson = '{foo:{1|2}}';
$this->setExpectedException(
'Aviat\Ion\JsonException',
'JSON_ERROR_SYNTAX - Syntax error',
JSON_ERROR_SYNTAX
);
Json::decode($badJson);
}
}

View File

@ -49,7 +49,7 @@ require _dir(__DIR__, '../vendor/autoload.php');
*/
spl_autoload_register(function ($class) {
$class_parts = explode('\\', $class);
$ns_path = AnimeClient_TestCase::SRC_DIR . '/' . implode('/', $class_parts) . ".php";
$ns_path = realpath(__DIR__ . '/../src') . '/' . implode('/', $class_parts) . ".php";
if (file_exists($ns_path))
{

View File

@ -0,0 +1 @@
[}]

View File

@ -0,0 +1,5 @@
[{
"foo": {
"bar": [1,2,3]
}
}]