Fix tests for PHP8...?

This commit is contained in:
Timothy Warren 2020-12-11 14:26:54 -05:00
parent 9d82154b2f
commit dee4a2dad5
22 changed files with 58 additions and 76 deletions

View File

@ -67,7 +67,7 @@ return static function (array $configArray = []): Container {
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
// Create Config Object // Create Config Object
$container->set('config', fn () => new Config($configArray)); $container->set('config', static fn () => new Config($configArray));
// Create Cache Object // Create Cache Object
$container->set('cache', static function(ContainerInterface $container): CacheInterface { $container->set('cache', static function(ContainerInterface $container): CacheInterface {
@ -77,7 +77,7 @@ return static function (array $configArray = []): Container {
}); });
// Create Aura Router Object // Create Aura Router Object
$container->set('aura-router', fn() => new RouterContainer); $container->set('aura-router', static fn() => new RouterContainer);
// Create Html helpers // Create Html helpers
$container->set('html-helper', static function(ContainerInterface $container) { $container->set('html-helper', static function(ContainerInterface $container) {
@ -125,8 +125,8 @@ return static function (array $configArray = []): Container {
}); });
// Create Request Object // Create Request Object
$container->set('request', fn () => ServerRequestFactory::fromGlobals( $container->set('request', static fn () => ServerRequestFactory::fromGlobals(
$_SERVER, $GLOBALS['_SERVER'],
$_GET, $_GET,
$_POST, $_POST,
$_COOKIE, $_COOKIE,
@ -134,10 +134,10 @@ return static function (array $configArray = []): Container {
)); ));
// Create session Object // Create session Object
$container->set('session', fn () => (new SessionFactory())->newInstance($_COOKIE)); $container->set('session', static fn () => (new SessionFactory())->newInstance($_COOKIE));
// Miscellaneous helper methods // Miscellaneous helper methods
$container->set('util', fn ($container) => new Util($container)); $container->set('util', static fn ($container) => new Util($container));
// Models // Models
$container->set('kitsu-model', static function(ContainerInterface $container): Kitsu\Model { $container->set('kitsu-model', static function(ContainerInterface $container): Kitsu\Model {
@ -170,10 +170,10 @@ return static function (array $configArray = []): Container {
return $model; return $model;
}); });
$container->set('anime-model', fn ($container) => new Model\Anime($container)); $container->set('anime-model', static fn ($container) => new Model\Anime($container));
$container->set('manga-model', fn ($container) => new Model\Manga($container)); $container->set('manga-model', static fn ($container) => new Model\Manga($container));
$container->set('anime-collection-model', fn ($container) => new Model\AnimeCollection($container)); $container->set('anime-collection-model', static fn ($container) => new Model\AnimeCollection($container));
$container->set('manga-collection-model', fn ($container) => new Model\MangaCollection($container)); $container->set('manga-collection-model', static fn ($container) => new Model\MangaCollection($container));
$container->set('settings-model', static function($container) { $container->set('settings-model', static function($container) {
$model = new Model\Settings($container->get('config')); $model = new Model\Settings($container->get('config'));
$model->setContainer($container); $model->setContainer($container);
@ -181,13 +181,13 @@ return static function (array $configArray = []): Container {
}); });
// Miscellaneous Classes // Miscellaneous Classes
$container->set('auth', fn ($container) => new Kitsu\Auth($container)); $container->set('auth', static fn ($container) => new Kitsu\Auth($container));
$container->set('url-generator', fn ($container) => new UrlGenerator($container)); $container->set('url-generator', static fn ($container) => new UrlGenerator($container));
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
// Dispatcher // Dispatcher
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
$container->set('dispatcher', fn ($container) => new Dispatcher($container)); $container->set('dispatcher', static fn ($container) => new Dispatcher($container));
return $container; return $container;
}; };

View File

@ -5,8 +5,8 @@ namespace Aviat\AnimeClient;
$whose = $config->get('whose_list') . "'s "; $whose = $config->get('whose_list') . "'s ";
$lastSegment = $urlGenerator->lastSegment(); $lastSegment = $urlGenerator->lastSegment();
$extraSegment = $lastSegment === 'list' ? '/list' : ''; $extraSegment = $lastSegment === 'list' ? '/list' : '';
$hasAnime = stripos($_SERVER['REQUEST_URI'], 'anime') !== FALSE; $hasAnime = stripos($GLOBALS['_SERVER']['REQUEST_URI'], 'anime') !== FALSE;
$hasManga = stripos($_SERVER['REQUEST_URI'], 'manga') !== FALSE; $hasManga = stripos($GLOBALS['_SERVER']['REQUEST_URI'], 'manga') !== FALSE;
?> ?>
<div id="main-nav" class="flex flex-align-end flex-wrap"> <div id="main-nav" class="flex flex-align-end flex-wrap">
@ -84,7 +84,7 @@ $hasManga = stripos($_SERVER['REQUEST_URI'], 'manga') !== FALSE;
<?php if ($container->get('util')->isViewPage() && ($hasAnime || $hasManga)): ?> <?php if ($container->get('util')->isViewPage() && ($hasAnime || $hasManga)): ?>
<nav> <nav>
<?= $helper->menu($menu_name) ?> <?= $helper->menu($menu_name) ?>
<?php if (stripos($_SERVER['REQUEST_URI'], 'history') === FALSE): ?> <?php if (stripos($GLOBALS['_SERVER']['REQUEST_URI'], 'history') === FALSE): ?>
<br /> <br />
<ul> <ul>
<?php $currentView = Util::eq('list', $lastSegment) ? 'list' : 'cover' ?> <?php $currentView = Util::eq('list', $lastSegment) ? 'list' : 'cover' ?>

View File

@ -49,11 +49,11 @@
"ext-gd": "*", "ext-gd": "*",
"ext-pdo": "*", "ext-pdo": "*",
"filp/whoops": "^2.1", "filp/whoops": "^2.1",
"laminas/laminas-diactoros": "^2.2.3", "laminas/laminas-diactoros": "^2.5.0",
"laminas/laminas-httphandlerrunner": "^1.1.0", "laminas/laminas-httphandlerrunner": "^1.1.0",
"maximebf/consolekit": "^1.0.3", "maximebf/consolekit": "^1.0.3",
"monolog/monolog": "^2.0.2", "monolog/monolog": "^2.0.2",
"php": ">=7.4", "php": "^7.4 || ~8.0.0",
"psr/container": "^1.0.0", "psr/container": "^1.0.0",
"psr/http-message": "^1.0.1", "psr/http-message": "^1.0.1",
"psr/log": "^1.1.3", "psr/log": "^1.1.3",

View File

@ -7,7 +7,7 @@ require_once __DIR__ . '/vendor/autoload.php';
use Aviat\AnimeClient\Command; use Aviat\AnimeClient\Command;
use ConsoleKit\Console; use ConsoleKit\Console;
$_SERVER['HTTP_HOST'] = 'localhost'; $GLOBALS['_SERVER']['HTTP_HOST'] = 'localhost';
define('APP_DIR', __DIR__ . '/app'); define('APP_DIR', __DIR__ . '/app');
define('TEMPLATE_DIR', APP_DIR . '/templates'); define('TEMPLATE_DIR', APP_DIR . '/templates');

View File

@ -1,6 +1,6 @@
<?php <?php
$verb = strtolower($_SERVER['REQUEST_METHOD']); $verb = strtolower($GLOBALS['_SERVER']['REQUEST_METHOD']);
// Send request method if nothing else is specified // Send request method if nothing else is specified
if (empty($_GET)) if (empty($_GET))

View File

@ -7,7 +7,10 @@
</coverage> </coverage>
<testsuites> <testsuites>
<testsuite name="AnimeClient"> <testsuite name="AnimeClient">
<directory>tests</directory> <directory>tests/AnimeClient</directory>
</testsuite>
<testsuite name="Ion">
<directory>tests/Ion</directory>
</testsuite> </testsuite>
</testsuites> </testsuites>
<php> <php>

View File

@ -168,7 +168,7 @@ abstract class BaseCommand extends Command {
// Create Request/Response Objects // Create Request/Response Objects
$container->set('request', fn () => ServerRequestFactory::fromGlobals( $container->set('request', fn () => ServerRequestFactory::fromGlobals(
$_SERVER, $GLOBALS['_SERVER'],
$_GET, $_GET,
$_POST, $_POST,
$_COOKIE, $_COOKIE,

View File

@ -54,7 +54,7 @@ final class FormGenerator {
{ {
try try
{ {
return new static($container); return new self($container);
} }
catch (\Throwable $e) catch (\Throwable $e)
{ {
@ -74,7 +74,7 @@ final class FormGenerator {
{ {
$type = $form['type']; $type = $form['type'];
$display = $form['display'] ?? TRUE; $display = $form['display'] ?? TRUE;
$value = $form['value'] ?? ''; $value = $form['value'] ?? $form['default'] ?? '';
if ($display === FALSE) if ($display === FALSE)
{ {
@ -101,6 +101,7 @@ final class FormGenerator {
'1' => 'Yes', '1' => 'Yes',
'0' => 'No', '0' => 'No',
]; ];
$params['strict'] = true;
unset($params['attribs']['id']); unset($params['attribs']['id']);
break; break;

View File

@ -35,13 +35,7 @@ class Config extends AbstractType {
public ?string $asset_path; // Path to public folder for urls public ?string $asset_path; // Path to public folder for urls
/** /**
* @deprecated Use 'theme' instead * The PHP timezone
* @var bool
*/
public $dark_theme; /* Deprecated */
/**
* @var string The PHP timezone
*/ */
public string $timezone = ''; public string $timezone = '';
@ -73,16 +67,22 @@ class Config extends AbstractType {
public bool $secure_urls = TRUE; public bool $secure_urls = TRUE;
public bool $show_anime_collection = FALSE; /**
* @var string|bool
*/
public $show_anime_collection = FALSE;
public bool $show_manga_collection = FALSE; /**
* @var string|bool
*/
public $show_manga_collection = FALSE;
/** /**
* CSS theme: light, dark, or auto-switching * CSS theme: light, dark, or auto-switching
* *
* @var 'auto' | 'light' | 'dark' * @var 'auto' | 'light' | 'dark'
*/ */
public ?string $theme; public ?string $theme = 'auto';
public ?string $whose_list; public ?string $whose_list;

View File

@ -27,7 +27,10 @@ class Anilist extends AbstractType {
public ?string $access_token; public ?string $access_token;
public ?int $access_token_expires; /**
* @var int|string|null
*/
public $access_token_expires;
public ?string $refresh_token; public ?string $refresh_token;

View File

@ -19,9 +19,6 @@ namespace Aviat\AnimeClient\Types\Config;
use Aviat\AnimeClient\Types\AbstractType; use Aviat\AnimeClient\Types\AbstractType;
class Cache extends AbstractType { class Cache extends AbstractType {
/**
* @var string
*/
public string $driver = 'null'; public string $driver = 'null';
public ?string $host; public ?string $host;
@ -33,13 +30,7 @@ class Cache extends AbstractType {
public ?string $database; public ?string $database;
/**
* @var array
*/
public array $connection = []; public array $connection = [];
/** public ?array $options;
* @var array
*/
public array $options = [];
} }

View File

@ -116,7 +116,7 @@ class AnimeClientTestCase extends TestCase {
public function setSuperGlobals($supers = []): void public function setSuperGlobals($supers = []): void
{ {
$default = [ $default = [
'_SERVER' => $_SERVER, '_SERVER' => $GLOBALS['_SERVER'],
'_GET' => $_GET, '_GET' => $_GET,
'_POST' => $_POST, '_POST' => $_POST,
'_COOKIE' => $_COOKIE, '_COOKIE' => $_COOKIE,
@ -125,7 +125,7 @@ class AnimeClientTestCase extends TestCase {
$request = \call_user_func_array( $request = \call_user_func_array(
[ServerRequestFactory::class, 'fromGlobals'], [ServerRequestFactory::class, 'fromGlobals'],
array_merge($default, $supers) array_values(array_merge($default, $supers)),
); );
$this->container->setInstance('request', $request); $this->container->setInstance('request', $request);
$this->container->set('response', static function() { $this->container->set('response', static function() {

View File

@ -35,12 +35,12 @@ class ControllerTest extends AnimeClientTestCase {
parent::setUp(); parent::setUp();
// Create Request/Response Objects // Create Request/Response Objects
$_SERVER['HTTP_REFERER'] = ''; $GLOBALS['_SERVER']['HTTP_REFERER'] = '';
$this->setSuperGlobals([ $this->setSuperGlobals([
'_GET' => [], '_GET' => [],
'_POST' => [], '_POST' => [],
'_COOKIE' => [], '_COOKIE' => [],
'_SERVER' => $_SERVER, '_SERVER' => $GLOBALS['_SERVER'],
'_FILES' => [] '_FILES' => []
]); ]);

View File

@ -35,7 +35,7 @@ class DispatcherTest extends AnimeClientTestCase {
protected function doSetUp($config, $uri, $host): void protected function doSetUp($config, $uri, $host): void
{ {
// Set up the environment // Set up the environment
$_SERVER = array_merge($_SERVER, [ $GLOBALS['_SERVER'] = array_merge($GLOBALS['_SERVER'], [
'REQUEST_METHOD' => 'GET', 'REQUEST_METHOD' => 'GET',
'REQUEST_URI' => $uri, 'REQUEST_URI' => $uri,
'PATH_INFO' => $uri, 'PATH_INFO' => $uri,
@ -44,7 +44,7 @@ class DispatcherTest extends AnimeClientTestCase {
]); ]);
$this->setSuperGlobals([ $this->setSuperGlobals([
'_SERVER' => $_SERVER '_SERVER' => $GLOBALS['_SERVER']
]); ]);
$logger = new Logger('test_logger'); $logger = new Logger('test_logger');

View File

@ -246,30 +246,14 @@ const SETTINGS_MAP = [
class FormGeneratorTest extends AnimeClientTestCase { class FormGeneratorTest extends AnimeClientTestCase {
protected $generator;
public function setUp(): void
{
parent::setUp();
$this->generator = FormGenerator::new($this->container);
}
public function testSanity(): void
{
$generator = FormGenerator::new($this->container);
$this->assertInstanceOf(FormGenerator::class, $generator);
}
public function testGeneration(): void public function testGeneration(): void
{ {
// $html = $this->generator->generate('database', SETTINGS_MAP); $generator = FormGenerator::new($this->container);
// $this->assertMatchesHtmlSnapshot($html);
foreach (SETTINGS_MAP as $section => $fields) foreach (SETTINGS_MAP as $section => $fields)
{ {
foreach ($fields as $name => $config) foreach ($fields as $name => $config)
{ {
$html = $this->generator->generate($name, $config); $html = $generator->generate($name, $config);
$this->assertMatchesSnapshot($html); $this->assertMatchesSnapshot($html);
} }
} }

View File

@ -1 +1 @@
<input id="whose_list" type="text" name="whose_list" value="" /> <input id="whose_list" type="text" name="whose_list" value="Somebody" />

View File

@ -1,5 +1,5 @@
<select id="theme" name="theme"> <select id="theme" name="theme">
<option value="auto">Automatically match OS theme</option> <option value="auto" selected>Automatically match OS theme</option>
<option value="light">Original Light Theme</option> <option value="light">Original Light Theme</option>
<option value="dark">Dark Theme</option> <option value="dark">Dark Theme</option>
</select> </select>

View File

@ -1,5 +1,5 @@
<select id="type" name="type"> <select id="type" name="type">
<option value="mysql">MySQL</option> <option value="mysql">MySQL</option>
<option value="pgsql">PostgreSQL</option> <option value="pgsql">PostgreSQL</option>
<option value="sqlite">SQLite</option> <option value="sqlite" selected>SQLite</option>
</select> </select>

View File

@ -1 +1 @@
<input id="file" type="text" name="file" value="" /> <input id="file" type="text" name="file" value="anime_collection.sqlite" />

View File

@ -1 +1 @@
<input id="access_token_expires" type="text" name="access_token_expires" readonly value="" /> <input id="access_token_expires" type="text" name="access_token_expires" readonly value="0" />

View File

@ -112,7 +112,7 @@ class IonTestCase extends TestCase {
public function setSuperGlobals(array $supers = []): void public function setSuperGlobals(array $supers = []): void
{ {
$default = [ $default = [
'_SERVER' => $_SERVER, '_SERVER' => $GLOBALS['_SERVER'],
'_GET' => $_GET, '_GET' => $_GET,
'_POST' => $_POST, '_POST' => $_POST,
'_COOKIE' => $_COOKIE, '_COOKIE' => $_COOKIE,

View File

@ -22,7 +22,7 @@ return static function(array $config_array = []) {
$container->set('request', static function() { $container->set('request', static function() {
return ServerRequestFactory::fromGlobals( return ServerRequestFactory::fromGlobals(
$_SERVER, $GLOBALS['_SERVER'],
$_GET, $_GET,
$_POST, $_POST,
$_COOKIE, $_COOKIE,