diff --git a/tests/phpunit/block/BrewingStandTest.php b/tests/phpunit/block/BrewingStandTest.php index 85cdd90e11..d363263447 100644 --- a/tests/phpunit/block/BrewingStandTest.php +++ b/tests/phpunit/block/BrewingStandTest.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace pocketmine\block; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use pocketmine\block\utils\BrewingStandSlot; use function count; @@ -39,11 +40,10 @@ class BrewingStandTest extends TestCase{ } /** - * @dataProvider slotsProvider - * * @param BrewingStandSlot[] $slots * @phpstan-param list $slots */ + #[DataProvider("slotsProvider")] public function testHasAndSetSlot(array $slots) : void{ $block = VanillaBlocks::BREWING_STAND(); foreach($slots as $slot){ @@ -62,11 +62,10 @@ class BrewingStandTest extends TestCase{ } /** - * @dataProvider slotsProvider - * * @param BrewingStandSlot[] $slots * @phpstan-param list $slots */ + #[DataProvider("slotsProvider")] public function testGetSlots(array $slots) : void{ $block = VanillaBlocks::BREWING_STAND(); @@ -83,11 +82,10 @@ class BrewingStandTest extends TestCase{ } /** - * @dataProvider slotsProvider - * * @param BrewingStandSlot[] $slots * @phpstan-param list $slots */ + #[DataProvider("slotsProvider")] public function testSetSlots(array $slots) : void{ $block = VanillaBlocks::BREWING_STAND(); diff --git a/tests/phpunit/command/utils/CommandStringHelperTest.php b/tests/phpunit/command/utils/CommandStringHelperTest.php index 047dc7cebd..01a869ad70 100644 --- a/tests/phpunit/command/utils/CommandStringHelperTest.php +++ b/tests/phpunit/command/utils/CommandStringHelperTest.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace pocketmine\command\utils; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class CommandStringHelperTest extends TestCase{ @@ -47,9 +48,9 @@ class CommandStringHelperTest extends TestCase{ } /** - * @dataProvider parseQuoteAwareProvider * @param string[] $expected */ + #[DataProvider("parseQuoteAwareProvider")] public function testParseQuoteAware(string $commandLine, array $expected) : void{ $actual = CommandStringHelper::parseQuoteAware($commandLine); diff --git a/tests/phpunit/console/ConsoleReaderChildProcessUtilsTest.php b/tests/phpunit/console/ConsoleReaderChildProcessUtilsTest.php index 31ae2e27a4..5b92098613 100644 --- a/tests/phpunit/console/ConsoleReaderChildProcessUtilsTest.php +++ b/tests/phpunit/console/ConsoleReaderChildProcessUtilsTest.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace pocketmine\console; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use function mt_rand; use function str_repeat; @@ -40,9 +41,7 @@ final class ConsoleReaderChildProcessUtilsTest extends TestCase{ yield ["give \"Steve\" golden_apple"]; } - /** - * @dataProvider commandStringProvider - */ + #[DataProvider("commandStringProvider")] public function testCreateParseSymmetry(string $input) : void{ $counterCreate = $counterParse = mt_rand(); $message = ConsoleReaderChildProcessUtils::createMessage($input, $counterCreate); @@ -74,9 +73,7 @@ final class ConsoleReaderChildProcessUtilsTest extends TestCase{ yield ["a" . ConsoleReaderChildProcessUtils::TOKEN_DELIMITER . "b", false]; //message with delimiter but not a valid IPC message } - /** - * @dataProvider parseMessageProvider - */ + #[DataProvider("parseMessageProvider")] public static function testParseMessage(string $message, bool $valid) : void{ $counter = $oldCounter = 0; diff --git a/tests/phpunit/data/bedrock/block/upgrade/BlockStateUpgraderTest.php b/tests/phpunit/data/bedrock/block/upgrade/BlockStateUpgraderTest.php index 91afd8ed92..9f4416a085 100644 --- a/tests/phpunit/data/bedrock/block/upgrade/BlockStateUpgraderTest.php +++ b/tests/phpunit/data/bedrock/block/upgrade/BlockStateUpgraderTest.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace pocketmine\data\bedrock\block\upgrade; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use pocketmine\block\Block; use pocketmine\data\bedrock\block\BlockStateData; @@ -126,9 +127,9 @@ class BlockStateUpgraderTest extends TestCase{ } /** - * @dataProvider removePropertyProvider * @phpstan-param \Closure() : BlockStateData $getStateData */ + #[DataProvider("removePropertyProvider")] public function testRemoveProperty(\Closure $getStateData) : void{ $this->prepareRemovePropertySchema($this->getNewSchema()); @@ -151,9 +152,9 @@ class BlockStateUpgraderTest extends TestCase{ } /** - * @dataProvider renamePropertyProvider * @phpstan-param \Closure() : BlockStateData $getStateData */ + #[DataProvider("renamePropertyProvider")] public function testRenameProperty(\Closure $getStateData, ?int $valueAfter) : void{ $this->prepareRenamePropertySchema($this->getNewSchema()); @@ -187,9 +188,9 @@ class BlockStateUpgraderTest extends TestCase{ } /** - * @dataProvider remapPropertyValueProvider * @phpstan-param \Closure() : BlockStateData $getStateData */ + #[DataProvider("remapPropertyValueProvider")] public function testRemapPropertyValue(\Closure $getStateData, ?int $valueAfter) : void{ $this->prepareRemapPropertyValueSchema($this->getNewSchema()); @@ -199,9 +200,9 @@ class BlockStateUpgraderTest extends TestCase{ } /** - * @dataProvider remapPropertyValueProvider * @phpstan-param \Closure() : BlockStateData $getStateData */ + #[DataProvider("remapPropertyValueProvider")] public function testRemapAndRenameProperty(\Closure $getStateData, ?int $valueAfter) : void{ $schema = $this->getNewSchema(); $this->prepareRenamePropertySchema($schema); @@ -239,9 +240,7 @@ class BlockStateUpgraderTest extends TestCase{ yield [0x1_00_00_00, 0x1_00_01_00, false, 1]; //Block newer than schema: block must NOT be altered } - /** - * @dataProvider upgraderVersionCompatibilityProvider - */ + #[DataProvider("upgraderVersionCompatibilityProvider")] public function testUpgraderVersionCompatibility(int $schemaVersion, int $stateVersion, bool $shouldChange, int $schemaCount) : void{ for($i = 0; $i < $schemaCount; $i++){ $schema = $this->getNewSchemaVersion($schemaVersion, $i); diff --git a/tests/phpunit/event/HandlerListManagerTest.php b/tests/phpunit/event/HandlerListManagerTest.php index c61043dab8..9a3c8e505e 100644 --- a/tests/phpunit/event/HandlerListManagerTest.php +++ b/tests/phpunit/event/HandlerListManagerTest.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace pocketmine\event; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use pocketmine\event\fixtures\TestAbstractAllowHandleEvent; use pocketmine\event\fixtures\TestAbstractEvent; @@ -63,10 +64,9 @@ class HandlerListManagerTest extends TestCase{ } /** - * @dataProvider isValidClassProvider - * * @phpstan-param \ReflectionClass $class */ + #[DataProvider("isValidClassProvider")] public function testIsValidClass(\ReflectionClass $class, bool $isValid, string $reason) : void{ self::assertSame($isValid, ($this->isValidFunc)($class), $reason); } @@ -83,11 +83,10 @@ class HandlerListManagerTest extends TestCase{ } /** - * @dataProvider resolveParentClassProvider - * * @phpstan-param \ReflectionClass $class * @phpstan-param \ReflectionClass|null $expect */ + #[DataProvider("resolveParentClassProvider")] public function testResolveParentClass(\ReflectionClass $class, ?\ReflectionClass $expect) : void{ if($expect === null){ self::assertNull(($this->resolveParentFunc)($class)); diff --git a/tests/phpunit/item/LegacyStringToItemParserTest.php b/tests/phpunit/item/LegacyStringToItemParserTest.php index f9243df7e3..78f9e16b39 100644 --- a/tests/phpunit/item/LegacyStringToItemParserTest.php +++ b/tests/phpunit/item/LegacyStringToItemParserTest.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace pocketmine\item; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use pocketmine\block\VanillaBlocks; @@ -43,9 +44,7 @@ class LegacyStringToItemParserTest extends TestCase{ ]; } - /** - * @dataProvider itemFromStringProvider - */ + #[DataProvider("itemFromStringProvider")] public function testFromStringSingle(string $string, Item $expected) : void{ $item = LegacyStringToItemParser::getInstance()->parse($string); diff --git a/tests/phpunit/network/mcpe/convert/BlockTranslatorTest.php b/tests/phpunit/network/mcpe/convert/BlockTranslatorTest.php index ef8e297c44..864acbfebc 100644 --- a/tests/phpunit/network/mcpe/convert/BlockTranslatorTest.php +++ b/tests/phpunit/network/mcpe/convert/BlockTranslatorTest.php @@ -23,14 +23,13 @@ declare(strict_types=1); namespace pocketmine\network\mcpe\convert; +use PHPUnit\Framework\Attributes\DoesNotPerformAssertions; use PHPUnit\Framework\TestCase; use pocketmine\block\RuntimeBlockStateRegistry; class BlockTranslatorTest extends TestCase{ - /** - * @doesNotPerformAssertions - */ + #[DoesNotPerformAssertions] public function testAllBlockStatesSerialize() : void{ $blockTranslator = TypeConverter::getInstance()->getBlockTranslator(); foreach(RuntimeBlockStateRegistry::getInstance()->getAllKnownStates() as $state){ diff --git a/tests/phpunit/plugin/ApiVersionTest.php b/tests/phpunit/plugin/ApiVersionTest.php index faa68200de..55afdbc73a 100644 --- a/tests/phpunit/plugin/ApiVersionTest.php +++ b/tests/phpunit/plugin/ApiVersionTest.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace pocketmine\plugin; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use function sort; @@ -47,9 +48,7 @@ class ApiVersionTest extends TestCase{ yield ["3.0.0-ALPHA1", "4.0.0-ALPHA1", false]; } - /** - * @dataProvider compatibleApiProvider - */ + #[DataProvider("compatibleApiProvider")] public function testCompatibleApi(string $myVersion, string $wantVersion, bool $expected) : void{ self::assertSame($expected, ApiVersion::isCompatible($myVersion, [$wantVersion]), "my version: $myVersion, their version: $wantVersion, expect " . ($expected ? "yes" : "no")); } @@ -67,11 +66,10 @@ class ApiVersionTest extends TestCase{ } /** - * @dataProvider ambiguousVersionsProvider - * * @param string[] $input * @param string[] $expectedOutput */ + #[DataProvider("ambiguousVersionsProvider")] public function testFindAmbiguousVersions(array $input, array $expectedOutput) : void{ $ambiguous = ApiVersion::checkAmbiguousVersions($input); diff --git a/tests/phpunit/scheduler/AsyncPoolTest.php b/tests/phpunit/scheduler/AsyncPoolTest.php index 0f2e8554d4..5f026c2439 100644 --- a/tests/phpunit/scheduler/AsyncPoolTest.php +++ b/tests/phpunit/scheduler/AsyncPoolTest.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace pocketmine\scheduler; +use PHPUnit\Framework\Attributes\DoesNotPerformAssertions; use PHPUnit\Framework\TestCase; use pmmp\thread\ThreadSafeArray; use pocketmine\promise\PromiseResolver; @@ -84,9 +85,8 @@ class AsyncPoolTest extends TestCase{ * * Due to an unset() in the function body, other AsyncTask::__destruct() calls could be triggered during * an AsyncTask's destruction. If done in the wrong way, this could lead to a crash. - * - * @doesNotPerformAssertions This test is checking for a crash condition, not a specific output. */ + #[DoesNotPerformAssertions] public function testTaskDestructorReentrancy() : void{ $this->pool->submitTask(new class extends AsyncTask{ public function __construct(){ diff --git a/tests/phpunit/utils/CloningRegistryTraitTest.php b/tests/phpunit/utils/CloningRegistryTraitTest.php index e3b53ecb56..a343d0033c 100644 --- a/tests/phpunit/utils/CloningRegistryTraitTest.php +++ b/tests/phpunit/utils/CloningRegistryTraitTest.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace pocketmine\utils; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; final class CloningRegistryTraitTest extends TestCase{ @@ -37,9 +38,9 @@ final class CloningRegistryTraitTest extends TestCase{ } /** - * @dataProvider cloningRegistryMembersProvider * @phpstan-param \Closure() : \stdClass $provider */ + #[DataProvider("cloningRegistryMembersProvider")] public function testEachMemberClone(\Closure $provider) : void{ self::assertNotSame($provider(), $provider(), "Cloning registry should never return the same object twice"); } diff --git a/tests/phpunit/utils/ConfigTest.php b/tests/phpunit/utils/ConfigTest.php index 55b4bc2d49..102a8dcf72 100644 --- a/tests/phpunit/utils/ConfigTest.php +++ b/tests/phpunit/utils/ConfigTest.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace pocketmine\utils; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use function yaml_parse; @@ -60,10 +61,9 @@ class ConfigTest extends TestCase{ } /** - * @dataProvider fixYamlIndexesProvider - * * @param mixed[] $expected */ + #[DataProvider("fixYamlIndexesProvider")] public function testFixYamlIndexes(string $test, array $expected) : void{ $fixed = Config::fixYAMLIndexes($test); $decoded = yaml_parse($fixed); diff --git a/tests/phpunit/utils/UtilsTest.php b/tests/phpunit/utils/UtilsTest.php index f061abac27..96254ca010 100644 --- a/tests/phpunit/utils/UtilsTest.php +++ b/tests/phpunit/utils/UtilsTest.php @@ -23,6 +23,8 @@ declare(strict_types=1); namespace pocketmine\utils; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\DoesNotPerformAssertions; use PHPUnit\Framework\TestCase; use pocketmine\utils\fixtures\TestAbstractClass; use pocketmine\utils\fixtures\TestInstantiableClass; @@ -52,9 +54,7 @@ class UtilsTest extends TestCase{ ]; } - /** - * @dataProvider parseDocCommentNewlineProvider - */ + #[DataProvider("parseDocCommentNewlineProvider")] public function testParseDocCommentNewlines(string $docComment) : void{ $tags = Utils::parseDocComment($docComment); @@ -76,9 +76,7 @@ class UtilsTest extends TestCase{ ]; } - /** - * @dataProvider parseDocCommentOneLineProvider - */ + #[DataProvider("parseDocCommentOneLineProvider")] public function testParseOneLineDocComment(string $comment) : void{ $tags = Utils::parseDocComment($comment); self::assertArrayHasKey("ignoreCancelled", $tags); @@ -120,11 +118,11 @@ class UtilsTest extends TestCase{ } /** - * @dataProvider validInstanceProvider - * @doesNotPerformAssertions * @phpstan-param class-string $className * @phpstan-param class-string $baseName */ + #[DataProvider("validInstanceProvider")] + #[DoesNotPerformAssertions] public function testValidInstanceWithValidCombinations(string $className, string $baseName) : void{ Utils::testValidInstance($className, $baseName); } @@ -146,9 +144,7 @@ class UtilsTest extends TestCase{ ]; } - /** - * @dataProvider validInstanceInvalidCombinationsProvider - */ + #[DataProvider("validInstanceInvalidCombinationsProvider")] public function testValidInstanceInvalidParameters(string $className, string $baseName) : void{ $this->expectException(\InvalidArgumentException::class); Utils::testValidInstance($className, $baseName); //@phpstan-ignore-line diff --git a/tests/phpunit/world/format/io/region/RegionLoaderTest.php b/tests/phpunit/world/format/io/region/RegionLoaderTest.php index ee96b6bc05..6d715867d9 100644 --- a/tests/phpunit/world/format/io/region/RegionLoaderTest.php +++ b/tests/phpunit/world/format/io/region/RegionLoaderTest.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace pocketmine\world\format\io\region; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use pocketmine\world\format\ChunkException; use Symfony\Component\Filesystem\Path; @@ -82,11 +83,10 @@ class RegionLoaderTest extends TestCase{ } /** - * @dataProvider outOfBoundsCoordsProvider - * * @throws ChunkException * @throws \InvalidArgumentException */ + #[DataProvider("outOfBoundsCoordsProvider")] public function testWriteChunkOutOfBounds(int $x, int $z) : void{ $this->expectException(\InvalidArgumentException::class); $this->region->writeChunk($x, $z, str_repeat("\x00", 1000)); @@ -107,11 +107,10 @@ class RegionLoaderTest extends TestCase{ } /** - * @dataProvider outOfBoundsCoordsProvider - * * @throws \InvalidArgumentException * @throws \pocketmine\world\format\io\exception\CorruptedChunkException */ + #[DataProvider("outOfBoundsCoordsProvider")] public function testReadChunkOutOfBounds(int $x, int $z) : void{ $this->expectException(\InvalidArgumentException::class); $this->region->readChunk($x, $z); diff --git a/tests/phpunit/world/format/io/region/RegionLocationTableEntryTest.php b/tests/phpunit/world/format/io/region/RegionLocationTableEntryTest.php index 498e2767e3..7aa67fabc9 100644 --- a/tests/phpunit/world/format/io/region/RegionLocationTableEntryTest.php +++ b/tests/phpunit/world/format/io/region/RegionLocationTableEntryTest.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace pocketmine\world\format\io\region; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use function sprintf; @@ -40,9 +41,7 @@ class RegionLocationTableEntryTest extends TestCase{ yield [new RegionLocationTableEntry(2, 4, 0), new RegionLocationTableEntry(3, 1, 0), true]; } - /** - * @dataProvider overlapDataProvider - */ + #[DataProvider("overlapDataProvider")] public function testOverlap(RegionLocationTableEntry $entry1, RegionLocationTableEntry $entry2, bool $overlaps) : void{ $stringify = function(RegionLocationTableEntry $entry) : string{ return sprintf("entry first=%d last=%d size=%d", $entry->getFirstSector(), $entry->getLastSector(), $entry->getSectorCount());