From 3840fd54a7f752f1b6fe0d4c18773ce7096b93ad Mon Sep 17 00:00:00 2001 From: mondrake Date: Mon, 28 Oct 2024 21:40:13 +0100 Subject: [PATCH] Cleanup tests from annotations (#86) --- .github/workflows/code-quality.yml | 4 +++- tests/src/MapHandlerTest.php | 11 +---------- tests/src/MapUpdaterTest.php | 18 ++++-------------- tests/src/TypeTest.php | 17 +++-------------- 4 files changed, 11 insertions(+), 39 deletions(-) diff --git a/.github/workflows/code-quality.yml b/.github/workflows/code-quality.yml index 08b5d6fa..ecacd1f8 100644 --- a/.github/workflows/code-quality.yml +++ b/.github/workflows/code-quality.yml @@ -33,7 +33,9 @@ jobs: - name: "Require tools" continue-on-error: true - run: composer require --ansi --dev "vimeo/psalm:^5.15" "phpstan/phpstan:>=1.10" "squizlabs/php_codesniffer:>=3.7" "phpunit/phpunit:>=10" + run: | + composer config --no-plugins allow-plugins.phpstan/extension-installer true + composer require --ansi --dev "vimeo/psalm:^5.15" "phpstan/phpstan:>=1.10" "phpstan/extension-installer:>=1.4" "phpstan/phpstan-phpunit:>=1.4" "squizlabs/php_codesniffer:>=3.7" "phpunit/phpunit:>=10" - name: "Run static analysis with phpstan/phpstan" run: "vendor/bin/phpstan" diff --git a/tests/src/MapHandlerTest.php b/tests/src/MapHandlerTest.php index 462bc094..7309913b 100644 --- a/tests/src/MapHandlerTest.php +++ b/tests/src/MapHandlerTest.php @@ -11,16 +11,10 @@ use PHPUnit\Framework\Attributes\BackupStaticProperties; use PHPUnit\Framework\Attributes\DataProvider; -/** - * @backupStaticAttributes enabled - */ #[BackupStaticProperties(true)] class MapHandlerTest extends MimeMapTestBase { - /** - * @var MimeMapInterface - */ - protected $map; + protected readonly MimeMapInterface $map; public function setUp(): void { @@ -364,9 +358,6 @@ public static function malformedTypeProvider(): array ]; } - /** - * @dataProvider malformedTypeProvider - */ #[DataProvider('malformedTypeProvider')] public function testAddMalformedTypeExtensionMapping(string $type): void { diff --git a/tests/src/MapUpdaterTest.php b/tests/src/MapUpdaterTest.php index 031f3e0f..a814a87d 100644 --- a/tests/src/MapUpdaterTest.php +++ b/tests/src/MapUpdaterTest.php @@ -10,23 +10,13 @@ use PHPUnit\Framework\Attributes\BackupStaticProperties; use PHPUnit\Framework\Attributes\CoversClass; -/** - * @coversDefaultClass \FileEye\MimeMap\MapUpdater - * @backupStaticAttributes enabled - */ #[CoversClass(MapUpdater::class)] #[BackupStaticProperties(true)] class MapUpdaterTest extends MimeMapTestBase { - - /** @var MimeMapInterface */ - protected $newMap; - - /** @var MapUpdater */ - protected $updater; - - /** @var Filesystem */ - protected $fileSystem; + protected readonly MimeMapInterface $newMap; + protected readonly MapUpdater $updater; + protected readonly Filesystem $fileSystem; public function setUp(): void { @@ -152,7 +142,7 @@ public function testLoadMapFromFreedesktopInvalidFile(): void public function testEmptyMapNotWriteable(): void { $this->expectException('LogicException'); - $this->assertNull($this->newMap->getFileName()); + $this->assertSame('', $this->newMap->getFileName()); } public function testWriteMapToPhpClassFile(): void diff --git a/tests/src/TypeTest.php b/tests/src/TypeTest.php index bb74e170..8e8a605b 100644 --- a/tests/src/TypeTest.php +++ b/tests/src/TypeTest.php @@ -424,8 +424,6 @@ public static function parseProvider(): array } /** - * @dataProvider parseProvider - * * @param string $type * @param string[] $expectedToString * @param string[] $expectedMedia @@ -489,9 +487,6 @@ public static function parseMalformedProvider(): array ]; } - /** - * @dataProvider parseMalformedProvider - */ #[DataProvider('parseMalformedProvider')] public function testParseMalformed(string $type): void { @@ -502,10 +497,10 @@ public function testParseMalformed(string $type): void public function testParseAgain(): void { $mt = new Type('application/ogg;description=Hello there!;asd=fgh'); - $this->assertSame(2, count($mt->getParameters())); + $this->assertCount(2, $mt->getParameters()); $mt = new Type('text/plain;hello=there!'); - $this->assertSame(1, count($mt->getParameters())); + $this->assertCount(1, $mt->getParameters()); } public function testGetDescription(): void @@ -536,9 +531,6 @@ public static function missingDescriptionProvider(): array ]; } - /** - * @dataProvider missingDescriptionProvider - */ #[DataProvider('missingDescriptionProvider')] public function testMissingDescription(string $type): void { @@ -730,13 +722,10 @@ public static function getDefaultExtensionFailProvider() ]; } - /** - * @dataProvider getDefaultExtensionFailProvider - */ #[DataProvider('getDefaultExtensionFailProvider')] public function testGetDefaultExtensionFail(string $type): void { $this->expectException(MappingException::class); - $this->assertNull((new Type($type))->getDefaultExtension()); + $this->assertSame('', (new Type($type))->getDefaultExtension()); } }