LegacyStringToItemParserTest: do not rely on the presence of legacy ID and meta in the API

This commit is contained in:
Dylan K. Taylor 2022-06-30 16:39:50 +01:00
parent cab56b0479
commit f8547ad57c
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -24,31 +24,31 @@ declare(strict_types=1);
namespace pocketmine\item; namespace pocketmine\item;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use pocketmine\block\VanillaBlocks;
class LegacyStringToItemParserTest extends TestCase{ class LegacyStringToItemParserTest extends TestCase{
/** /**
* @return mixed[][] * @return mixed[][]
* @phpstan-return list<array{string,int,int}> * @phpstan-return list<array{string,Item}>
*/ */
public function itemFromStringProvider() : array{ public function itemFromStringProvider() : array{
return [ return [
["dye:4", ItemIds::DYE, 4], ["dye:4", VanillaItems::LAPIS_LAZULI()],
["351", ItemIds::DYE, 0], ["351", VanillaItems::INK_SAC()],
["351:4", ItemIds::DYE, 4], ["351:4", VanillaItems::LAPIS_LAZULI()],
["stone:3", ItemIds::STONE, 3], ["stone:3", VanillaBlocks::DIORITE()->asItem()],
["minecraft:string", ItemIds::STRING, 0], ["minecraft:string", VanillaItems::STRING()],
["diamond_pickaxe", ItemIds::DIAMOND_PICKAXE, 0] ["diamond_pickaxe", VanillaItems::DIAMOND_PICKAXE()]
]; ];
} }
/** /**
* @dataProvider itemFromStringProvider * @dataProvider itemFromStringProvider
*/ */
public function testFromStringSingle(string $string, int $id, int $meta) : void{ public function testFromStringSingle(string $string, Item $expected) : void{
$item = LegacyStringToItemParser::getInstance()->parse($string); $item = LegacyStringToItemParser::getInstance()->parse($string);
self::assertEquals($id, $item->getId()); self::assertTrue($item->equals($expected));
self::assertEquals($meta, $item->getMeta());
} }
} }