Tweak tests for new version of PHPUnit

This commit is contained in:
Timothy Warren 2019-12-06 09:15:49 -05:00
parent 47b9d7ba7a
commit 6fd2b22d72
20 changed files with 46 additions and 50 deletions

View File

@ -31,7 +31,7 @@ Update your anime/manga list on Kitsu.io and MyAnimeList.net
### Requirements ### Requirements
* PHP 7.1+ * PHP 7.2+
* PDO SQLite or PDO PostgreSQL (For collection tab) * PDO SQLite or PDO PostgreSQL (For collection tab)
* GD extension for caching images * GD extension for caching images

View File

@ -93,12 +93,12 @@ class InlineCommentSniff implements Sniff
private function _checkCommentStyle(File $phpcsFile, $stackPtr) private function _checkCommentStyle(File $phpcsFile, $stackPtr)
{ {
$tokens = $phpcsFile->getTokens(); $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'; $error = 'Perl-style comments are not allowed; use "// Comment" or DocBlock comments instead';
$phpcsFile->addError($error, $stackPtr, 'WrongStyle'); $phpcsFile->addError($error, $stackPtr, 'WrongStyle');
return FALSE; return FALSE;
} else if (substr($tokens[$stackPtr]['content'], 0, 2) === '/*' } 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'; $error = 'Multi lines comments are not allowed; use "// Comment" DocBlock comments instead';
$phpcsFile->addError($error, $stackPtr, 'WrongStyle'); $phpcsFile->addError($error, $stackPtr, 'WrongStyle');

View File

@ -9,7 +9,7 @@
* @author Timothy J. Warren <tim@timshomepage.net> * @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2019 Timothy J. Warren * @copyright 2015 - 2019 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License * @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.5 * @version 4.2
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient * @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/ */

View File

@ -35,7 +35,7 @@ function get_text_to_replace($tokens)
// Tokens have the follow structure if arrays: // Tokens have the follow structure if arrays:
// [0] => token type constant // [0] => token type constant
// [1] => raw sytax parsed to that token // [1] => raw syntax parsed to that token
// [2] => line number // [2] => line number
foreach($tokens as $token) foreach($tokens as $token)
{ {

View File

@ -16,6 +16,7 @@
namespace Aviat\AnimeClient\API; namespace Aviat\AnimeClient\API;
use Amp\Artax\Request;
use function Amp\call; use function Amp\call;
use function Amp\Promise\{all, wait}; use function Amp\Promise\{all, wait};
use function Aviat\AnimeClient\getApiClient; use function Aviat\AnimeClient\getApiClient;
@ -35,7 +36,7 @@ final class ParallelAPIRequest {
/** /**
* Add a request * Add a request
* *
* @param string|\Amp\Artax\Request $request * @param string|Request $request
* @param string|number $key * @param string|number $key
* @return self * @return self
*/ */
@ -54,7 +55,7 @@ final class ParallelAPIRequest {
/** /**
* Add multiple requests * Add multiple requests
* *
* @param string[]|\Amp\Artax\Request[] $requests * @param string[]|Request[] $requests
* @return self * @return self
*/ */
public function addRequests(array $requests): self public function addRequests(array $requests): self
@ -77,7 +78,7 @@ final class ParallelAPIRequest {
foreach ($this->requests as $key => $url) 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); $response = yield $client->request($url);
return yield $response->getBody(); return yield $response->getBody();
}); });
@ -100,7 +101,7 @@ final class ParallelAPIRequest {
foreach ($this->requests as $key => $url) 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); return yield $client->request($url);
}); });
} }

View File

@ -28,8 +28,7 @@ class APIRequestBuilderTest extends TestCase {
protected $builder; protected $builder;
public function setUp() public function setUp(): void {
{
$this->builder = new class extends APIRequestBuilder { $this->builder = new class extends APIRequestBuilder {
protected $baseUrl = 'https://httpbin.org/'; protected $baseUrl = 'https://httpbin.org/';

View File

@ -23,8 +23,7 @@ class CacheTraitTest extends AnimeClientTestCase {
protected $testClass; protected $testClass;
public function setUp() public function setUp(): void {
{
parent::setUp(); parent::setUp();
$this->testClass = new class { $this->testClass = new class {
use CacheTrait; use CacheTrait;

View File

@ -26,8 +26,7 @@ class JsonAPITest extends TestCase {
protected $organizedIncludes; protected $organizedIncludes;
protected $inlineIncluded; protected $inlineIncluded;
public function setUp() public function setUp(): void {
{
$dir = __DIR__ . '/../test_data/JsonAPI'; $dir = __DIR__ . '/../test_data/JsonAPI';
$this->startData = Json::decodeFile("{$dir}/jsonApiExample.json"); $this->startData = Json::decodeFile("{$dir}/jsonApiExample.json");
$this->organizedIncludes = Json::decodeFile("{$dir}/organizedIncludes.json"); $this->organizedIncludes = Json::decodeFile("{$dir}/organizedIncludes.json");

View File

@ -27,8 +27,7 @@ class AnimeListTransformerTest extends AnimeClientTestCase {
protected $afterTransform; protected $afterTransform;
protected $transformer; protected $transformer;
public function setUp() public function setUp(): void {
{
parent::setUp(); parent::setUp();
$this->dir = AnimeClientTestCase::TEST_DATA_DIR . '/Kitsu'; $this->dir = AnimeClientTestCase::TEST_DATA_DIR . '/Kitsu';

View File

@ -27,8 +27,7 @@ class AnimeTransformerTest extends AnimeClientTestCase {
protected $afterTransform; protected $afterTransform;
protected $transformer; protected $transformer;
public function setUp() public function setUp(): void {
{
parent::setUp(); parent::setUp();
$this->dir = AnimeClientTestCase::TEST_DATA_DIR . '/Kitsu'; $this->dir = AnimeClientTestCase::TEST_DATA_DIR . '/Kitsu';

View File

@ -33,8 +33,7 @@ class MangaListTransformerTest extends AnimeClientTestCase {
protected $afterTransform; protected $afterTransform;
protected $transformer; protected $transformer;
public function setUp() public function setUp(): void {
{
parent::setUp(); parent::setUp();
$kitsuModel = $this->container->get('kitsu-model'); $kitsuModel = $this->container->get('kitsu-model');

View File

@ -28,8 +28,7 @@ class MangaTransformerTest extends AnimeClientTestCase {
protected $afterTransform; protected $afterTransform;
protected $transformer; protected $transformer;
public function setUp() public function setUp(): void {
{
parent::setUp(); parent::setUp();
$this->dir = AnimeClientTestCase::TEST_DATA_DIR . '/Kitsu'; $this->dir = AnimeClientTestCase::TEST_DATA_DIR . '/Kitsu';

View File

@ -0,0 +1,5 @@
- null
- null
- null
- null
- null

View File

@ -29,7 +29,7 @@ use Zend\Diactoros\{
ServerRequestFactory ServerRequestFactory
}; };
\define('ROOT_DIR', __DIR__ . '/../'); \define('ROOT_DIR', realpath(__DIR__ . '/../'));
\define('TEST_DATA_DIR', __DIR__ . '/test_data'); \define('TEST_DATA_DIR', __DIR__ . '/test_data');
\define('TEST_VIEW_DIR', __DIR__ . '/test_views'); \define('TEST_VIEW_DIR', __DIR__ . '/test_views');
@ -50,7 +50,7 @@ class AnimeClientTestCase extends TestCase {
protected static $staticContainer; protected static $staticContainer;
protected static $session_handler; protected static $session_handler;
public static function setUpBeforeClass() public static function setUpBeforeClass(): void
{ {
// Use mock session handler // Use mock session handler
//$session_handler = new TestSessionHandler(); //$session_handler = new TestSessionHandler();
@ -62,7 +62,7 @@ class AnimeClientTestCase extends TestCase {
array_map('unlink', $files); array_map('unlink', $files);
} }
public function setUp() public function setUp(): void
{ {
parent::setUp(); parent::setUp();
@ -139,7 +139,7 @@ class AnimeClientTestCase extends TestCase {
array_merge($default, $supers) array_merge($default, $supers)
); );
$this->container->setInstance('request', $request); $this->container->setInstance('request', $request);
$this->container->set('response', function() { $this->container->set('response', static function() {
return new HttpResponse(); return new HttpResponse();
}); });
} }
@ -165,6 +165,7 @@ class AnimeClientTestCase extends TestCase {
* *
* Takes multiple path arguments * Takes multiple path arguments
* *
* @param array $args
* @return mixed - the decoded data * @return mixed - the decoded data
*/ */
public function getMockFileData(...$args) public function getMockFileData(...$args)

View File

@ -24,9 +24,8 @@ use ConsoleKit\Console;
class BaseCommandTest extends AnimeClientTestCase { class BaseCommandTest extends AnimeClientTestCase {
protected $base; protected $base;
protected $friend; protected $friend;
public function setUp() public function setUp(): void {
{
$this->base = new BaseCommand(new Console()); $this->base = new BaseCommand(new Console());
$this->friend = new Friend($this->base); $this->friend = new Friend($this->base);
} }

View File

@ -31,8 +31,7 @@ class ControllerTest extends AnimeClientTestCase {
protected $BaseController; protected $BaseController;
public function setUp() public function setUp(): void {
{
parent::setUp(); parent::setUp();
// Create Request/Response Objects // Create Request/Response Objects

View File

@ -16,6 +16,7 @@
namespace Aviat\AnimeClient\Tests; namespace Aviat\AnimeClient\Tests;
use Aura\Router\Route;
use Aviat\AnimeClient\Controller; use Aviat\AnimeClient\Controller;
use Aviat\AnimeClient\Dispatcher; use Aviat\AnimeClient\Dispatcher;
use Aviat\AnimeClient\UrlGenerator; use Aviat\AnimeClient\UrlGenerator;
@ -31,7 +32,7 @@ class DispatcherTest extends AnimeClientTestCase {
protected $config; protected $config;
protected $urlGenerator; protected $urlGenerator;
protected function doSetUp($config, $uri, $host) protected function doSetUp($config, $uri, $host): void
{ {
// Set up the environment // Set up the environment
$_SERVER = array_merge($_SERVER, [ $_SERVER = array_merge($_SERVER, [
@ -63,13 +64,13 @@ class DispatcherTest extends AnimeClientTestCase {
$this->container->setInstance('url-generator', $this->urlGenerator); $this->container->setInstance('url-generator', $this->urlGenerator);
} }
public function testRouterSanity() public function testRouterSanity(): void
{ {
$this->doSetUp([], '/', 'localhost'); $this->doSetUp([], '/', 'localhost');
$this->assertInternalType('object', $this->router); $this->assertIsObject($this->router);
} }
public function dataRoute() public function dataRoute(): array
{ {
$defaultConfig = [ $defaultConfig = [
'routes' => [ 'routes' => [
@ -142,7 +143,7 @@ class DispatcherTest extends AnimeClientTestCase {
/** /**
* @dataProvider dataRoute * @dataProvider dataRoute
*/ */
public function testRoute($config, $controller, $host, $uri) public function testRoute($config, $controller, $host, $uri): void
{ {
$this->doSetUp($config, $uri, $host); $this->doSetUp($config, $uri, $host);
@ -150,7 +151,7 @@ class DispatcherTest extends AnimeClientTestCase {
// Check route setup // Check route setup
$this->assertEquals($config['routes'], $this->config->get('routes'), 'Incorrect route path'); $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 // Check environment variables
$this->assertEquals($uri, $request->getServerParams()['REQUEST_URI']); $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 // Make sure the route matches, by checking that it is actually an object
$route = $this->router->getRoute(); $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 = [
'config' => [ 'config' => [
@ -202,7 +203,7 @@ class DispatcherTest extends AnimeClientTestCase {
$this->urlGenerator->defaultUrl('foo'); $this->urlGenerator->defaultUrl('foo');
} }
public function dataGetControllerList() public function dataGetControllerList(): array
{ {
$expectedList = [ $expectedList = [
'anime' => Controller\Anime::class, 'anime' => Controller\Anime::class,
@ -246,7 +247,7 @@ class DispatcherTest extends AnimeClientTestCase {
/** /**
* @dataProvider dataGetControllerList * @dataProvider dataGetControllerList
*/ */
public function testGetControllerList($config, $expected) public function testGetControllerList($config, $expected): void
{ {
$this->doSetUp($config, '/', 'localhost'); $this->doSetUp($config, '/', 'localhost');
$this->assertEquals($expected, $this->router->getControllerList()); $this->assertEquals($expected, $this->router->getControllerList());

View File

@ -20,12 +20,11 @@ use Aviat\AnimeClient\Helper\Menu as MenuHelper;
use Aviat\AnimeClient\Tests\AnimeClientTestCase; use Aviat\AnimeClient\Tests\AnimeClientTestCase;
class MenuHelperTest extends AnimeClientTestCase { class MenuHelperTest extends AnimeClientTestCase {
protected $helper; protected $helper;
protected $urlGenerator; protected $urlGenerator;
public function setUp() public function setUp(): void {
{
parent::setUp(); parent::setUp();
$this->helper = $this->container->get('html-helper'); $this->helper = $this->container->get('html-helper');
$this->urlGenerator = $this->container->get('url-generator'); $this->urlGenerator = $this->container->get('url-generator');

View File

@ -24,8 +24,7 @@ class MenuGeneratorTest extends AnimeClientTestCase {
protected $generator; protected $generator;
protected $friend; protected $friend;
public function setUp() public function setUp(): void {
{
parent::setUp(); parent::setUp();
$this->generator = new MenuGenerator($this->container); $this->generator = new MenuGenerator($this->container);
} }

View File

@ -19,11 +19,10 @@ namespace Aviat\AnimeClient\Tests;
use Aviat\AnimeClient\Util; use Aviat\AnimeClient\Util;
class UtilTest extends AnimeClientTestCase { class UtilTest extends AnimeClientTestCase {
protected $util; protected $util;
public function setUp() public function setUp(): void {
{
parent::setUp(); parent::setUp();
$this->util = new Util($this->container); $this->util = new Util($this->container);
} }