Test all known blockstates, not just the ones found in VanillaBlocks

VanillaBlocks isn't guaranteed to be a complete record. For example, I've considered moving chemistry blocks to a separate EducationBlocks registry.
In such a case, the blocks are still expected to serialize correctly, but they won't be in VanillaBlocks.
This commit is contained in:
Dylan K. Taylor 2022-05-12 16:45:44 +01:00
parent 4c03aabe0f
commit d17032dd8c
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -5,7 +5,7 @@ declare(strict_types=1);
namespace pocketmine\data\bedrock\blockstate\convert; namespace pocketmine\data\bedrock\blockstate\convert;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use pocketmine\block\VanillaBlocks; use pocketmine\block\BlockFactory;
final class BlockSerializerDeserializerTest extends TestCase{ final class BlockSerializerDeserializerTest extends TestCase{
private BlockStateToBlockObjectDeserializer $deserializer; private BlockStateToBlockObjectDeserializer $deserializer;
@ -16,12 +16,12 @@ final class BlockSerializerDeserializerTest extends TestCase{
$this->serializer = new BlockObjectToBlockStateSerializer(); $this->serializer = new BlockObjectToBlockStateSerializer();
} }
public function testAllVanillaBlocksSerializableAndDeserializable() : void{ public function testAllKnownBlockStatesSerializableAndDeserializable() : void{
foreach(VanillaBlocks::getAll() as $block){ foreach(BlockFactory::getInstance()->getAllKnownStates() as $block){
$blockStateData = $this->serializer->serializeBlock($block); $blockStateData = $this->serializer->serializeBlock($block);
$newBlock = $this->deserializer->deserializeBlock($blockStateData); $newBlock = $this->deserializer->deserializeBlock($blockStateData);
self::assertSame($block->getFullId(), $newBlock->getFullId()); self::assertSame($block->getFullId(), $newBlock->getFullId(), "Mismatch of blockstate for " . $block->getName());
} }
} }
} }