From b4b5c63d654aaf1e12522423d59e6280ea911312 Mon Sep 17 00:00:00 2001 From: "Timothy J. Warren" Date: Fri, 6 Dec 2019 09:15:49 -0500 Subject: [PATCH] Tweak tests for new version of PHPUnit --- README.md | 2 +- .../Sniffs/Commenting/InlineCommentSniff.php | 4 ++-- build/header_comment.txt | 2 +- build/update_header_comments.php | 2 +- src/API/ParallelAPIRequest.php | 9 ++++---- tests/API/APIRequestBuilderTest.php | 3 +-- tests/API/CacheTraitTest.php | 3 +-- tests/API/JsonAPITest.php | 3 +-- .../Transformer/AnimeListTransformerTest.php | 3 +-- .../Transformer/AnimeTransformerTest.php | 3 +-- .../Transformer/MangaListTransformerTest.php | 3 +-- .../Transformer/MangaTransformerTest.php | 3 +-- ...aListTransformerTest__testTransform__1.yml | 5 +++++ tests/AnimeClientTestCase.php | 9 ++++---- tests/Command/BaseCommandTest.php | 5 ++--- tests/ControllerTest.php | 3 +-- tests/DispatcherTest.php | 21 ++++++++++--------- tests/Helper/MenuHelperTest.php | 5 ++--- tests/MenuGeneratorTest.php | 3 +-- tests/UtilTest.php | 5 ++--- 20 files changed, 46 insertions(+), 50 deletions(-) create mode 100644 tests/API/Kitsu/Transformer/__snapshots__/MangaListTransformerTest__testTransform__1.yml diff --git a/README.md b/README.md index a70a6cd8..2629142b 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ Update your anime/manga list on Kitsu.io and MyAnimeList.net ### Requirements -* PHP 7.1+ +* PHP 7.2+ * PDO SQLite or PDO PostgreSQL (For collection tab) * GD extension for caching images diff --git a/build/CodeIgniter/Sniffs/Commenting/InlineCommentSniff.php b/build/CodeIgniter/Sniffs/Commenting/InlineCommentSniff.php index d8e51eb9..9fb43b0e 100644 --- a/build/CodeIgniter/Sniffs/Commenting/InlineCommentSniff.php +++ b/build/CodeIgniter/Sniffs/Commenting/InlineCommentSniff.php @@ -93,12 +93,12 @@ class InlineCommentSniff implements Sniff private function _checkCommentStyle(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); - if ($tokens[$stackPtr]['content']{0} === '#') { + if ($tokens[$stackPtr]['content'][0] === '#') { $error = 'Perl-style comments are not allowed; use "// Comment" or DocBlock comments instead'; $phpcsFile->addError($error, $stackPtr, 'WrongStyle'); return FALSE; } else if (substr($tokens[$stackPtr]['content'], 0, 2) === '/*' - || $tokens[$stackPtr]['content']{0} === '*' + || $tokens[$stackPtr]['content'][0] === '*' ) { $error = 'Multi lines comments are not allowed; use "// Comment" DocBlock comments instead'; $phpcsFile->addError($error, $stackPtr, 'WrongStyle'); diff --git a/build/header_comment.txt b/build/header_comment.txt index 70638604..ab826ef3 100644 --- a/build/header_comment.txt +++ b/build/header_comment.txt @@ -9,7 +9,7 @@ * @author Timothy J. Warren * @copyright 2015 - 2019 Timothy J. Warren * @license http://www.opensource.org/licenses/mit-license.html MIT License - * @version 4.5 + * @version 4.2 * @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient */ diff --git a/build/update_header_comments.php b/build/update_header_comments.php index 32ec3eb5..58e9c9eb 100644 --- a/build/update_header_comments.php +++ b/build/update_header_comments.php @@ -35,7 +35,7 @@ function get_text_to_replace($tokens) // Tokens have the follow structure if arrays: // [0] => token type constant - // [1] => raw sytax parsed to that token + // [1] => raw syntax parsed to that token // [2] => line number foreach($tokens as $token) { diff --git a/src/API/ParallelAPIRequest.php b/src/API/ParallelAPIRequest.php index 043038e2..5030a0c5 100644 --- a/src/API/ParallelAPIRequest.php +++ b/src/API/ParallelAPIRequest.php @@ -16,6 +16,7 @@ namespace Aviat\AnimeClient\API; +use Amp\Artax\Request; use function Amp\call; use function Amp\Promise\{all, wait}; use function Aviat\AnimeClient\getApiClient; @@ -35,7 +36,7 @@ final class ParallelAPIRequest { /** * Add a request * - * @param string|\Amp\Artax\Request $request + * @param string|Request $request * @param string|number $key * @return self */ @@ -54,7 +55,7 @@ final class ParallelAPIRequest { /** * Add multiple requests * - * @param string[]|\Amp\Artax\Request[] $requests + * @param string[]|Request[] $requests * @return self */ public function addRequests(array $requests): self @@ -77,7 +78,7 @@ final class ParallelAPIRequest { foreach ($this->requests as $key => $url) { - $promises[$key] = call(function () use ($client, $url) { + $promises[$key] = call(static function () use ($client, $url) { $response = yield $client->request($url); return yield $response->getBody(); }); @@ -100,7 +101,7 @@ final class ParallelAPIRequest { foreach ($this->requests as $key => $url) { - $promises[$key] = call(function () use ($client, $url) { + $promises[$key] = call(static function () use ($client, $url) { return yield $client->request($url); }); } diff --git a/tests/API/APIRequestBuilderTest.php b/tests/API/APIRequestBuilderTest.php index 30b3284c..fe0c9924 100644 --- a/tests/API/APIRequestBuilderTest.php +++ b/tests/API/APIRequestBuilderTest.php @@ -28,8 +28,7 @@ class APIRequestBuilderTest extends TestCase { protected $builder; - public function setUp() - { + public function setUp(): void { $this->builder = new class extends APIRequestBuilder { protected $baseUrl = 'https://httpbin.org/'; diff --git a/tests/API/CacheTraitTest.php b/tests/API/CacheTraitTest.php index dede8103..280891fa 100644 --- a/tests/API/CacheTraitTest.php +++ b/tests/API/CacheTraitTest.php @@ -23,8 +23,7 @@ class CacheTraitTest extends AnimeClientTestCase { protected $testClass; - public function setUp() - { + public function setUp(): void { parent::setUp(); $this->testClass = new class { use CacheTrait; diff --git a/tests/API/JsonAPITest.php b/tests/API/JsonAPITest.php index ff67503c..21a0b3b4 100644 --- a/tests/API/JsonAPITest.php +++ b/tests/API/JsonAPITest.php @@ -26,8 +26,7 @@ class JsonAPITest extends TestCase { protected $organizedIncludes; protected $inlineIncluded; - public function setUp() - { + public function setUp(): void { $dir = __DIR__ . '/../test_data/JsonAPI'; $this->startData = Json::decodeFile("{$dir}/jsonApiExample.json"); $this->organizedIncludes = Json::decodeFile("{$dir}/organizedIncludes.json"); diff --git a/tests/API/Kitsu/Transformer/AnimeListTransformerTest.php b/tests/API/Kitsu/Transformer/AnimeListTransformerTest.php index 6cccf48a..0b45a649 100644 --- a/tests/API/Kitsu/Transformer/AnimeListTransformerTest.php +++ b/tests/API/Kitsu/Transformer/AnimeListTransformerTest.php @@ -27,8 +27,7 @@ class AnimeListTransformerTest extends AnimeClientTestCase { protected $afterTransform; protected $transformer; - public function setUp() - { + public function setUp(): void { parent::setUp(); $this->dir = AnimeClientTestCase::TEST_DATA_DIR . '/Kitsu'; diff --git a/tests/API/Kitsu/Transformer/AnimeTransformerTest.php b/tests/API/Kitsu/Transformer/AnimeTransformerTest.php index 1fc599e9..09fffc4a 100644 --- a/tests/API/Kitsu/Transformer/AnimeTransformerTest.php +++ b/tests/API/Kitsu/Transformer/AnimeTransformerTest.php @@ -27,8 +27,7 @@ class AnimeTransformerTest extends AnimeClientTestCase { protected $afterTransform; protected $transformer; - public function setUp() - { + public function setUp(): void { parent::setUp(); $this->dir = AnimeClientTestCase::TEST_DATA_DIR . '/Kitsu'; diff --git a/tests/API/Kitsu/Transformer/MangaListTransformerTest.php b/tests/API/Kitsu/Transformer/MangaListTransformerTest.php index e8d30ca0..8e128b3c 100644 --- a/tests/API/Kitsu/Transformer/MangaListTransformerTest.php +++ b/tests/API/Kitsu/Transformer/MangaListTransformerTest.php @@ -33,8 +33,7 @@ class MangaListTransformerTest extends AnimeClientTestCase { protected $afterTransform; protected $transformer; - public function setUp() - { + public function setUp(): void { parent::setUp(); $kitsuModel = $this->container->get('kitsu-model'); diff --git a/tests/API/Kitsu/Transformer/MangaTransformerTest.php b/tests/API/Kitsu/Transformer/MangaTransformerTest.php index 827f6b0d..6357791d 100644 --- a/tests/API/Kitsu/Transformer/MangaTransformerTest.php +++ b/tests/API/Kitsu/Transformer/MangaTransformerTest.php @@ -28,8 +28,7 @@ class MangaTransformerTest extends AnimeClientTestCase { protected $afterTransform; protected $transformer; - public function setUp() - { + public function setUp(): void { parent::setUp(); $this->dir = AnimeClientTestCase::TEST_DATA_DIR . '/Kitsu'; diff --git a/tests/API/Kitsu/Transformer/__snapshots__/MangaListTransformerTest__testTransform__1.yml b/tests/API/Kitsu/Transformer/__snapshots__/MangaListTransformerTest__testTransform__1.yml new file mode 100644 index 00000000..87effff0 --- /dev/null +++ b/tests/API/Kitsu/Transformer/__snapshots__/MangaListTransformerTest__testTransform__1.yml @@ -0,0 +1,5 @@ +- null +- null +- null +- null +- null diff --git a/tests/AnimeClientTestCase.php b/tests/AnimeClientTestCase.php index 2cddbcf1..4e5b2265 100644 --- a/tests/AnimeClientTestCase.php +++ b/tests/AnimeClientTestCase.php @@ -29,7 +29,7 @@ use Zend\Diactoros\{ ServerRequestFactory }; -\define('ROOT_DIR', __DIR__ . '/../'); +\define('ROOT_DIR', realpath(__DIR__ . '/../')); \define('TEST_DATA_DIR', __DIR__ . '/test_data'); \define('TEST_VIEW_DIR', __DIR__ . '/test_views'); @@ -50,7 +50,7 @@ class AnimeClientTestCase extends TestCase { protected static $staticContainer; protected static $session_handler; - public static function setUpBeforeClass() + public static function setUpBeforeClass(): void { // Use mock session handler //$session_handler = new TestSessionHandler(); @@ -62,7 +62,7 @@ class AnimeClientTestCase extends TestCase { array_map('unlink', $files); } - public function setUp() + public function setUp(): void { parent::setUp(); @@ -139,7 +139,7 @@ class AnimeClientTestCase extends TestCase { array_merge($default, $supers) ); $this->container->setInstance('request', $request); - $this->container->set('response', function() { + $this->container->set('response', static function() { return new HttpResponse(); }); } @@ -165,6 +165,7 @@ class AnimeClientTestCase extends TestCase { * * Takes multiple path arguments * + * @param array $args * @return mixed - the decoded data */ public function getMockFileData(...$args) diff --git a/tests/Command/BaseCommandTest.php b/tests/Command/BaseCommandTest.php index e570d78c..2c9fa3d6 100644 --- a/tests/Command/BaseCommandTest.php +++ b/tests/Command/BaseCommandTest.php @@ -24,9 +24,8 @@ use ConsoleKit\Console; class BaseCommandTest extends AnimeClientTestCase { protected $base; protected $friend; - - public function setUp() - { + + public function setUp(): void { $this->base = new BaseCommand(new Console()); $this->friend = new Friend($this->base); } diff --git a/tests/ControllerTest.php b/tests/ControllerTest.php index e37156c7..cedfb9af 100644 --- a/tests/ControllerTest.php +++ b/tests/ControllerTest.php @@ -31,8 +31,7 @@ class ControllerTest extends AnimeClientTestCase { protected $BaseController; - public function setUp() - { + public function setUp(): void { parent::setUp(); // Create Request/Response Objects diff --git a/tests/DispatcherTest.php b/tests/DispatcherTest.php index 3a7d4b30..3915896b 100644 --- a/tests/DispatcherTest.php +++ b/tests/DispatcherTest.php @@ -16,6 +16,7 @@ namespace Aviat\AnimeClient\Tests; +use Aura\Router\Route; use Aviat\AnimeClient\Controller; use Aviat\AnimeClient\Dispatcher; use Aviat\AnimeClient\UrlGenerator; @@ -31,7 +32,7 @@ class DispatcherTest extends AnimeClientTestCase { protected $config; protected $urlGenerator; - protected function doSetUp($config, $uri, $host) + protected function doSetUp($config, $uri, $host): void { // Set up the environment $_SERVER = array_merge($_SERVER, [ @@ -63,13 +64,13 @@ class DispatcherTest extends AnimeClientTestCase { $this->container->setInstance('url-generator', $this->urlGenerator); } - public function testRouterSanity() + public function testRouterSanity(): void { $this->doSetUp([], '/', 'localhost'); - $this->assertInternalType('object', $this->router); + $this->assertIsObject($this->router); } - public function dataRoute() + public function dataRoute(): array { $defaultConfig = [ 'routes' => [ @@ -142,7 +143,7 @@ class DispatcherTest extends AnimeClientTestCase { /** * @dataProvider dataRoute */ - public function testRoute($config, $controller, $host, $uri) + public function testRoute($config, $controller, $host, $uri): void { $this->doSetUp($config, $uri, $host); @@ -150,7 +151,7 @@ class DispatcherTest extends AnimeClientTestCase { // Check route setup $this->assertEquals($config['routes'], $this->config->get('routes'), 'Incorrect route path'); - $this->assertInternalType('array', $this->router->getOutputRoutes()); + $this->assertIsArray($this->router->getOutputRoutes()); // Check environment variables $this->assertEquals($uri, $request->getServerParams()['REQUEST_URI']); @@ -162,10 +163,10 @@ class DispatcherTest extends AnimeClientTestCase { // Make sure the route matches, by checking that it is actually an object $route = $this->router->getRoute(); - $this->assertInstanceOf(\Aura\Router\Route::class, $route, 'Route is invalid, not matched'); + $this->assertInstanceOf(Route::class, $route, 'Route is invalid, not matched'); } - public function testDefaultRoute() + public function testDefaultRoute(): void { $config = [ 'config' => [ @@ -202,7 +203,7 @@ class DispatcherTest extends AnimeClientTestCase { $this->urlGenerator->defaultUrl('foo'); } - public function dataGetControllerList() + public function dataGetControllerList(): array { $expectedList = [ 'anime' => Controller\Anime::class, @@ -246,7 +247,7 @@ class DispatcherTest extends AnimeClientTestCase { /** * @dataProvider dataGetControllerList */ - public function testGetControllerList($config, $expected) + public function testGetControllerList($config, $expected): void { $this->doSetUp($config, '/', 'localhost'); $this->assertEquals($expected, $this->router->getControllerList()); diff --git a/tests/Helper/MenuHelperTest.php b/tests/Helper/MenuHelperTest.php index 4a549e6f..dd8b5ca3 100644 --- a/tests/Helper/MenuHelperTest.php +++ b/tests/Helper/MenuHelperTest.php @@ -20,12 +20,11 @@ use Aviat\AnimeClient\Helper\Menu as MenuHelper; use Aviat\AnimeClient\Tests\AnimeClientTestCase; class MenuHelperTest extends AnimeClientTestCase { - + protected $helper; protected $urlGenerator; - public function setUp() - { + public function setUp(): void { parent::setUp(); $this->helper = $this->container->get('html-helper'); $this->urlGenerator = $this->container->get('url-generator'); diff --git a/tests/MenuGeneratorTest.php b/tests/MenuGeneratorTest.php index cb93f607..f68fb3ae 100644 --- a/tests/MenuGeneratorTest.php +++ b/tests/MenuGeneratorTest.php @@ -24,8 +24,7 @@ class MenuGeneratorTest extends AnimeClientTestCase { protected $generator; protected $friend; - public function setUp() - { + public function setUp(): void { parent::setUp(); $this->generator = new MenuGenerator($this->container); } diff --git a/tests/UtilTest.php b/tests/UtilTest.php index b742e964..62d85289 100644 --- a/tests/UtilTest.php +++ b/tests/UtilTest.php @@ -19,11 +19,10 @@ namespace Aviat\AnimeClient\Tests; use Aviat\AnimeClient\Util; class UtilTest extends AnimeClientTestCase { - + protected $util; - public function setUp() - { + public function setUp(): void { parent::setUp(); $this->util = new Util($this->container); }