|
25 | 25 |
|
26 | 26 | use Generator;
|
27 | 27 | use PHPUnit\Framework\TestCase;
|
| 28 | +use pocketmine\item\enchantment\EnchantmentInstance; |
| 29 | +use pocketmine\item\enchantment\VanillaEnchantments; |
28 | 30 | use pocketmine\item\Item;
|
29 | 31 | use pocketmine\item\VanillaItems;
|
30 | 32 | use function floor;
|
31 | 33 |
|
32 | 34 | class AnvilCraftTest extends TestCase{
|
33 |
| - public static function materialRepairRecipe() : Generator{ |
| 35 | + public static function materialRepairRecipeProvider() : Generator{ |
34 | 36 | yield "No repair available" => [
|
35 | 37 | VanillaItems::DIAMOND_PICKAXE(),
|
36 | 38 | VanillaItems::DIAMOND(),
|
@@ -76,29 +78,117 @@ public static function materialRepairRecipe() : Generator{
|
76 | 78 | }
|
77 | 79 |
|
78 | 80 | /**
|
79 |
| - * @dataProvider materialRepairRecipe |
| 81 | + * @dataProvider materialRepairRecipeProvider |
80 | 82 | */
|
81 | 83 | public function testMaterialRepairRecipe(Item $base, Item $material, ?AnvilCraftResult $expected) : void{
|
82 | 84 | $recipe = new MaterialRepairRecipe(
|
83 |
| - new ExactRecipeIngredient((clone $base)->setCount(1)), |
84 |
| - new ExactRecipeIngredient((clone $material)->setCount(1)) |
| 85 | + new WildcardRecipeIngredient(), |
| 86 | + new WildcardRecipeIngredient() |
85 | 87 | );
|
86 |
| - $result = $recipe->getResultFor($base, $material); |
| 88 | + self::assertAnvilCraftResultEquals($expected, $recipe->getResultFor($base, $material)); |
| 89 | + } |
| 90 | + |
| 91 | + public static function itemSelfCombineRecipeProvider() : Generator{ |
| 92 | + yield "Combine two identical items without damage and enchants" => [ |
| 93 | + VanillaItems::DIAMOND_PICKAXE(), |
| 94 | + VanillaItems::DIAMOND_PICKAXE(), |
| 95 | + null |
| 96 | + ]; |
| 97 | + |
| 98 | + yield "Enchant on base item and no enchants on material with no damage" => [ |
| 99 | + VanillaItems::DIAMOND_PICKAXE()->addEnchantment(new EnchantmentInstance(VanillaEnchantments::UNBREAKING(), 1)), |
| 100 | + VanillaItems::DIAMOND_PICKAXE(), |
| 101 | + null |
| 102 | + ]; |
| 103 | + |
| 104 | + yield "No enchant on base item and one enchant on material" => [ |
| 105 | + VanillaItems::DIAMOND_PICKAXE(), |
| 106 | + VanillaItems::DIAMOND_PICKAXE()->addEnchantment(new EnchantmentInstance(VanillaEnchantments::UNBREAKING(), 1)), |
| 107 | + new AnvilCraftResult(2, VanillaItems::DIAMOND_PICKAXE()->addEnchantment(new EnchantmentInstance(VanillaEnchantments::UNBREAKING(), 1)), null) |
| 108 | + ]; |
| 109 | + |
| 110 | + yield "Combine two identical items with damage" => [ |
| 111 | + VanillaItems::DIAMOND_PICKAXE()->setDamage(10), |
| 112 | + VanillaItems::DIAMOND_PICKAXE(), |
| 113 | + new AnvilCraftResult(1, VanillaItems::DIAMOND_PICKAXE()->setDamage(0), null) |
| 114 | + ]; |
| 115 | + |
| 116 | + yield "Combine two identical items with damage for material" => [ |
| 117 | + VanillaItems::DIAMOND_PICKAXE(), |
| 118 | + VanillaItems::DIAMOND_PICKAXE()->setDamage(10), |
| 119 | + null |
| 120 | + ]; |
| 121 | + |
| 122 | + yield "Combine two identical items with different enchantments" => [ |
| 123 | + VanillaItems::DIAMOND_PICKAXE()->addEnchantment(new EnchantmentInstance(VanillaEnchantments::EFFICIENCY(), 2)), |
| 124 | + VanillaItems::DIAMOND_PICKAXE()->addEnchantment(new EnchantmentInstance(VanillaEnchantments::UNBREAKING(), 1)), |
| 125 | + new AnvilCraftResult(2, VanillaItems::DIAMOND_PICKAXE() |
| 126 | + ->addEnchantment(new EnchantmentInstance(VanillaEnchantments::EFFICIENCY(), 2)) |
| 127 | + ->addEnchantment(new EnchantmentInstance(VanillaEnchantments::UNBREAKING(), 1)), |
| 128 | + null) |
| 129 | + ]; |
| 130 | + |
| 131 | + yield "Combine two identical items with different enchantments with damage" => [ |
| 132 | + VanillaItems::DIAMOND_PICKAXE()->addEnchantment(new EnchantmentInstance(VanillaEnchantments::EFFICIENCY(), 2))->setDamage(10), |
| 133 | + VanillaItems::DIAMOND_PICKAXE()->addEnchantment(new EnchantmentInstance(VanillaEnchantments::UNBREAKING(), 1)), |
| 134 | + new AnvilCraftResult(4, VanillaItems::DIAMOND_PICKAXE() |
| 135 | + ->addEnchantment(new EnchantmentInstance(VanillaEnchantments::EFFICIENCY(), 2)) |
| 136 | + ->addEnchantment(new EnchantmentInstance(VanillaEnchantments::UNBREAKING(), 1)), |
| 137 | + null) |
| 138 | + ]; |
| 139 | + |
| 140 | + yield "Combine two identical items with different enchantments with damage for material" => [ |
| 141 | + VanillaItems::DIAMOND_PICKAXE()->addEnchantment(new EnchantmentInstance(VanillaEnchantments::EFFICIENCY(), 2)), |
| 142 | + VanillaItems::DIAMOND_PICKAXE()->addEnchantment(new EnchantmentInstance(VanillaEnchantments::UNBREAKING(), 1))->setDamage(10), |
| 143 | + new AnvilCraftResult(2, VanillaItems::DIAMOND_PICKAXE() |
| 144 | + ->addEnchantment(new EnchantmentInstance(VanillaEnchantments::EFFICIENCY(), 2)) |
| 145 | + ->addEnchantment(new EnchantmentInstance(VanillaEnchantments::UNBREAKING(), 1)), |
| 146 | + null) |
| 147 | + ]; |
| 148 | + |
| 149 | + yield "Combine two identical items with same enchantment level" => [ |
| 150 | + VanillaItems::DIAMOND_PICKAXE()->addEnchantment(new EnchantmentInstance(VanillaEnchantments::FORTUNE(), 1)), |
| 151 | + VanillaItems::DIAMOND_PICKAXE()->addEnchantment(new EnchantmentInstance(VanillaEnchantments::FORTUNE(), 1)), |
| 152 | + new AnvilCraftResult(8, VanillaItems::DIAMOND_PICKAXE()->addEnchantment(new EnchantmentInstance(VanillaEnchantments::FORTUNE(), 2)), null) |
| 153 | + ]; |
| 154 | + |
| 155 | + yield "Combine two identical items with same enchantment level and damage" => [ |
| 156 | + VanillaItems::DIAMOND_PICKAXE()->addEnchantment(new EnchantmentInstance(VanillaEnchantments::FORTUNE(), 1))->setDamage(10), |
| 157 | + VanillaItems::DIAMOND_PICKAXE()->addEnchantment(new EnchantmentInstance(VanillaEnchantments::FORTUNE(), 1)), |
| 158 | + new AnvilCraftResult(10, VanillaItems::DIAMOND_PICKAXE()->addEnchantment(new EnchantmentInstance(VanillaEnchantments::FORTUNE(), 2))->setDamage(0), null) |
| 159 | + ]; |
| 160 | + |
| 161 | + yield "Combine two identical items with same enchantment level and damage for material" => [ |
| 162 | + VanillaItems::DIAMOND_PICKAXE()->addEnchantment(new EnchantmentInstance(VanillaEnchantments::FORTUNE(), 1)), |
| 163 | + VanillaItems::DIAMOND_PICKAXE()->addEnchantment(new EnchantmentInstance(VanillaEnchantments::FORTUNE(), 1))->setDamage(10), |
| 164 | + new AnvilCraftResult(8, VanillaItems::DIAMOND_PICKAXE()->addEnchantment(new EnchantmentInstance(VanillaEnchantments::FORTUNE(), 2)), null) |
| 165 | + ]; |
| 166 | + } |
| 167 | + |
| 168 | + /** |
| 169 | + * @dataProvider itemSelfCombineRecipeProvider |
| 170 | + */ |
| 171 | + public function testItemSelfCombineRecipe(Item $base, Item $combined, ?AnvilCraftResult $expected) : void{ |
| 172 | + $recipe = new ItemSelfCombineRecipe(new WildcardRecipeIngredient()); |
| 173 | + self::assertAnvilCraftResultEquals($expected, $recipe->getResultFor($base, $combined)); |
| 174 | + } |
| 175 | + |
| 176 | + private static function assertAnvilCraftResultEquals(?AnvilCraftResult $expected, ?AnvilCraftResult $actual) : void{ |
87 | 177 | if($expected === null){
|
88 |
| - self::assertNull($result, "Recipe did not match expected result"); |
| 178 | + self::assertNull($actual, "Recipe did not match expected result"); |
89 | 179 | return;
|
90 | 180 | }else{
|
91 |
| - self::assertNotNull($result, "Recipe did not match expected result"); |
| 181 | + self::assertNotNull($actual, "Recipe did not match expected result"); |
92 | 182 | }
|
93 |
| - self::assertEquals($expected->getXpCost(), $result->getXpCost(), "XP cost did not match expected result"); |
94 |
| - self::assertTrue($expected->getOutput()->equalsExact($result->getOutput()), "Recipe output did not match expected result"); |
| 183 | + self::assertEquals($expected->getXpCost(), $actual->getXpCost(), "XP cost did not match expected result"); |
| 184 | + self::assertTrue($expected->getOutput()->equalsExact($actual->getOutput()), "Recipe output did not match expected result"); |
95 | 185 | $sacrificeResult = $expected->getSacrificeResult();
|
96 | 186 | if($sacrificeResult !== null){
|
97 |
| - $resultExpected = $result->getSacrificeResult(); |
| 187 | + $resultExpected = $actual->getSacrificeResult(); |
98 | 188 | self::assertNotNull($resultExpected, "Recipe sacrifice result did not match expected result");
|
99 | 189 | self::assertTrue($sacrificeResult->equalsExact($resultExpected), "Recipe sacrifice result did not match expected result");
|
100 | 190 | }else{
|
101 |
| - self::assertNull($result->getSacrificeResult(), "Recipe sacrifice result did not match expected result"); |
| 191 | + self::assertNull($actual->getSacrificeResult(), "Recipe sacrifice result did not match expected result"); |
102 | 192 | }
|
103 | 193 | }
|
104 | 194 | }
|
0 commit comments