Rector updates for tests
This commit is contained in:
parent
97fe3b4b40
commit
77c6419c80
@ -40,7 +40,7 @@ final class APIRequestBuilderTest extends TestCase
|
||||
$this->builder->setLogger(new NullLogger());
|
||||
}
|
||||
|
||||
public function testGzipRequest(): void
|
||||
public function testGzipRequest(): never
|
||||
{
|
||||
$this->markTestSkipped('Need new test API');
|
||||
|
||||
@ -51,7 +51,7 @@ final class APIRequestBuilderTest extends TestCase
|
||||
$this->assertTrue($body['gzipped']);
|
||||
}
|
||||
|
||||
public function testInvalidRequestMethod(): void
|
||||
public function testInvalidRequestMethod(): never
|
||||
{
|
||||
$this->markTestSkipped('Need new test API');
|
||||
|
||||
@ -60,7 +60,7 @@ final class APIRequestBuilderTest extends TestCase
|
||||
->getFullRequest();
|
||||
}
|
||||
|
||||
public function testRequestWithBasicAuth(): void
|
||||
public function testRequestWithBasicAuth(): never
|
||||
{
|
||||
$this->markTestSkipped('Need new test API');
|
||||
|
||||
@ -74,7 +74,7 @@ final class APIRequestBuilderTest extends TestCase
|
||||
$this->assertSame('Basic dXNlcm5hbWU6cGFzc3dvcmQ=', $body['headers']['Authorization']);
|
||||
}
|
||||
|
||||
public function testRequestWithQueryString(): void
|
||||
public function testRequestWithQueryString(): never
|
||||
{
|
||||
$this->markTestSkipped('Need new test API');
|
||||
|
||||
@ -104,7 +104,7 @@ final class APIRequestBuilderTest extends TestCase
|
||||
$this->assertSame($expected, $body['args']);
|
||||
}
|
||||
|
||||
public function testFormValueRequest(): void
|
||||
public function testFormValueRequest(): never
|
||||
{
|
||||
$this->markTestSkipped('Need new test API');
|
||||
|
||||
@ -123,7 +123,7 @@ final class APIRequestBuilderTest extends TestCase
|
||||
$this->assertSame($formValues, $body['form']);
|
||||
}
|
||||
|
||||
public function testFullUrlRequest(): void
|
||||
public function testFullUrlRequest(): never
|
||||
{
|
||||
$this->markTestSkipped('Need new test API');
|
||||
|
||||
|
@ -38,7 +38,7 @@ final class AnimeListTransformerTest extends AnimeClientTestCase
|
||||
$this->transformer = new AnimeListTransformer();
|
||||
}
|
||||
|
||||
public function testTransform(): void
|
||||
public function testTransform(): never
|
||||
{
|
||||
$this->markTestSkipped('Old test data');
|
||||
|
||||
@ -50,7 +50,7 @@ final class AnimeListTransformerTest extends AnimeClientTestCase
|
||||
{
|
||||
return [[
|
||||
'input' => [
|
||||
'id' => 14047981,
|
||||
'id' => 14_047_981,
|
||||
'watching_status' => 'current',
|
||||
'user_rating' => 8,
|
||||
'episodes_watched' => 38,
|
||||
@ -60,7 +60,7 @@ final class AnimeListTransformerTest extends AnimeClientTestCase
|
||||
],
|
||||
], [
|
||||
'input' => [
|
||||
'id' => 14047981,
|
||||
'id' => 14_047_981,
|
||||
'mal_id' => '12345',
|
||||
'watching_status' => 'current',
|
||||
'user_rating' => 8,
|
||||
@ -73,7 +73,7 @@ final class AnimeListTransformerTest extends AnimeClientTestCase
|
||||
],
|
||||
], [
|
||||
'input' => [
|
||||
'id' => 14047983,
|
||||
'id' => 14_047_983,
|
||||
'mal_id' => '12347',
|
||||
'watching_status' => 'current',
|
||||
'user_rating' => 0,
|
||||
|
@ -37,7 +37,7 @@ final class AnimeTransformerTest extends AnimeClientTestCase
|
||||
$this->transformer = new AnimeTransformer();
|
||||
}
|
||||
|
||||
public function testTransform()
|
||||
public function testTransform(): never
|
||||
{
|
||||
$this->markTestSkipped('May fail on CI');
|
||||
$actual = $this->transformer->transform($this->beforeTransform);
|
||||
|
@ -35,7 +35,7 @@ final class CharacterTransformerTest extends AnimeClientTestCase
|
||||
$this->beforeTransform = $raw;
|
||||
}
|
||||
|
||||
public function testTransform(): void
|
||||
public function testTransform(): never
|
||||
{
|
||||
$this->markTestSkipped('Fails on CI');
|
||||
$actual = (new CharacterTransformer())->transform($this->beforeTransform);
|
||||
|
@ -35,7 +35,7 @@ final class HistoryTransformerTest extends AnimeClientTestCase
|
||||
$this->beforeTransform = $raw;
|
||||
}
|
||||
|
||||
public function testAnimeTransform(): void
|
||||
public function testAnimeTransform(): never
|
||||
{
|
||||
$this->markTestSkipped('Old test data');
|
||||
|
||||
|
@ -35,7 +35,7 @@ final class PersonTransformerTest extends AnimeClientTestCase
|
||||
$this->beforeTransform = $raw;
|
||||
}
|
||||
|
||||
public function testTransform(): void
|
||||
public function testTransform(): never
|
||||
{
|
||||
$this->markTestSkipped('Fails on CI');
|
||||
$actual = (new PersonTransformer())->transform($this->beforeTransform);
|
||||
|
@ -40,10 +40,10 @@ class AnimeClientTestCase extends TestCase
|
||||
use MatchesSnapshots;
|
||||
|
||||
// Test directory constants
|
||||
public const ROOT_DIR = AC_TEST_ROOT_DIR;
|
||||
public const SRC_DIR = SRC_DIR;
|
||||
public const TEST_DATA_DIR = __DIR__ . '/test_data';
|
||||
public const TEST_VIEW_DIR = __DIR__ . '/test_views';
|
||||
final public const ROOT_DIR = AC_TEST_ROOT_DIR;
|
||||
final public const SRC_DIR = SRC_DIR;
|
||||
final public const TEST_DATA_DIR = __DIR__ . '/test_data';
|
||||
final public const TEST_VIEW_DIR = __DIR__ . '/test_views';
|
||||
|
||||
protected ContainerInterface $container;
|
||||
|
||||
@ -97,7 +97,7 @@ class AnimeClientTestCase extends TestCase
|
||||
$container = $di($config_array);
|
||||
|
||||
// Use mock session handler
|
||||
$container->set('session-handler', static function () {
|
||||
$container->set('session-handler', static function (): \Aviat\AnimeClient\Tests\TestSessionHandler {
|
||||
$session_handler = new TestSessionHandler();
|
||||
session_set_save_handler($session_handler, TRUE);
|
||||
|
||||
@ -123,7 +123,7 @@ class AnimeClientTestCase extends TestCase
|
||||
];
|
||||
|
||||
$request = call_user_func_array(
|
||||
[ServerRequestFactory::class, 'fromGlobals'],
|
||||
ServerRequestFactory::fromGlobals(...),
|
||||
array_values(array_merge($default, $supers)),
|
||||
);
|
||||
$this->container->setInstance('request', $request);
|
||||
|
@ -141,11 +141,8 @@ final class DispatcherTest extends AnimeClientTestCase
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $config
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('dataRoute')]
|
||||
public function testRoute($config, mixed $controller, mixed $host, mixed $uri): void
|
||||
public function testRoute(mixed $config, mixed $controller, mixed $host, mixed $uri): void
|
||||
{
|
||||
$this->doSetUp($config, $uri, $host);
|
||||
|
||||
|
@ -251,7 +251,7 @@ final class FormGeneratorTest extends AnimeClientTestCase
|
||||
{
|
||||
$generator = FormGenerator::new($this->container);
|
||||
|
||||
foreach (SETTINGS_MAP as $section => $fields)
|
||||
foreach (SETTINGS_MAP as $fields)
|
||||
{
|
||||
foreach ($fields as $name => $config)
|
||||
{
|
||||
|
@ -64,6 +64,7 @@ final class MenuHelperTest extends AnimeClientTestCase
|
||||
// Set config for tests
|
||||
$config = $this->container->get('config');
|
||||
$config->set('menus', $menus);
|
||||
|
||||
$this->container->setInstance('config', $config);
|
||||
|
||||
foreach ($menus as $case => $config)
|
||||
|
@ -83,6 +83,7 @@ final class MenuGeneratorTest extends AnimeClientTestCase
|
||||
];
|
||||
$config = $this->container->get('config');
|
||||
$config->set('menus', $menus);
|
||||
|
||||
$this->container->setInstance('config', $config);
|
||||
$expected = '';
|
||||
|
||||
|
@ -23,7 +23,7 @@ final class RequirementsTest extends AnimeClientTestCase
|
||||
{
|
||||
public function testPHPVersion(): void
|
||||
{
|
||||
$this->assertTrue(version_compare(PHP_VERSION, '8', 'ge'));
|
||||
$this->assertTrue(PHP_VERSION_ID >= 8);
|
||||
}
|
||||
|
||||
public function testHasPDO(): void
|
||||
|
@ -55,13 +55,13 @@ class TestSessionHandler implements SessionHandlerInterface
|
||||
|
||||
public function read($id)
|
||||
{
|
||||
return json_decode(@file_get_contents("{$this->savePath}/{$id}"), TRUE);
|
||||
return json_decode(@file_get_contents("{$this->savePath}/{$id}"), TRUE, 512, JSON_THROW_ON_ERROR);
|
||||
}
|
||||
|
||||
public function write($id, $data)
|
||||
{
|
||||
$file = "{$this->savePath}/{$id}";
|
||||
file_put_contents($file, json_encode($data));
|
||||
file_put_contents($file, json_encode($data, JSON_THROW_ON_ERROR));
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -69,11 +69,8 @@ final class UtilTest extends AnimeClientTestCase
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $uri
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('dataIsViewPage')]
|
||||
public function testIsViewPage($uri, mixed $expected)
|
||||
public function testIsViewPage(mixed $uri, mixed $expected)
|
||||
{
|
||||
$this->setSuperGlobals([
|
||||
'_SERVER' => [
|
||||
@ -83,12 +80,8 @@ final class UtilTest extends AnimeClientTestCase
|
||||
$this->assertSame($expected, $this->util->isViewPage());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $uri
|
||||
* @param mixed $expected
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('dataIsViewPage')]
|
||||
public function testIsFormPage($uri, $expected)
|
||||
public function testIsFormPage(mixed $uri, mixed $expected)
|
||||
{
|
||||
$this->setSuperGlobals([
|
||||
'_SERVER' => [
|
||||
|
@ -29,9 +29,9 @@ class MockErrorHandler
|
||||
|
||||
class TestEnum extends Enum
|
||||
{
|
||||
public const FOO = 'bar';
|
||||
public const BAR = 'foo';
|
||||
public const FOOBAR = 'baz';
|
||||
final public const FOO = 'bar';
|
||||
final public const BAR = 'foo';
|
||||
final public const FOOBAR = 'baz';
|
||||
}
|
||||
|
||||
class FriendGrandParentTestClass
|
||||
|
@ -29,12 +29,9 @@ use TypeError;
|
||||
*/
|
||||
final class FooTest
|
||||
{
|
||||
public $item;
|
||||
|
||||
public function __construct($item)
|
||||
{
|
||||
$this->item = $item;
|
||||
}
|
||||
public function __construct(public $item)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
class FooTest2
|
||||
@ -71,11 +68,8 @@ final class ContainerTest extends IonTestCase
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $exception
|
||||
*/
|
||||
#[DataProvider('dataGetWithException')]
|
||||
public function testGetWithException(mixed $id, $exception, ?string $message = NULL): void
|
||||
public function testGetWithException(mixed $id, mixed $exception, ?string $message = NULL): void
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -92,11 +86,8 @@ final class ContainerTest extends IonTestCase
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $exception
|
||||
*/
|
||||
#[DataProvider('dataGetWithException')]
|
||||
public function testGetNewWithException(mixed $id, $exception, ?string $message = NULL): void
|
||||
public function testGetNewWithException(mixed $id, mixed $exception, ?string $message = NULL): void
|
||||
{
|
||||
$this->expectException($exception);
|
||||
if ($message !== NULL)
|
||||
@ -123,13 +114,8 @@ final class ContainerTest extends IonTestCase
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $id
|
||||
* @param mixed $exception
|
||||
* @param mixed $message
|
||||
*/
|
||||
#[DataProvider('dataSetInstanceWithException')]
|
||||
public function testSetInstanceWithException($id, $exception, $message): void
|
||||
public function testSetInstanceWithException(mixed $id, mixed $exception, mixed $message): void
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -176,9 +162,7 @@ final class ContainerTest extends IonTestCase
|
||||
|
||||
public function testGetSet(): void
|
||||
{
|
||||
$container = $this->container->set('foo', static function () {
|
||||
return static function () {};
|
||||
});
|
||||
$container = $this->container->set('foo', static fn() => static function (): void {});
|
||||
|
||||
$this->assertInstanceOf(Container::class, $container);
|
||||
$this->assertInstanceOf(ContainerInterface::class, $container);
|
||||
|
@ -70,12 +70,8 @@ final class EnumTest extends IonTestCase
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
* @param mixed $static
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('dataIsValid')]
|
||||
public function testIsValid($value, mixed $expected, $static)
|
||||
public function testIsValid(mixed $value, mixed $expected, mixed $static)
|
||||
{
|
||||
$actual = ($static)
|
||||
? TestEnum::isValid($value)
|
||||
|
@ -22,7 +22,7 @@ use Aviat\Ion\Tests\IonTestCase;
|
||||
*/
|
||||
final class DoubleRenderExceptionTest extends IonTestCase
|
||||
{
|
||||
public function testDefaultMessage()
|
||||
public function testDefaultMessage(): never
|
||||
{
|
||||
$this->expectException(DoubleRenderException::class);
|
||||
$this->expectExceptionMessage('A view can only be rendered once, because headers can only be sent once.');
|
||||
|
@ -26,10 +26,10 @@ use function Aviat\Ion\_dir;
|
||||
class IonTestCase extends TestCase
|
||||
{
|
||||
// Test directory constants
|
||||
public const ROOT_DIR = AC_TEST_ROOT_DIR;
|
||||
public const SRC_DIR = SRC_DIR;
|
||||
public const TEST_DATA_DIR = __DIR__ . '/test_data';
|
||||
public const TEST_VIEW_DIR = __DIR__ . '/test_views';
|
||||
final public const ROOT_DIR = AC_TEST_ROOT_DIR;
|
||||
final public const SRC_DIR = SRC_DIR;
|
||||
final public const TEST_DATA_DIR = __DIR__ . '/test_data';
|
||||
final public const TEST_VIEW_DIR = __DIR__ . '/test_views';
|
||||
|
||||
protected ContainerInterface $container;
|
||||
protected static $staticContainer;
|
||||
@ -92,7 +92,7 @@ class IonTestCase extends TestCase
|
||||
// Set up DI container
|
||||
$di = require 'di.php';
|
||||
$container = $di($config_array);
|
||||
$container->set('session-handler', static function () {
|
||||
$container->set('session-handler', static function (): \Aviat\Ion\Tests\TestSessionHandler {
|
||||
// Use mock session handler
|
||||
$session_handler = new TestSessionHandler();
|
||||
session_set_save_handler($session_handler, TRUE);
|
||||
@ -117,7 +117,7 @@ class IonTestCase extends TestCase
|
||||
];
|
||||
|
||||
$request = call_user_func_array(
|
||||
[ServerRequestFactory::class, 'fromGlobals'],
|
||||
ServerRequestFactory::fromGlobals(...),
|
||||
array_merge($default, $supers)
|
||||
);
|
||||
$this->container->setInstance('request', $request);
|
||||
|
@ -74,7 +74,7 @@ final class JsonTest extends IonTestCase
|
||||
$this->assertEquals((object) $expected, Json::decode($json, FALSE));
|
||||
|
||||
$badJson = '{foo:{1|2}}';
|
||||
$this->expectException('Aviat\Ion\JsonException');
|
||||
$this->expectException(\Aviat\Ion\JsonException::class);
|
||||
$this->expectExceptionMessage('JSON_ERROR_SYNTAX - Syntax error');
|
||||
$this->expectExceptionCode(JSON_ERROR_SYNTAX);
|
||||
|
||||
|
@ -55,13 +55,13 @@ class TestSessionHandler implements SessionHandlerInterface
|
||||
|
||||
public function read($id)
|
||||
{
|
||||
return json_decode(@file_get_contents("{$this->save_path}/{$id}"), TRUE);
|
||||
return json_decode(@file_get_contents("{$this->save_path}/{$id}"), TRUE, 512, JSON_THROW_ON_ERROR);
|
||||
}
|
||||
|
||||
public function write($id, $data)
|
||||
{
|
||||
$file = "{$this->save_path}/{$id}";
|
||||
file_put_contents($file, json_encode($data));
|
||||
file_put_contents($file, json_encode($data, JSON_THROW_ON_ERROR));
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -130,32 +130,22 @@ final class AbstractTransformerTest extends IonTestCase
|
||||
$this->assertSame($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $original
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('dataTransformCollection')]
|
||||
public function testTransformCollection($original, mixed $expected)
|
||||
public function testTransformCollection(mixed $original, mixed $expected)
|
||||
{
|
||||
$actual = $this->transformer->transformCollection($original);
|
||||
$this->assertSame($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $original
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('dataUnTransformCollection')]
|
||||
public function testUntransformCollection($original, mixed $expected)
|
||||
public function testUntransformCollection(mixed $original, mixed $expected)
|
||||
{
|
||||
$actual = $this->untransformer->untransformCollection($original);
|
||||
$this->assertSame($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $original
|
||||
* @param mixed $expected
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('dataUnTransformCollection')]
|
||||
public function testUntransformCollectionWithException($original, $expected)
|
||||
public function testUntransformCollectionWithException(mixed $original, mixed $expected)
|
||||
{
|
||||
$this->expectException(BadMethodCallException::class);
|
||||
$this->transformer->untransformCollection($original);
|
||||
|
@ -16,15 +16,13 @@ return static function (array $config_array = []) {
|
||||
|
||||
$container->setInstance('config', new Config($config_array));
|
||||
|
||||
$container->set('request', static function () {
|
||||
return ServerRequestFactory::fromGlobals(
|
||||
$container->set('request', static fn() => ServerRequestFactory::fromGlobals(
|
||||
$GLOBALS['_SERVER'],
|
||||
$_GET,
|
||||
$_POST,
|
||||
$_COOKIE,
|
||||
$_FILES
|
||||
);
|
||||
});
|
||||
));
|
||||
|
||||
$container->set('response', static fn () => new Response());
|
||||
|
||||
|
@ -36,9 +36,9 @@ class MockErrorHandler
|
||||
|
||||
class TestEnum extends Enum
|
||||
{
|
||||
public const FOO = 'bar';
|
||||
public const BAR = 'foo';
|
||||
public const FOOBAR = 'baz';
|
||||
final public const FOO = 'bar';
|
||||
final public const BAR = 'foo';
|
||||
final public const FOOBAR = 'baz';
|
||||
}
|
||||
|
||||
class FriendGrandParentTestClass
|
||||
@ -49,13 +49,13 @@ class FriendGrandParentTestClass
|
||||
class FriendParentTestClass extends FriendGrandParentTestClass
|
||||
{
|
||||
protected $parentProtected = 47;
|
||||
private $parentPrivate = 654;
|
||||
private int $parentPrivate = 654;
|
||||
}
|
||||
|
||||
class FriendTestClass extends FriendParentTestClass
|
||||
{
|
||||
protected $protected = 356;
|
||||
private $private = 486;
|
||||
private int $private = 486;
|
||||
|
||||
protected function getProtected()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user