2019-07-07 23:13:30 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace NoccyLabs\Juicer\Recipe\Mixer;
|
|
|
|
|
|
|
|
use NoccyLabs\Juicer\Recipe\Recipe;
|
|
|
|
use NoccyLabs\Juicer\Ingredient\Ingredient;
|
|
|
|
use NoccyLabs\Juicer\Ingredient\Base;
|
2019-07-09 00:10:56 +00:00
|
|
|
use NoccyLabs\Juicer\Recipe\RecipeInterface;
|
2019-07-07 23:13:30 +00:00
|
|
|
|
|
|
|
class MixerTest extends \PhpUnit\Framework\TestCase
|
|
|
|
{
|
|
|
|
|
2019-07-09 00:10:56 +00:00
|
|
|
public function getDataForEmptyRecipes()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
[ 'VG100', 10, [ 'VG' => 10 ], 10 ],
|
|
|
|
[ 'PG100', 10, [ 'PG' => 10 ], 10 ],
|
|
|
|
[ 'VG70', 10, [ 'VG' => 7, 'PG' => 3 ], 10 ],
|
|
|
|
[ 'VG50', 10, [ 'VG' => 5, 'PG' => 5 ], 10 ]
|
|
|
|
];
|
2019-07-07 23:13:30 +00:00
|
|
|
}
|
|
|
|
|
2019-07-09 00:10:56 +00:00
|
|
|
/**
|
|
|
|
* @dataProvider getDataForEmptyRecipes
|
|
|
|
*/
|
|
|
|
public function testMixingEmptyRecipes($base, $amount, array $assertBases, $assertAmount)
|
2019-07-07 23:13:30 +00:00
|
|
|
{
|
|
|
|
$recipe = new Recipe();
|
|
|
|
$mixer = new Mixer();
|
|
|
|
|
2019-07-09 00:10:56 +00:00
|
|
|
$base = new Base($base);
|
|
|
|
$mixed = $mixer->mixRecipe($recipe, $amount, $base, 0);
|
2019-07-07 23:13:30 +00:00
|
|
|
|
2019-07-09 00:10:56 +00:00
|
|
|
$this->assertCount(count($assertBases), $mixed);
|
|
|
|
$mixedAmount = 0;
|
|
|
|
foreach ($mixed as $measured) {
|
|
|
|
$name = $measured->getFlavorName();
|
|
|
|
if (!array_key_exists($name, $assertBases)) {
|
|
|
|
$this->assertFail("Mixed contains unexpected ingredients");
|
|
|
|
}
|
|
|
|
$mixedAmount += $measured->getVolume();
|
|
|
|
}
|
|
|
|
$this->assertEquals($assertAmount, $mixedAmount);
|
|
|
|
}
|
2019-07-07 23:13:30 +00:00
|
|
|
|
2019-07-09 00:10:56 +00:00
|
|
|
public function getDataForDummyRecipes()
|
|
|
|
{
|
|
|
|
$ingredientA1 = new Ingredient("Ingredient A1", null, 2);
|
|
|
|
$ingredientA2 = new Ingredient("Ingredient A2", null, 3);
|
|
|
|
$recipeA = new Recipe();
|
|
|
|
$recipeA->setRecipeName("Recipe A");
|
|
|
|
$recipeA->addIngredient($ingredientA1);
|
|
|
|
$recipeA->addIngredient($ingredientA2);
|
|
|
|
return [
|
|
|
|
[ $recipeA, 'VG70', 10 ],
|
|
|
|
];
|
2019-07-07 23:13:30 +00:00
|
|
|
}
|
|
|
|
|
2019-07-09 00:10:56 +00:00
|
|
|
/**
|
|
|
|
* @dataProvider getDataForDummyRecipes
|
|
|
|
*/
|
|
|
|
public function testMixingDummyRecipes(RecipeInterface $recipe, $base, $amount)
|
2019-07-07 23:13:30 +00:00
|
|
|
{
|
|
|
|
$mixer = new Mixer();
|
2019-07-09 00:10:56 +00:00
|
|
|
$base = new Base($base);
|
|
|
|
$mixed = $mixer->mixRecipe($recipe, $amount, $base, 0);
|
2019-07-07 23:13:30 +00:00
|
|
|
|
2019-07-09 00:10:56 +00:00
|
|
|
$expectedCount = count($base->getComponents()) + count($recipe->getIngredients());
|
2019-07-07 23:13:30 +00:00
|
|
|
|
2019-07-09 00:10:56 +00:00
|
|
|
$this->assertCount($expectedCount, $mixed);
|
|
|
|
$mixedAmount = 0;
|
|
|
|
foreach ($mixed as $measured) {
|
|
|
|
$mixedAmount += $measured->getVolume();
|
|
|
|
}
|
|
|
|
$this->assertEquals($amount, $mixedAmount);
|
2019-07-07 23:13:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|