Check consistency of block remaps

This commit is contained in:
Dylan K. Taylor
2021-06-21 20:30:27 +01:00
parent 85ee628a74
commit 2a6009f8bf
4 changed files with 46 additions and 12 deletions

View File

@ -145,14 +145,26 @@ class BlockTest extends TestCase{
public function testConsistency() : void{
$list = json_decode(file_get_contents(__DIR__ . '/block_factory_consistency_check.json'), true);
$knownStates = $list["knownStates"];
$remaps = $list["remaps"];
$states = $this->blockFactory->getAllKnownStates();
foreach($states as $k => $state){
self::assertArrayHasKey($k, $list, "New block state $k (" . $state->getName() . ") - consistency check may need regenerating");
self::assertSame($list[$k], $state->getName());
if($state->getFullId() !== $k){
self::assertArrayHasKey($k, $remaps, "New remap of state $k (" . $state->getName() . ") - consistency check may need regenerating");
self::assertSame($state->getFullId(), $remaps[$k], "Mismatched full IDs of remapped state $k");
}else{
self::assertArrayHasKey($k, $knownStates, "New block state $k (" . $state->getName() . ") - consistency check may need regenerating");
self::assertSame($knownStates[$k], $state->getName());
}
}
foreach($list as $k => $name){
foreach($knownStates as $k => $name){
self::assertArrayHasKey($k, $states, "Missing previously-known block state $k ($name)");
self::assertSame($name, $states[$k]->getName());
}
foreach($remaps as $origin => $destination){
self::assertArrayHasKey($origin, $states, "Missing previously-remapped state $origin");
self::assertSame($destination, $states[$origin]->getFullId());
}
}
}