Version 5.1 - All the GraphQL #32

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

View File

@ -15,7 +15,7 @@ test:7:
- php composer.phar install --no-dev - php composer.phar install --no-dev
image: php:7 image: php:7
script: script:
- phpunit -c build --coverage-text - phpunit -c build --coverage-text --colors=never
test:7.1: test:7.1:
before_script: before_script:
@ -24,7 +24,7 @@ test:7.1:
- php composer.phar install --no-dev - php composer.phar install --no-dev
image: php:7.1 image: php:7.1
script: script:
- phpunit -c build --coverage-text - phpunit -c build --coverage-text --colors=never
test:hhvm: test:hhvm:
before_script: before_script:
@ -34,4 +34,4 @@ test:hhvm:
- composer install --no-dev - composer install --no-dev
image: 51systems/docker-gitlab-ci-runner-hhvm image: 51systems/docker-gitlab-ci-runner-hhvm
script: script:
- hhvm -d hhvm.php7.all=true /usr/local/bin/phpunit -c build --coverage-text - hhvm -d hhvm.php7.all=true /usr/local/bin/phpunit -c build --coverage-text --colors=never

View File

@ -3,6 +3,7 @@
A self-hosted client that allows custom formatting of data from the hummingbird api A self-hosted client that allows custom formatting of data from the hummingbird api
[![Build Status](https://travis-ci.org/timw4mail/HummingBirdAnimeClient.svg?branch=master)](https://travis-ci.org/timw4mail/HummingBirdAnimeClient) [![Build Status](https://travis-ci.org/timw4mail/HummingBirdAnimeClient.svg?branch=master)](https://travis-ci.org/timw4mail/HummingBirdAnimeClient)
[![build status](https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient/badges/develop/build.svg)](https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient/commits/develop)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/timw4mail/HummingBirdAnimeClient/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/timw4mail/HummingBirdAnimeClient/?branch=master) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/timw4mail/HummingBirdAnimeClient/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/timw4mail/HummingBirdAnimeClient/?branch=master)
[[Hosted Example](https://list.timshomepage.net)] [[Hosted Example](https://list.timshomepage.net)]

View File

@ -26,7 +26,8 @@
"psr/log": "~1.0", "psr/log": "~1.0",
"yosymfony/toml": "0.3.*", "yosymfony/toml": "0.3.*",
"zendframework/zend-diactoros": "1.3.*", "zendframework/zend-diactoros": "1.3.*",
"maximebf/consolekit": "^1.0" "maximebf/consolekit": "^1.0",
"amphp/artax": "^2.0"
}, },
"require-dev": { "require-dev": {
"pdepend/pdepend": "^2.2", "pdepend/pdepend": "^2.2",

View File

@ -42,75 +42,6 @@ class JsonAPI {
*/ */
protected $data = []; protected $data = [];
/**
* Data array parsed out from a request
*
* @var array
*/
protected $parsedData = [];
/**
* Related objects included with the request
*
* @var array
*/
public $included = [];
/**
* Pagination links
*
* @var array
*/
protected $links = [];
/**
* JsonAPI constructor
*
* @param array $initital
*/
public function __construct(array $initial = [])
{
$this->data = $initial;
}
public function parseFromString(string $json)
{
$this->parse(Json::decode($json));
}
/**
* Parse a JsonAPI response into its components
*
* @param array $data
*/
public function parse(array $data)
{
$this->included = static::organizeIncludes($data['included']);
}
/**
* Return data array after input is parsed
* to inline includes inside of relationship objects
*
* @return array
*/
public function getParsedData(): array
{
}
/**
* Take inlined included data and inline it into the main object's relationships
*
* @param array $mainObject
* @param array $included
* @return array
*/
public static function inlineIncludedIntoMainObject(array $mainObject, array $included): array
{
$output = clone $mainObject;
}
/** /**
* Take organized includes and inline them, where applicable * Take organized includes and inline them, where applicable
* *

View File

@ -73,7 +73,7 @@ class Kitsu {
public static function getAiringStatus(string $startDate = null, string $endDate = null): string public static function getAiringStatus(string $startDate = null, string $endDate = null): string
{ {
$startAirDate = new DateTimeImmutable($startDate ?? 'tomorrow'); $startAirDate = new DateTimeImmutable($startDate ?? 'tomorrow');
$endAirDate = new DateTimeImmutable($endDate ?? 'tomorrow'); $endAirDate = new DateTimeImmutable($endDate ?? 'next year');
$now = new DateTimeImmutable(); $now = new DateTimeImmutable();
$isDoneAiring = $now > $endAirDate; $isDoneAiring = $now > $endAirDate;
@ -195,6 +195,8 @@ class Kitsu {
return $links; return $links;
} }
return [];
} }
/** /**

View File

@ -0,0 +1,28 @@
<?php declare(strict_types=1);
namespace Aviat\AnimeClient\Tests\API;
use Aviat\AnimeClient\API\CacheTrait;
class CacheTraitTest extends \AnimeClient_TestCase {
public function setUp()
{
parent::setUp();
$this->testClass = new class {
use CacheTrait;
};
}
public function testSetGet()
{
$cachePool = $this->container->get('cache');
$this->testClass->setCache($cachePool);
$this->assertEquals($cachePool, $this->testClass->getCache());
}
public function testGetHashForMethodCall()
{
$hash = $this->testClass->getHashForMethodCall($this, __METHOD__, []);
$this->assertEquals('684ba0a5c29ffec452c5f6a07d2eee6932575490', $hash);
}
}

59
tests/API/KitsuTest.php Normal file
View File

@ -0,0 +1,59 @@
<?php declare(strict_types=1);
namespace Aviat\AnimeClient\Tests\API;
use Aviat\AnimeClient\API\Kitsu;
use Aviat\AnimeClient\API\Kitsu\Enum\{
AnimeAiringStatus,
AnimeWatchingStatus,
MangaReadingStatus
};
use DateTimeImmutable;
use PHPUnit\Framework\TestCase;
class KitsuTest extends TestCase {
public function testGetStatusToSelectMap()
{
$this->assertEquals([
AnimeWatchingStatus::WATCHING => 'Currently Watching',
AnimeWatchingStatus::PLAN_TO_WATCH => 'Plan to Watch',
AnimeWatchingStatus::COMPLETED => 'Completed',
AnimeWatchingStatus::ON_HOLD => 'On Hold',
AnimeWatchingStatus::DROPPED => 'Dropped'
], Kitsu::getStatusToSelectMap());
}
public function testGetStatusToMangaSelectMap()
{
$this->assertEquals([
MangaReadingStatus::READING => 'Currently Reading',
MangaReadingStatus::PLAN_TO_READ => 'Plan to Read',
MangaReadingStatus::COMPLETED => 'Completed',
MangaReadingStatus::ON_HOLD => 'On Hold',
MangaReadingStatus::DROPPED => 'Dropped'
], Kitsu::getStatusToMangaSelectMap());
}
public function testGetAiringStatus()
{
$actual = Kitsu::getAiringStatus('next week', 'next year');
$this->assertEquals(AnimeAiringStatus::NOT_YET_AIRED, $actual);
}
public function testParseStreamingLinksEmpty()
{
$this->assertEquals([], Kitsu::parseStreamingLinks([]));
}
public function testTitleIsUniqueEmpty()
{
$actual = Kitsu::filterTitles([
'canonicalTitle' => 'Foo',
'titles' => [
null,
''
]
]);
$this->assertEquals(['Foo'], $actual);
}
}

View File

@ -87,10 +87,6 @@ class AnimeClient_TestCase extends TestCase {
'routes' => [ 'routes' => [
] ]
],
'redis' => [
'host' => (array_key_exists('REDIS_HOST', $_ENV)) ? $_ENV['REDIS_HOST'] : 'localhost',
'database' => 13
] ]
]; ];
@ -157,9 +153,9 @@ class AnimeClient_TestCase extends TestCase {
* *
* @return mixed - the decoded data * @return mixed - the decoded data
*/ */
public function getMockFileData() public function getMockFileData(...$args)
{ {
$rawData = call_user_func_array([$this, 'getMockFile'], func_get_args()); $rawData = $this->getMockFile(...$args);
return Json::decode($rawData); return Json::decode($rawData);
} }