From ba4d3f497bcbaf18412ddef3c59ee2c14ee96826 Mon Sep 17 00:00:00 2001 From: "J. King" Date: Fri, 27 Dec 2024 20:28:38 -0500 Subject: [PATCH] Replace PHPUnit annotations with attributes --- .php-cs-fixer.dist.php | 1 + tests/bootstrap.php | 3 +- tests/cases/CLI/TestCLI.php | 51 ++++++++++++------- tests/cases/Conf/TestConf.php | 36 ++++++++----- tests/cases/Database/AbstractTest.php | 3 +- tests/cases/Database/SeriesArticle.php | 3 +- tests/cases/Database/SeriesCleanup.php | 1 + tests/cases/Database/SeriesFeed.php | 1 + tests/cases/Database/SeriesFolder.php | 1 + tests/cases/Database/SeriesIcon.php | 1 + tests/cases/Database/SeriesLabel.php | 1 + tests/cases/Database/SeriesMeta.php | 1 + tests/cases/Database/SeriesMiscellany.php | 1 + tests/cases/Database/SeriesSession.php | 1 + tests/cases/Database/SeriesSubscription.php | 1 + tests/cases/Database/SeriesTag.php | 1 + tests/cases/Database/SeriesToken.php | 1 + tests/cases/Database/SeriesUser.php | 1 + tests/cases/Database/TestDatabase.php | 11 ++-- tests/cases/Db/BaseDriver.php | 3 +- tests/cases/Db/BaseResult.php | 1 + tests/cases/Db/BaseStatement.php | 8 ++- tests/cases/Db/BaseUpdate.php | 3 +- tests/cases/Db/MySQL/TestDatabase.php | 12 +++-- tests/cases/Db/MySQLPDO/TestDatabase.php | 14 ++--- tests/cases/Db/PostgreSQL/TestDatabase.php | 12 +++-- tests/cases/Db/PostgreSQLPDO/TestDatabase.php | 14 ++--- tests/cases/Db/SQLite3/TestDatabase.php | 10 ++-- tests/cases/Db/SQLite3PDO/TestDatabase.php | 7 +-- tests/cases/Db/TestTransaction.php | 5 +- tests/cases/Exception/TestException.php | 27 ++++------ tests/cases/Feed/TestException.php | 19 ++++--- tests/cases/Feed/TestFeed.php | 15 ++++-- tests/cases/Feed/TestFetching.php | 8 +-- tests/cases/ImportExport/TestFile.php | 11 ++-- tests/cases/ImportExport/TestImportExport.php | 4 +- tests/cases/Lang/TestBasic.php | 21 +++----- tests/cases/Lang/TestComplex.php | 37 +++++--------- tests/cases/Lang/TestErrors.php | 4 +- tests/cases/Misc/TestDate.php | 4 +- tests/cases/Misc/TestFactory.php | 4 +- tests/cases/Misc/TestHTTP.php | 10 ++-- tests/cases/Misc/TestQuery.php | 8 +-- tests/cases/Misc/TestRule.php | 8 ++- tests/cases/Misc/TestURL.php | 13 +++-- tests/cases/Misc/TestValueInfo.php | 20 +++++--- tests/cases/REST/Miniflux/TestStatus.php | 7 ++- tests/cases/REST/Miniflux/TestV1.php | 2 +- .../cases/REST/NextcloudNews/TestVersions.php | 4 +- tests/cases/REST/TestREST.php | 33 +++++++----- tests/cases/REST/TinyTinyRSS/TestAPI.php | 2 +- tests/cases/REST/TinyTinyRSS/TestIcon.php | 2 +- tests/cases/REST/TinyTinyRSS/TestSearch.php | 8 ++- tests/cases/Service/TestDaemon.php | 21 +++++--- tests/cases/Service/TestSerial.php | 4 +- tests/cases/Service/TestService.php | 6 ++- tests/cases/Service/TestSubprocess.php | 4 +- tests/cases/TestArsse.php | 8 ++- tests/cases/User/TestInternal.php | 12 +++-- tests/cases/User/TestUser.php | 23 ++++++--- tests/lib/AbstractTest.php | 6 ++- tests/lib/Database.php | 1 + tests/lib/DatabaseDrivers/MySQL.php | 3 +- tests/lib/DatabaseDrivers/MySQLCommon.php | 1 + tests/lib/DatabaseDrivers/MySQLPDO.php | 1 + tests/lib/DatabaseDrivers/PostgreSQL.php | 1 + .../lib/DatabaseDrivers/PostgreSQLCommon.php | 1 + tests/lib/DatabaseDrivers/PostgreSQLPDO.php | 1 + tests/lib/DatabaseDrivers/SQLite3.php | 1 + tests/lib/DatabaseDrivers/SQLite3Common.php | 1 + tests/lib/DatabaseDrivers/SQLite3PDO.php | 1 + tests/lib/Lang/Setup.php | 1 + tests/lib/Misc/StrClass.php | 1 + tests/lib/PDOTest.php | 1 + tests/lib/Result.php | 1 + tests/lib/Service.php | 1 + tests/server.php | 1 + 77 files changed, 363 insertions(+), 219 deletions(-) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 2baaee70..d85ff33f 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -65,6 +65,7 @@ $rules = [ ], 'function_declaration' => ['closure_function_spacing' => "none"], 'new_with_braces' => false, // no option to specify absence of braces + 'php_unit_attributes' => true, ]; $finder = \PhpCsFixer\Finder::create(); diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 63092953..e748d2b1 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,4 +1,5 @@ cli, \Phake::never())->loadConf(); } - /** @dataProvider provideHelpText */ + + #[DataProvider('provideHelpText')] public function testPrintHelp(string $cmd, string $name): void { $this->assertConsole($cmd, 0, str_replace("arsse.php", $name, CLI::USAGE)); \Phake::verify($this->cli, \Phake::never())->loadConf(); @@ -66,7 +70,7 @@ class TestCLI extends \JKingWeb\Arsse\Test\AbstractTest { public function testStartTheDaemon(): void { $srv = \Phake::mock(Service::class); - \Phake::when($srv)->watch->thenReturn(new \DateTimeImmutable); + \Phake::when($srv)->watch->thenReturn(new \DateTimeImmutable()); \Phake::when(Arsse::$obj)->get(Service::class)->thenReturn($srv); $this->assertConsole("arsse.php daemon", 0); \Phake::verify($this->cli)->loadConf(); @@ -77,7 +81,7 @@ class TestCLI extends \JKingWeb\Arsse\Test\AbstractTest { $f = tempnam(sys_get_temp_dir(), "arsse"); $srv = \Phake::mock(Service::class); $daemon = \Phake::mock(Daemon::class); - \Phake::when($srv)->watch->thenReturn(new \DateTimeImmutable); + \Phake::when($srv)->watch->thenReturn(new \DateTimeImmutable()); \Phake::when($daemon)->checkPIDFilePath->thenReturn($f); \Phake::when($daemon)->fork->thenReturn(null); \Phake::when(Arsse::$obj)->get(Service::class)->thenReturn($srv); @@ -95,7 +99,7 @@ class TestCLI extends \JKingWeb\Arsse\Test\AbstractTest { public function testFailToStartTheForkingDaemon(): void { $srv = \Phake::mock(Service::class); $daemon = \Phake::mock(Daemon::class); - \Phake::when($srv)->watch->thenReturn(new \DateTimeImmutable); + \Phake::when($srv)->watch->thenReturn(new \DateTimeImmutable()); \Phake::when($daemon)->checkPIDFilePath->thenThrow(new Service\Exception("pidDuplicate", ['pid' => 2112])); \Phake::when($daemon)->fork->thenReturn(null); \Phake::when(Arsse::$obj)->get(Service::class)->thenReturn($srv); @@ -109,14 +113,15 @@ class TestCLI extends \JKingWeb\Arsse\Test\AbstractTest { public function testRefreshAllFeeds(): void { $srv = \Phake::mock(Service::class); - \Phake::when($srv)->watch->thenReturn(new \DateTimeImmutable); + \Phake::when($srv)->watch->thenReturn(new \DateTimeImmutable()); \Phake::when(Arsse::$obj)->get(Service::class)->thenReturn($srv); $this->assertConsole("arsse.php feed refresh-all", 0); \Phake::verify($this->cli)->loadConf(); \Phake::verify($srv)->watch(false); } - /** @dataProvider provideFeedUpdates */ + + #[DataProvider('provideFeedUpdates')] public function testRefreshAFeed(string $cmd, int $exitStatus, string $output): void { \Phake::when(Arsse::$db)->feedUpdate(1, true)->thenReturn(true); \Phake::when(Arsse::$db)->feedUpdate(2, true)->thenThrow(new \JKingWeb\Arsse\Feed\Exception("", ['url' => "http://example.com/"], $this->mockGuzzleException(ClientException::class, "", 404))); @@ -132,7 +137,8 @@ class TestCLI extends \JKingWeb\Arsse\Test\AbstractTest { ]; } - /** @dataProvider provideDefaultConfigurationSaves */ + + #[DataProvider('provideDefaultConfigurationSaves')] public function testSaveTheDefaultConfiguration(string $cmd, int $exitStatus, string $file): void { $conf = \Phake::mock(Conf::class); \Phake::when($conf)->exportFile("php://output", true)->thenReturn(true); @@ -153,7 +159,8 @@ class TestCLI extends \JKingWeb\Arsse\Test\AbstractTest { ]; } - /** @dataProvider provideUserList */ + + #[DataProvider('provideUserList')] public function testListUsers(string $cmd, array $list, int $exitStatus, string $output): void { Arsse::$user = \Phake::mock(User::class); \Phake::when(Arsse::$user)->list()->thenReturn($list); @@ -171,7 +178,8 @@ class TestCLI extends \JKingWeb\Arsse\Test\AbstractTest { ]; } - /** @dataProvider provideUserAdditions */ + + #[DataProvider('provideUserAdditions')] public function testAddAUser(string $cmd, int $exitStatus, string $output): void { Arsse::$user = \Phake::mock(User::class); \Phake::when(Arsse::$user)->add("john.doe@example.com", $this->anything())->thenThrow(new \JKingWeb\Arsse\User\ExceptionConflict("alreadyExists")); @@ -199,7 +207,8 @@ class TestCLI extends \JKingWeb\Arsse\Test\AbstractTest { \Phake::verify(Arsse::$user)->propertiesSet("jane.doe@example.com", ['admin' => true]); } - /** @dataProvider provideUserAuthentication */ + + #[DataProvider('provideUserAuthentication')] public function testAuthenticateAUser(string $cmd, int $exitStatus, string $output): void { Arsse::$user = \Phake::mock(User::class); \Phake::when(Arsse::$user)->auth->thenReturn(false); @@ -214,7 +223,7 @@ class TestCLI extends \JKingWeb\Arsse\Test\AbstractTest { } public static function provideUserAuthentication(): iterable { - $l = new \JKingWeb\Arsse\Lang; + $l = new \JKingWeb\Arsse\Lang(); $success = $l("CLI.Auth.Success"); $failure = $l("CLI.Auth.Failure"); return [ @@ -229,7 +238,8 @@ class TestCLI extends \JKingWeb\Arsse\Test\AbstractTest { ]; } - /** @dataProvider provideUserRemovals */ + + #[DataProvider('provideUserRemovals')] public function testRemoveAUser(string $cmd, int $exitStatus, string $output): void { Arsse::$user = \Phake::mock(User::class); \Phake::when(Arsse::$user)->remove->thenThrow(new \JKingWeb\Arsse\User\ExceptionConflict("doesNotExist")); @@ -244,7 +254,8 @@ class TestCLI extends \JKingWeb\Arsse\Test\AbstractTest { ]; } - /** @dataProvider provideUserPasswordChanges */ + + #[DataProvider('provideUserPasswordChanges')] public function testChangeAUserPassword(string $cmd, int $exitStatus, string $output): void { $passwordChange = function($user, $pass = null) { switch ($user) { @@ -273,7 +284,8 @@ class TestCLI extends \JKingWeb\Arsse\Test\AbstractTest { ]; } - /** @dataProvider provideUserPasswordClearings */ + + #[DataProvider('provideUserPasswordClearings')] public function testClearAUserPassword(string $cmd, int $exitStatus, string $output): void { $passwordClear = function($user) { switch ($user) { @@ -300,7 +312,8 @@ class TestCLI extends \JKingWeb\Arsse\Test\AbstractTest { ]; } - /** @dataProvider provideOpmlExports */ + + #[DataProvider('provideOpmlExports')] public function testExportToOpml(string $cmd, int $exitStatus, string $file, string $user, bool $flat): void { $opml = \Phake::mock(OPML::class); \Phake::when($opml)->exportFile("php://output", $user, $flat)->thenReturn(true); @@ -341,7 +354,8 @@ class TestCLI extends \JKingWeb\Arsse\Test\AbstractTest { ]; } - /** @dataProvider provideOpmlImports */ + + #[DataProvider('provideOpmlImports')] public function testImportFromOpml(string $cmd, int $exitStatus, string $file, string $user, bool $flat, bool $replace): void { $opml = \Phake::mock(OPML::class); \Phake::when($opml)->importFile("php://input", $user, $flat, $replace)->thenReturn(true); @@ -425,7 +439,8 @@ class TestCLI extends \JKingWeb\Arsse\Test\AbstractTest { \Phake::verify(Arsse::$user)->propertiesGet("john.doe@example.com"); } - /** @dataProvider provideMetadataChanges */ + + #[DataProvider('provideMetadataChanges')] public function testSetMetadataOfAUser(string $cmd, string $user, array $in, array $out, int $exp): void { Arsse::$user = \Phake::mock(User::class); \Phake::when(Arsse::$user)->propertiesSet->thenReturn($out); diff --git a/tests/cases/Conf/TestConf.php b/tests/cases/Conf/TestConf.php index 143caccd..5a891fb3 100644 --- a/tests/cases/Conf/TestConf.php +++ b/tests/cases/Conf/TestConf.php @@ -1,4 +1,5 @@ assertInstanceOf(Conf::class, new Conf); } - /** @depends testLoadDefaultValues */ + + #[Depends('testLoadDefaultValues')] public function testImportFromArray(): void { $arr = [ 'lang' => "xx", @@ -54,7 +58,8 @@ class TestConf extends \JKingWeb\Arsse\Test\AbstractTest { $this->assertEquals("xx", $conf->lang); } - /** @depends testImportFromArray */ + + #[Depends('testImportFromArray')] public function testImportFromFile(): void { $conf = new Conf; $conf->importFile(self::$path."confGood"); @@ -63,38 +68,44 @@ class TestConf extends \JKingWeb\Arsse\Test\AbstractTest { $this->assertEquals("xx", $conf->lang); } - /** @depends testImportFromFile */ + + #[Depends('testImportFromFile')] public function testImportFromMissingFile(): void { $this->assertException("fileMissing", "Conf"); $conf = new Conf(self::$path."confMissing"); } - /** @depends testImportFromFile */ + + #[Depends('testImportFromFile')] public function testImportFromEmptyFile(): void { $this->assertException("fileCorrupt", "Conf"); $conf = new Conf(self::$path."confEmpty"); } - /** @depends testImportFromFile */ + + #[Depends('testImportFromFile')] public function testImportFromFileWithoutReadPermission(): void { $this->assertException("fileUnreadable", "Conf"); $conf = new Conf(self::$path."confUnreadable"); } - /** @depends testImportFromFile */ + + #[Depends('testImportFromFile')] public function testImportFromFileWhichIsNotAnArray(): void { $this->assertException("fileCorrupt", "Conf"); $conf = new Conf(self::$path."confNotArray"); } - /** @depends testImportFromFile */ + + #[Depends('testImportFromFile')] public function testImportFromFileWhichIsNotPhp(): void { $this->assertException("fileCorrupt", "Conf"); // this should not print the output of the non-PHP file $conf = new Conf(self::$path."confNotPHP"); } - /** @depends testImportFromFile */ + + #[Depends('testImportFromFile')] public function testImportFromCorruptFile(): void { $this->assertException("fileCorrupt", "Conf"); $conf = new Conf(self::$path."confCorrupt"); @@ -145,8 +156,8 @@ class TestConf extends \JKingWeb\Arsse\Test\AbstractTest { $this->assertArraySubset($exp, $res); } - /** @depends testExportToArray - * @depends testImportFromFile */ + #[Depends('testExportToArray')] + #[Depends('testImportFromFile')] public function testExportToFile(): void { $conf = new Conf; $conf->lang = ["en", "fr"]; // should not be exported: not scalar @@ -167,7 +178,8 @@ class TestConf extends \JKingWeb\Arsse\Test\AbstractTest { $this->assertArraySubset($exp, $arr); } - /** @depends testExportToFile */ + + #[Depends('testExportToFile')] public function testExportToStdout(): void { $conf = new Conf(self::$path."confGood"); $conf->exportFile(self::$path."confGood"); diff --git a/tests/cases/Database/AbstractTest.php b/tests/cases/Database/AbstractTest.php index 309843ee..8bfb4f58 100644 --- a/tests/cases/Database/AbstractTest.php +++ b/tests/cases/Database/AbstractTest.php @@ -1,4 +1,5 @@ getMessage(); return; diff --git a/tests/cases/Database/SeriesArticle.php b/tests/cases/Database/SeriesArticle.php index a918a868..5790fcb9 100644 --- a/tests/cases/Database/SeriesArticle.php +++ b/tests/cases/Database/SeriesArticle.php @@ -1,4 +1,5 @@ data, $this->matches, $this->fields, $this->checkTables, $this->user); } - /** + /** * @dataProvider provideContextMatches * @covers \JKingWeb\Arsse\Database::articleList * @covers \JKingWeb\Arsse\Database::articleQuery diff --git a/tests/cases/Database/SeriesCleanup.php b/tests/cases/Database/SeriesCleanup.php index 7d745a06..54a4ff75 100644 --- a/tests/cases/Database/SeriesCleanup.php +++ b/tests/cases/Database/SeriesCleanup.php @@ -1,4 +1,5 @@ drv = new static::$dbDriverClass; + $this->drv = new static::$dbDriverClass(); } public function tearDown(): void { diff --git a/tests/cases/Db/BaseResult.php b/tests/cases/Db/BaseResult.php index 26df924c..69f4ee12 100644 --- a/tests/cases/Db/BaseResult.php +++ b/tests/cases/Db/BaseResult.php @@ -1,4 +1,5 @@ assertInstanceOf(Statement::class, new $this->statementClass(...$this->makeStatement("SELECT ? as value"))); } - /** @dataProvider provideBindings */ + + #[DataProvider('provideBindings')] public function testBindATypedValue($value, string $type, string $exp): void { if ($exp === "null") { $query = "SELECT (? is null) as pass"; @@ -60,7 +63,8 @@ abstract class BaseStatement extends \JKingWeb\Arsse\Test\AbstractTest { $this->assertTrue((bool) $act); } - /** @dataProvider provideBinaryBindings */ + + #[DataProvider('provideBinaryBindings')] public function testHandleBinaryData($value, string $type, string $exp): void { if ($exp === "null") { $query = "SELECT (? is null) as pass"; diff --git a/tests/cases/Db/BaseUpdate.php b/tests/cases/Db/BaseUpdate.php index 86491533..952a9f10 100644 --- a/tests/cases/Db/BaseUpdate.php +++ b/tests/cases/Db/BaseUpdate.php @@ -1,4 +1,5 @@ drv = new static::$dbDriverClass; + $this->drv = new static::$dbDriverClass(); $schemaId = (get_class($this->drv))::schemaID(); // set up a virtual filesystem for schema files $this->vfs = vfsStream::setup("schemata", null, [$schemaId => []]); diff --git a/tests/cases/Db/MySQL/TestDatabase.php b/tests/cases/Db/MySQL/TestDatabase.php index b2a45697..1e9c8f79 100644 --- a/tests/cases/Db/MySQL/TestDatabase.php +++ b/tests/cases/Db/MySQL/TestDatabase.php @@ -1,4 +1,5 @@ assertException("unknown"); - throw new Exception(); + throw new Exception; } - /** - * @depends testBaseClass - */ + #[Depends('testBaseClass')] public function testDerivedClass(): void { $this->assertException("fileMissing", "Lang"); throw new LangException("fileMissing"); } - /** - * @depends testDerivedClass - */ + #[Depends('testDerivedClass')] public function testDerivedClassWithMessageParameters(): void { $this->assertException("fileMissing", "Lang"); throw new LangException("fileMissing", "en"); } - /** - * @depends testBaseClass - */ + #[Depends('testBaseClass')] public function testBaseClassWithUnknownCode(): void { $this->assertException("uncoded"); throw new Exception("testThisExceptionMessageDoesNotExist"); } - /** - * @depends testBaseClassWithUnknownCode - */ + #[Depends('testBaseClassWithUnknownCode')] public function testDerivedClassWithMissingMessage(): void { $this->assertException("uncoded"); throw new LangException("testThisExceptionMessageDoesNotExist"); diff --git a/tests/cases/Feed/TestException.php b/tests/cases/Feed/TestException.php index c96a9b3b..cbe076f2 100644 --- a/tests/cases/Feed/TestException.php +++ b/tests/cases/Feed/TestException.php @@ -1,4 +1,5 @@ mockGuzzleException(TransferException::class, "cURL error $code: Some message", 0); $this->assertException($message, "Feed"); @@ -116,7 +119,8 @@ class TestException extends \JKingWeb\Arsse\Test\AbstractTest { ]; } - /** @dataProvider provideHTTPErrors */ + + #[DataProvider('provideHTTPErrors')] public function testHandleHttpErrors(int $code, string $message): void { $e = $this->mockGuzzleException(BadResponseException::class, "Irrelevant message", $code); $this->assertException($message, "Feed"); @@ -143,7 +147,8 @@ class TestException extends \JKingWeb\Arsse\Test\AbstractTest { return $out; } - /** @dataProvider providePicoFeedException */ + + #[DataProvider('providePicoFeedException')] public function testHandlePicofeedException(PicoFeedException $e, string $message) { $this->assertException($message, "Feed"); throw new FeedException("", ['url' => "https://example.com/"], $e); @@ -171,7 +176,7 @@ class TestException extends \JKingWeb\Arsse\Test\AbstractTest { } public function testHandleUnexpectedError() { - $e = new \Exception; + $e = new \Exception(); $this->assertException("internalError", "Feed"); throw new FeedException("", ['url' => "https://example.com/"], $e); } diff --git a/tests/cases/Feed/TestFeed.php b/tests/cases/Feed/TestFeed.php index 43f5c0e3..0e05246b 100644 --- a/tests/cases/Feed/TestFeed.php +++ b/tests/cases/Feed/TestFeed.php @@ -1,4 +1,5 @@ assertSame("http://example.com/1", $f->newItems[0]->url); } - /** @dataProvider provide304ResponseURLs */ + + #[DataProvider('provide304ResponseURLs')] public function testHandleCacheHeadersOn304(string $url): void { // upon 304, the client should re-use the caching header values it supplied to the server $t = Date::transform("2010-01-01T00:00:00Z", "unix"); @@ -284,7 +288,8 @@ class TestFeed extends \JKingWeb\Arsse\Test\AbstractTest { } } - /** @dataProvider provide304Timestamps */ + + #[DataProvider('provide304Timestamps')] public function testComputeNextFetchFrom304(string $t, string $exp): void { $t = $t ? strtotime($t) : ""; $f = new Feed(null, $this->base."NextFetch/NotModified?t=$t", Date::transform($t, "http")); diff --git a/tests/cases/Feed/TestFetching.php b/tests/cases/Feed/TestFetching.php index 8b82d614..e7d5569e 100644 --- a/tests/cases/Feed/TestFetching.php +++ b/tests/cases/Feed/TestFetching.php @@ -1,4 +1,5 @@ path.$file; try { @@ -84,7 +88,8 @@ class TestFile extends \JKingWeb\Arsse\Test\AbstractTest { ]; } - /** @dataProvider provideFileImports */ + + #[DataProvider('provideFileImports')] public function testImportFromAFile(string $file, string $user, bool $flat, bool $replace, $exp): void { $path = $this->path.$file; try { diff --git a/tests/cases/ImportExport/TestImportExport.php b/tests/cases/ImportExport/TestImportExport.php index 91bfae86..0b7607c5 100644 --- a/tests/cases/ImportExport/TestImportExport.php +++ b/tests/cases/ImportExport/TestImportExport.php @@ -1,4 +1,5 @@ assertCount(sizeof($this->files), $this->l->list("en")); } - /** - * @depends testListLanguages - */ + #[Depends('testListLanguages')] public function testSetLanguage(): void { $this->assertEquals("en", $this->l->set("en")); $this->assertEquals("en_ca", $this->l->set("en_ca")); @@ -34,18 +35,14 @@ class TestBasic extends \JKingWeb\Arsse\Test\AbstractTest { $this->assertEquals("", $this->l->set("")); } - /** - * @depends testSetLanguage - */ + #[Depends('testSetLanguage')] public function testLoadInternalStrings(): void { $exp = (new \ReflectionClassConstant(TestClass::class, "REQUIRED"))->getValue(); $this->assertEquals("", $this->l->set("", true)); $this->assertCount(sizeof($exp), $this->l->dump()); } - /** - * @depends testLoadInternalStrings - */ + #[Depends('testLoadInternalStrings')] public function testLoadDefaultLanguage(): void { $this->assertEquals(TestClass::DEFAULT, $this->l->set(TestClass::DEFAULT, true)); $str = $this->l->dump(); @@ -53,9 +50,7 @@ class TestBasic extends \JKingWeb\Arsse\Test\AbstractTest { $this->assertArrayHasKey('Test.presentText', $str); } - /** - * @depends testLoadDefaultLanguage - */ + #[Depends('testLoadDefaultLanguage')] public function testLoadSupplementaryLanguage(): void { $this->l->set(TestClass::DEFAULT, true); $this->assertEquals("ja", $this->l->set("ja", true)); diff --git a/tests/cases/Lang/TestComplex.php b/tests/cases/Lang/TestComplex.php index 326b4878..c300886a 100644 --- a/tests/cases/Lang/TestComplex.php +++ b/tests/cases/Lang/TestComplex.php @@ -1,4 +1,5 @@ assertArrayNotHasKey('Test.absentText', $this->l->dump()); } - /** - * @depends testLazyLoad - */ + #[Depends('testLazyLoad')] public function testGetWantedAndLoadedLocale(): void { $this->l->set("en", true); $this->l->set("ja"); @@ -44,9 +45,7 @@ class TestComplex extends \JKingWeb\Arsse\Test\AbstractTest { $this->assertEquals('und der Stein der Weisen', $str['Test.presentText']); } - /** - * @depends testLoadCascadeOfFiles - */ + #[Depends('testLoadCascadeOfFiles')] public function testLoadSubtag(): void { $this->assertEquals("en_ca", $this->l->set("en_ca", true)); } @@ -56,49 +55,37 @@ class TestComplex extends \JKingWeb\Arsse\Test\AbstractTest { $this->assertEquals('und der Stein der Weisen', $this->l->msg('Test.presentText')); } - /** - * @depends testFetchAMessage - */ + #[Depends('testFetchAMessage')] public function testFetchAMessageWithMissingParameters(): void { $this->l->set("en_ca", true); $this->assertEquals('{0} and {1}', $this->l->msg('Test.presentText')); } - /** - * @depends testFetchAMessage - */ + #[Depends('testFetchAMessage')] public function testFetchAMessageWithSingleNumericParameter(): void { $this->l->set("en_ca", true); $this->assertEquals('Default language file "en" missing', $this->l->msg('Exception.JKingWeb/Arsse/Lang/Exception.defaultFileMissing', TestClass::DEFAULT)); } - /** - * @depends testFetchAMessage - */ + #[Depends('testFetchAMessage')] public function testFetchAMessageWithMultipleNumericParameters(): void { $this->l->set("en_ca", true); $this->assertEquals('Happy Rotter and the Philosopher\'s Stone', $this->l->msg('Test.presentText', ['Happy Rotter', 'the Philosopher\'s Stone'])); } - /** - * @depends testFetchAMessage - */ + #[Depends('testFetchAMessage')] public function testFetchAMessageWithNamedParameters(): void { $this->assertEquals('Message string "Test.absentText" missing from all loaded language files (en)', $this->l->msg('Exception.JKingWeb/Arsse/Lang/Exception.stringMissing', ['msgID' => 'Test.absentText', 'fileList' => 'en'])); } - /** - * @depends testFetchAMessage - */ + #[Depends('testFetchAMessage')] public function testReloadDefaultStrings(): void { $this->l->set("de", true); $this->l->set("en", true); $this->assertEquals('and the Philosopher\'s Stone', $this->l->msg('Test.presentText')); } - /** - * @depends testFetchAMessage - */ + #[Depends('testFetchAMessage')] public function testReloadGeneralTagAfterSubtag(): void { $this->l->set("en", true); $this->l->set("en_us", true); diff --git a/tests/cases/Lang/TestErrors.php b/tests/cases/Lang/TestErrors.php index 3a49ed04..cc2701e6 100644 --- a/tests/cases/Lang/TestErrors.php +++ b/tests/cases/Lang/TestErrors.php @@ -1,4 +1,5 @@ withHeader("Content-Type", $header); $this->assertSame($exp, HTTP::matchType($msg, ...$types)); @@ -36,7 +39,8 @@ class TestHTTP extends \JKingWeb\Arsse\Test\AbstractTest { ]; } - /** @dataProvider provideTypedMessages */ + + #[DataProvider('provideTypedMessages')] public function testCreateResponses(string $type, array $params, ResponseInterface $exp): void { $act = call_user_func(["JKingWeb\\Arsse\\Misc\\HTTP", $type], ...$params); $this->assertMessage($exp, $act); diff --git a/tests/cases/Misc/TestQuery.php b/tests/cases/Misc/TestQuery.php index 95390983..5d830778 100644 --- a/tests/cases/Misc/TestQuery.php +++ b/tests/cases/Misc/TestQuery.php @@ -1,4 +1,5 @@ assertSame("", Rule::prep("")); } - /** @dataProvider provideApplications */ + + #[DataProvider('provideApplications')] public function testApplyRules(string $keepRule, string $blockRule, string $title, array $categories, $exp): void { $keepRule = Rule::prep($keepRule); $blockRule = Rule::prep($blockRule); diff --git a/tests/cases/Misc/TestURL.php b/tests/cases/Misc/TestURL.php index fcacf794..a39a1816 100644 --- a/tests/cases/Misc/TestURL.php +++ b/tests/cases/Misc/TestURL.php @@ -1,4 +1,5 @@ assertSame($exp, URL::normalize($url, $user, $pass)); } @@ -73,7 +76,8 @@ class TestURL extends \JKingWeb\Arsse\Test\AbstractTest { ]; } - /** @dataProvider provideQueries */ + + #[DataProvider('provideQueries')] public function testAppendQueryParameters(string $url, string $query, string $exp): void { $this->assertSame($exp, URL::queryAppend($url, $query)); } @@ -89,7 +93,8 @@ class TestURL extends \JKingWeb\Arsse\Test\AbstractTest { ]; } - /** @dataProvider provideAbsolutes */ + + #[DataProvider('provideAbsolutes')] public function testDetermineAbsoluteness(bool $exp, string $url): void { $this->assertSame($exp, URL::absolute($url)); } diff --git a/tests/cases/Misc/TestValueInfo.php b/tests/cases/Misc/TestValueInfo.php index 0bcb4177..8ca9d66d 100644 --- a/tests/cases/Misc/TestValueInfo.php +++ b/tests/cases/Misc/TestValueInfo.php @@ -1,4 +1,5 @@ dispatch($this->serverRequest($method, $url, "")); $this->assertMessage($exp, $act); diff --git a/tests/cases/REST/Miniflux/TestV1.php b/tests/cases/REST/Miniflux/TestV1.php index 609004fa..b5ef43e4 100644 --- a/tests/cases/REST/Miniflux/TestV1.php +++ b/tests/cases/REST/Miniflux/TestV1.php @@ -84,7 +84,7 @@ class TestV1 extends \JKingWeb\Arsse\Test\AbstractTest { \Phake::when(Arsse::$user)->propertiesGet->thenReturn(['num' => 42, 'admin' => false, 'root_folder_name' => null, 'tz' => "Asia/Gaza"]); \Phake::when(Arsse::$user)->begin->thenReturn($this->transaction); //initialize a handler - $this->h = new V1(); + $this->h = new V1; } protected static function v($value) { diff --git a/tests/cases/REST/NextcloudNews/TestVersions.php b/tests/cases/REST/NextcloudNews/TestVersions.php index 908627e3..b14da1ab 100644 --- a/tests/cases/REST/NextcloudNews/TestVersions.php +++ b/tests/cases/REST/NextcloudNews/TestVersions.php @@ -1,4 +1,5 @@ auth->thenReturn(false); @@ -93,7 +97,7 @@ class TestREST extends \JKingWeb\Arsse\Test\AbstractTest { public function testSendAuthenticationChallenges(): void { self::setConf(); - $r = new REST(); + $r = new REST; $in = HTTP::respEmpty(401); $exp = $in->withHeader("WWW-Authenticate", 'Basic realm="OOK", charset="UTF-8"'); $act = $r->challenge($in, "OOK"); @@ -103,9 +107,10 @@ class TestREST extends \JKingWeb\Arsse\Test\AbstractTest { $this->assertMessage($exp, $act); } - /** @dataProvider provideUnnormalizedOrigins */ + + #[DataProvider('provideUnnormalizedOrigins')] public function testNormalizeOrigins(string $origin, string $exp, ?array $ports = null): void { - $r = new REST(); + $r = new REST; $act = $r->corsNormalizeOrigin($origin, $ports); $this->assertSame($exp, $act); } @@ -146,7 +151,8 @@ class TestREST extends \JKingWeb\Arsse\Test\AbstractTest { ]; } - /** @dataProvider provideCorsNegotiations */ + + #[DataProvider('provideCorsNegotiations')] public function testNegotiateCors($origin, bool $exp, ?string $allowed = null, ?string $denied = null): void { self::setConf(); $rMock = \Phake::partialMock(REST::class); @@ -184,9 +190,10 @@ class TestREST extends \JKingWeb\Arsse\Test\AbstractTest { ]; } - /** @dataProvider provideCorsHeaders */ + + #[DataProvider('provideCorsHeaders')] public function testAddCorsHeaders(string $reqMethod, array $reqHeaders, array $resHeaders, array $expHeaders): void { - $r = new REST(); + $r = new REST; $req = new Request($reqMethod, "php://memory", $reqHeaders); $res = HTTP::respEmpty(204, $resHeaders); $exp = HTTP::respEmpty(204, $expHeaders); @@ -248,7 +255,8 @@ class TestREST extends \JKingWeb\Arsse\Test\AbstractTest { ]; } - /** @dataProvider provideUnnormalizedResponses */ + + #[DataProvider('provideUnnormalizedResponses')] public function testNormalizeHttpResponses(ResponseInterface $res, ResponseInterface $exp, ?RequestInterface $req = null): void { $rMock = \Phake::partialMock(REST::class); \Phake::when($rMock)->corsNegotiate->thenReturn(true); @@ -284,7 +292,8 @@ class TestREST extends \JKingWeb\Arsse\Test\AbstractTest { ]; } - /** @dataProvider provideMockRequests */ + + #[DataProvider('provideMockRequests')] public function testDispatchRequests(ServerRequest $req, string $method, bool $called, string $class = "", string $target = ""): void { $rMock = \Phake::partialMock(REST::class); \Phake::when($rMock)->normalizeResponse->thenReturnCallback(function($res) { diff --git a/tests/cases/REST/TinyTinyRSS/TestAPI.php b/tests/cases/REST/TinyTinyRSS/TestAPI.php index 7a27a3fd..9e023fce 100644 --- a/tests/cases/REST/TinyTinyRSS/TestAPI.php +++ b/tests/cases/REST/TinyTinyRSS/TestAPI.php @@ -147,7 +147,7 @@ LONG_STRING; 'expires' => "2112-12-21 21:12:00", 'user' => self::$userId, ]); - $this->h = new API(); + $this->h = new API; } protected function req($data, string $method = "POST", string $target = "", ?string $strData = null, ?string $user = null): ResponseInterface { diff --git a/tests/cases/REST/TinyTinyRSS/TestIcon.php b/tests/cases/REST/TinyTinyRSS/TestIcon.php index 359de9ad..72184d78 100644 --- a/tests/cases/REST/TinyTinyRSS/TestIcon.php +++ b/tests/cases/REST/TinyTinyRSS/TestIcon.php @@ -26,7 +26,7 @@ class TestIcon extends \JKingWeb\Arsse\Test\AbstractTest { Arsse::$user = \Phake::mock(User::class); // create a mock database interface Arsse::$db = \Phake::mock(Database::class); - $this->h = new Icon(); + $this->h = new Icon; } protected function req(string $target, string $method = "GET", ?string $user = null): ResponseInterface { diff --git a/tests/cases/REST/TinyTinyRSS/TestSearch.php b/tests/cases/REST/TinyTinyRSS/TestSearch.php index 3c95ef84..24739672 100644 --- a/tests/cases/REST/TinyTinyRSS/TestSearch.php +++ b/tests/cases/REST/TinyTinyRSS/TestSearch.php @@ -1,4 +1,5 @@ assertEquals($exp, $act); diff --git a/tests/cases/Service/TestDaemon.php b/tests/cases/Service/TestDaemon.php index cace0aa7..0604d51d 100644 --- a/tests/cases/Service/TestDaemon.php +++ b/tests/cases/Service/TestDaemon.php @@ -1,4 +1,5 @@ [ @@ -47,7 +51,8 @@ class TestDaemon extends \JKingWeb\Arsse\Test\AbstractTest { $this->daemon = \Phake::partialMock(Daemon::class); } - /** @dataProvider providePathResolutions */ + + #[DataProvider('providePathResolutions')] public function testResolveRelativePaths(string $path, $cwd, $exp): void { // set up mock daemon class \Phake::when($this->daemon)->cwd->thenReturn($cwd); @@ -73,7 +78,8 @@ class TestDaemon extends \JKingWeb\Arsse\Test\AbstractTest { ]; } - /** @dataProvider providePidFileChecks */ + + #[DataProvider('providePidFileChecks')] public function testCheckPidFiles(string $file, bool $accessible, $exp): void { $vfs = vfsStream::setup("pidtest", 0777, $this->pidfiles); $path = $vfs->url()."/"; @@ -109,7 +115,8 @@ class TestDaemon extends \JKingWeb\Arsse\Test\AbstractTest { ]; } - /** @dataProvider providePidReadChecks */ + + #[DataProvider('providePidReadChecks')] public function testCheckPidReads(string $file, $exp) { $vfs = vfsStream::setup("pidtest", 0777, $this->pidfiles); $path = $vfs->url()."/pid/"; @@ -155,10 +162,8 @@ class TestDaemon extends \JKingWeb\Arsse\Test\AbstractTest { ]; } - /** - * @dataProvider providePidWriteChecks - * @requires extension posix - */ + #[DataProvider('providePidWriteChecks')] + #[RequiresPhpExtension('posix')] public function testCheckPidWrites(string $file, $exp) { $pid = (string) posix_getpid(); $vfs = vfsStream::setup("pidtest", 0777, $this->pidfiles); diff --git a/tests/cases/Service/TestSerial.php b/tests/cases/Service/TestSerial.php index 9321b5a2..cef2f9a8 100644 --- a/tests/cases/Service/TestSerial.php +++ b/tests/cases/Service/TestSerial.php @@ -1,4 +1,5 @@ srv = new Service(); + $this->srv = new Service; } public function testCheckIn(): void { diff --git a/tests/cases/Service/TestSubprocess.php b/tests/cases/Service/TestSubprocess.php index 94d1ce25..a2c6215a 100644 --- a/tests/cases/Service/TestSubprocess.php +++ b/tests/cases/Service/TestSubprocess.php @@ -1,4 +1,5 @@ assertInstanceOf(User::class, Arsse::$user); } - /** @dataProvider provideExtensionChecks */ + + #[DataProvider('provideExtensionChecks')] public function testCheckForExtensions(array $ext, $exp): void { if ($exp instanceof \Exception) { $this->assertException($exp); diff --git a/tests/cases/User/TestInternal.php b/tests/cases/User/TestInternal.php index 04570525..47cca000 100644 --- a/tests/cases/User/TestInternal.php +++ b/tests/cases/User/TestInternal.php @@ -1,4 +1,5 @@ assertTrue(strlen(Driver::driverName()) > 0); } - /** - * @dataProvider provideAuthentication - * @group slow - */ + #[DataProvider('provideAuthentication')] + #[Group('slow')] public function testAuthenticateAUser(string $user, $password, bool $exp): void { \Phake::when(Arsse::$db)->userPasswordGet("john.doe@example.com")->thenReturn('$2y$10$1zbqRJhxM8uUjeSBPp4IhO90xrqK0XjEh9Z16iIYEFRV4U.zeAFom'); // hash of "secret" \Phake::when(Arsse::$db)->userPasswordGet("jane.doe@example.com")->thenReturn('$2y$10$bK1ljXfTSyc2D.NYvT.Eq..OpehLRXVbglW.23ihVuyhgwJCd.7Im'); // hash of "superman" diff --git a/tests/cases/User/TestUser.php b/tests/cases/User/TestUser.php index 5a1be7d5..61f021eb 100644 --- a/tests/cases/User/TestUser.php +++ b/tests/cases/User/TestUser.php @@ -1,4 +1,5 @@ assertNotEquals($pass1, $pass2); } - /** @dataProvider provideAuthentication */ + + #[DataProvider('provideAuthentication')] public function testAuthenticateAUser(bool $preAuth, string $user, string $password, bool $exp): void { Arsse::$conf->userPreAuth = $preAuth; \Phake::when($this->drv)->auth->thenReturn(false); @@ -156,7 +160,8 @@ class TestUser extends \JKingWeb\Arsse\Test\AbstractTest { } } - /** @dataProvider provideInvalidUserNames */ + + #[DataProvider('provideInvalidUserNames')] public function testAddAnInvalidUser(string $user): void { $u = new User($this->drv); $this->assertException("invalidUsername", "User", "ExceptionInput"); @@ -240,7 +245,8 @@ class TestUser extends \JKingWeb\Arsse\Test\AbstractTest { \Phake::verify($this->drv)->userRename($old, $old); } - /** @dataProvider provideInvalidUserNames */ + + #[DataProvider('provideInvalidUserNames')] public function testRenameAUserToAnInvalidName(string $new): void { $u = new User($this->drv); $this->assertException("invalidUsername", "User", "ExceptionInput"); @@ -405,7 +411,8 @@ class TestUser extends \JKingWeb\Arsse\Test\AbstractTest { } } - /** @dataProvider provideProperties */ + + #[DataProvider('provideProperties')] public function testGetThePropertiesOfAUser(array $exp, array $base, array $extra): void { $user = "john.doe@example.com"; $exp = array_merge(['num' => null], array_combine(array_keys(User::PROPERTIES), array_fill(0, sizeof(User::PROPERTIES), null)), $exp); @@ -460,7 +467,8 @@ class TestUser extends \JKingWeb\Arsse\Test\AbstractTest { } } - /** @dataProvider providePropertyChanges */ + + #[DataProvider('providePropertyChanges')] public function testSetThePropertiesOfAUser(array $in, $out): void { $user = "john.doe@example.com"; if ($out instanceof \Exception) { @@ -479,7 +487,8 @@ class TestUser extends \JKingWeb\Arsse\Test\AbstractTest { } } - /** @dataProvider providePropertyChanges */ + + #[DataProvider('providePropertyChanges')] public function testSetThePropertiesOfAUserWeDoNotKnow(array $in, $out): void { $user = "john.doe@example.com"; if ($out instanceof \Exception) { diff --git a/tests/lib/AbstractTest.php b/tests/lib/AbstractTest.php index 27f27585..427f9c50 100644 --- a/tests/lib/AbstractTest.php +++ b/tests/lib/AbstractTest.php @@ -1,4 +1,5 @@ get->thenReturnCallback(function(string $class) { - return new $class; + return new $class(); }); } diff --git a/tests/lib/Database.php b/tests/lib/Database.php index 4949a227..8b501553 100644 --- a/tests/lib/Database.php +++ b/tests/lib/Database.php @@ -1,4 +1,5 @@ report_mode = \MYSQLI_REPORT_OFF; $d = mysqli_init(); $d->options(\MYSQLI_OPT_INT_AND_FLOAT_NATIVE, false); diff --git a/tests/lib/DatabaseDrivers/MySQLCommon.php b/tests/lib/DatabaseDrivers/MySQLCommon.php index e2a43cc3..50c16872 100644 --- a/tests/lib/DatabaseDrivers/MySQLCommon.php +++ b/tests/lib/DatabaseDrivers/MySQLCommon.php @@ -1,4 +1,5 @@