From ab8386ed5a49c71960f6fdd3e49fea4f7c338b7d Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 9 Jun 2023 15:49:10 +0100 Subject: [PATCH] Tests: verify that ItemTypeIds/BlockTypeIds constants match their corresponding VanillaItems/VanillaBlocks registrations --- tests/phpunit/block/BlockTypeIdsTest.php | 11 +++++++++++ tests/phpunit/item/ItemTypeIdsTest.php | 14 ++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/tests/phpunit/block/BlockTypeIdsTest.php b/tests/phpunit/block/BlockTypeIdsTest.php index 5d38c740a..32c8d4902 100644 --- a/tests/phpunit/block/BlockTypeIdsTest.php +++ b/tests/phpunit/block/BlockTypeIdsTest.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\block; use PHPUnit\Framework\TestCase; +use pocketmine\utils\Utils; use function array_unique; use function max; @@ -43,4 +44,14 @@ class BlockTypeIdsTest extends TestCase{ self::assertSameSize($idTable, array_unique($idTable), "Every BlockTypeID must be unique"); } + + public function testVanillaBlocksParity() : void{ + $reflect = new \ReflectionClass(BlockTypeIds::class); + + foreach(Utils::stringifyKeys(VanillaBlocks::getAll()) as $name => $block){ + $expected = $block->getTypeId(); + $actual = $reflect->getConstant($name); + self::assertSame($expected, $actual, "VanillaBlocks::$name() does not match BlockTypeIds::$name"); + } + } } diff --git a/tests/phpunit/item/ItemTypeIdsTest.php b/tests/phpunit/item/ItemTypeIdsTest.php index a5394bcbb..7ac8485fc 100644 --- a/tests/phpunit/item/ItemTypeIdsTest.php +++ b/tests/phpunit/item/ItemTypeIdsTest.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\item; use PHPUnit\Framework\TestCase; +use pocketmine\utils\Utils; use function array_unique; use function max; @@ -43,4 +44,17 @@ class ItemTypeIdsTest extends TestCase{ self::assertSameSize($idTable, array_unique($idTable), "Every ItemTypeID must be unique"); } + + public function testVanillaItemsParity() : void{ + $reflect = new \ReflectionClass(ItemTypeIds::class); + + foreach(Utils::stringifyKeys(VanillaItems::getAll()) as $name => $item){ + if($item instanceof ItemBlock){ + continue; + } + $expected = $item->getTypeId(); + $actual = $reflect->getConstant($name); + self::assertSame($expected, $actual, "VanillaItems::$name() type ID does not match ItemTypeIds::$name"); + } + } }