Added tests for BlockTypeIds and ItemTypeIds

This commit is contained in:
Dylan K. Taylor 2022-07-24 21:57:51 +01:00
parent f4de4bd971
commit 6ba3b39541
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
2 changed files with 92 additions and 0 deletions

View File

@ -0,0 +1,46 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\block;
use PHPUnit\Framework\TestCase;
use function array_unique;
use function max;
class BlockTypeIdsTest extends TestCase{
public function testFirstUnused() : void{
$reflect = new \ReflectionClass(BlockTypeIds::class);
$constants = $reflect->getConstants();
unset($constants['FIRST_UNUSED_BLOCK_ID']);
self::assertSame($reflect->getConstant('FIRST_UNUSED_BLOCK_ID'), max($constants) + 1, "FIRST_UNUSED_BLOCK_ID must be one higher than the highest fixed type ID");
}
public function testNoDuplicates() : void{
$idTable = (new \ReflectionClass(BlockTypeIds::class))->getConstants();
self::assertSameSize($idTable, array_unique($idTable), "Every BlockTypeID must be unique");
}
}

View File

@ -0,0 +1,46 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\item;
use PHPUnit\Framework\TestCase;
use function array_unique;
use function max;
class ItemTypeIdsTest extends TestCase{
public function testFirstUnused() : void{
$reflect = new \ReflectionClass(ItemTypeIds::class);
$constants = $reflect->getConstants();
unset($constants['FIRST_UNUSED_ITEM_ID']);
self::assertSame($reflect->getConstant('FIRST_UNUSED_ITEM_ID'), max($constants) + 1, "FIRST_UNUSED_ITEM_ID must be one higher than the highest fixed type ID");
}
public function testNoDuplicates() : void{
$idTable = (new \ReflectionClass(ItemTypeIds::class))->getConstants();
self::assertSameSize($idTable, array_unique($idTable), "Every ItemTypeID must be unique");
}
}