From 6ab2fa84da4631f63c8ae639be0c172ecfa52fdb Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 17 Jul 2018 14:52:47 +0100 Subject: [PATCH] added some tests for ItemFactory::fromString() --- tests/phpunit/item/ItemTest.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/phpunit/item/ItemTest.php b/tests/phpunit/item/ItemTest.php index 2cb2b975d..f1be994f3 100644 --- a/tests/phpunit/item/ItemTest.php +++ b/tests/phpunit/item/ItemTest.php @@ -51,4 +51,29 @@ class ItemTest extends TestCase{ self::assertEquals(BlockFactory::isRegistered($id), ItemFactory::isRegistered($id)); } } + + public function itemFromStringProvider() : array{ + return [ + ["dye:4", ItemIds::DYE, 4], + ["351", ItemIds::DYE, 0], + ["351:4", ItemIds::DYE, 4], + ["stone:3", ItemIds::STONE, 3], + ["minecraft:string", ItemIds::STRING, 0], + ["diamond_pickaxe", ItemIds::DIAMOND_PICKAXE, 0], + ["diamond_pickaxe:5", ItemIds::DIAMOND_PICKAXE, 5] + ]; + } + + /** + * @dataProvider itemFromStringProvider + * @param string $string + * @param int $id + * @param int $meta + */ + public function testFromStringSingle(string $string, int $id, int $meta) : void{ + $item = ItemFactory::fromString($string); + + self::assertEquals($id, $item->getId()); + self::assertEquals($meta, $item->getDamage()); + } }