Tests: verify that ItemTypeIds/BlockTypeIds constants match their corresponding VanillaItems/VanillaBlocks registrations

This commit is contained in:
Dylan K. Taylor 2023-06-09 15:49:10 +01:00
parent 64c1776910
commit ab8386ed5a
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
2 changed files with 25 additions and 0 deletions

View File

@ -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");
}
}
}

View File

@ -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");
}
}
}