From ad4b71ac0355ae914afffb38dcaf632c8ec3b716 Mon Sep 17 00:00:00 2001 From: Timothy J Warren Date: Fri, 27 Jan 2017 15:41:52 -0500 Subject: [PATCH] More test coverage, attempt to get Gitlab to see test coverage --- .gitlab-ci.yml | 6 +-- README.md | 1 + composer.json | 5 ++- src/API/JsonAPI.php | 69 ---------------------------------- src/API/Kitsu.php | 4 +- tests/API/CacheTraitTest.php | 28 ++++++++++++++ tests/API/KitsuTest.php | 59 +++++++++++++++++++++++++++++ tests/AnimeClient_TestCase.php | 8 +--- 8 files changed, 99 insertions(+), 81 deletions(-) create mode 100644 tests/API/CacheTraitTest.php create mode 100644 tests/API/KitsuTest.php diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 59d45874..9e6660a9 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -15,7 +15,7 @@ test:7: - php composer.phar install --no-dev image: php:7 script: - - phpunit -c build --coverage-text + - phpunit -c build --coverage-text --colors=never test:7.1: before_script: @@ -24,7 +24,7 @@ test:7.1: - php composer.phar install --no-dev image: php:7.1 script: - - phpunit -c build --coverage-text + - phpunit -c build --coverage-text --colors=never test:hhvm: before_script: @@ -34,4 +34,4 @@ test:hhvm: - composer install --no-dev image: 51systems/docker-gitlab-ci-runner-hhvm script: - - hhvm -d hhvm.php7.all=true /usr/local/bin/phpunit -c build --coverage-text \ No newline at end of file + - hhvm -d hhvm.php7.all=true /usr/local/bin/phpunit -c build --coverage-text --colors=never \ No newline at end of file diff --git a/README.md b/README.md index dfde7c1c..30db60d3 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ 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://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) [[Hosted Example](https://list.timshomepage.net)] diff --git a/composer.json b/composer.json index e35efd48..f6f9d6bf 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,8 @@ "psr/log": "~1.0", "yosymfony/toml": "0.3.*", "zendframework/zend-diactoros": "1.3.*", - "maximebf/consolekit": "^1.0" + "maximebf/consolekit": "^1.0", + "amphp/artax": "^2.0" }, "require-dev": { "pdepend/pdepend": "^2.2", @@ -46,4 +47,4 @@ "build:css": "cd public && npm run build && cd ..", "watch:css": "cd public && npm run watch" } -} \ No newline at end of file +} diff --git a/src/API/JsonAPI.php b/src/API/JsonAPI.php index 1ea85ca2..229aac35 100644 --- a/src/API/JsonAPI.php +++ b/src/API/JsonAPI.php @@ -41,75 +41,6 @@ class JsonAPI { * @var array */ 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 diff --git a/src/API/Kitsu.php b/src/API/Kitsu.php index 98378e5e..34907c90 100644 --- a/src/API/Kitsu.php +++ b/src/API/Kitsu.php @@ -73,7 +73,7 @@ class Kitsu { public static function getAiringStatus(string $startDate = null, string $endDate = null): string { $startAirDate = new DateTimeImmutable($startDate ?? 'tomorrow'); - $endAirDate = new DateTimeImmutable($endDate ?? 'tomorrow'); + $endAirDate = new DateTimeImmutable($endDate ?? 'next year'); $now = new DateTimeImmutable(); $isDoneAiring = $now > $endAirDate; @@ -195,6 +195,8 @@ class Kitsu { return $links; } + + return []; } /** diff --git a/tests/API/CacheTraitTest.php b/tests/API/CacheTraitTest.php new file mode 100644 index 00000000..7f34b8eb --- /dev/null +++ b/tests/API/CacheTraitTest.php @@ -0,0 +1,28 @@ +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); + } +} \ No newline at end of file diff --git a/tests/API/KitsuTest.php b/tests/API/KitsuTest.php new file mode 100644 index 00000000..2d69e8dc --- /dev/null +++ b/tests/API/KitsuTest.php @@ -0,0 +1,59 @@ +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); + } +} \ No newline at end of file diff --git a/tests/AnimeClient_TestCase.php b/tests/AnimeClient_TestCase.php index 76cfc0c3..6e8ab7fa 100644 --- a/tests/AnimeClient_TestCase.php +++ b/tests/AnimeClient_TestCase.php @@ -87,10 +87,6 @@ class AnimeClient_TestCase extends TestCase { '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 */ - 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); }