diff --git a/src/Recipe/Mixer/MixedRecipe.php b/src/Recipe/Mixer/MixedRecipe.php index 54b1b11..5e6b9a4 100644 --- a/src/Recipe/Mixer/MixedRecipe.php +++ b/src/Recipe/Mixer/MixedRecipe.php @@ -7,15 +7,41 @@ use NoccyLabs\Juicer\Recipe\RecipeInterface; class MixedRecipe { - + /** @var RecipeInterface The recipe that was mixed */ protected $recipe; protected $mixedIngredients = []; - public function __construct(RecipeInterface $recipe, array $mixedIngredients) + protected $base; + + protected $volume; + + protected $nicotine; + + protected $totalFlavorMl; + + protected $totalFlavorPercent; + + protected $totalFlavorGrams; + + protected $specificGravity; + + public function __construct(RecipeInterface $recipe, array $mixedIngredients, Base $base, int $volume, int $nicotine) { $this->recipe = $recipe; $this->mixedIngredients = $mixedIngredients; + $this->base = $base; + $this->volume = $volume; + $this->nicotine = $nicotine; + + foreach ($mixedIngredients as $mixedIngredient) { + if (!in_array($mixedIngredient->getFlavorName(), ['PG','VG'])) { + $this->totalFlavorMl += $mixedIngredient->getVolume(); + $this->totalFlavorGrams += $mixedIngredient->getWeight(); + $this->totalFlavorPercent += $mixedIngredient->getPercent(); + } + $this->specificGravity += $mixedIngredient->getSpecificGravity() * ($mixedIngredient->getPercent() / 100); + } } public function getIngredients(): array @@ -23,6 +49,16 @@ class MixedRecipe return $this->recipe->getIngredients(); } + public function getBase(): Base + { + return $this->base; + } + + public function getVolume(): int + { + return $this->volume; + } + public function getMeasuredIngredients(): array { return $this->mixedIngredients; @@ -30,21 +66,21 @@ class MixedRecipe public function getTotalFlavorMl(): float { - + return $this->totalFlavorMl; } public function getTotalFlavorPercent(): float { - + return $this->totalFlavorPercent; } public function getTotalFlavorGrams(): float { - + return $this->totalFlavorGrams; } public function getSpecificGravity(): float { - + return $this->specificGravity; } } \ No newline at end of file diff --git a/src/Recipe/Mixer/Mixer.php b/src/Recipe/Mixer/Mixer.php index 4157ef6..bb4f5d1 100644 --- a/src/Recipe/Mixer/Mixer.php +++ b/src/Recipe/Mixer/Mixer.php @@ -55,7 +55,7 @@ class Mixer $mixed[] = new MeasuredIngredient($ingredient, $ingredientPercent, $volume * $floatPercent); } - $mixedRecipe = new MixedRecipe($recipe, $mixed); + $mixedRecipe = new MixedRecipe($recipe, $mixed, $base, $volume, $nicotineStrength); return $mixedRecipe; } diff --git a/tests/Recipe/Mixer/MixedRecipeTest.php b/tests/Recipe/Mixer/MixedRecipeTest.php new file mode 100644 index 0000000..46665d5 --- /dev/null +++ b/tests/Recipe/Mixer/MixedRecipeTest.php @@ -0,0 +1,62 @@ +setRecipeName("Recipe 1"); + $recipe1->addIngredient($ingredientA); + $recipe1->addIngredient($ingredientB); + $percent1 = 5; + + $recipe2 = new Recipe(); + $recipe2->setRecipeName("Recipe 2"); + $recipe2->addIngredient($ingredientB); + $recipe2->addIngredient($ingredientC); + $percent2 = 7; + + $base1 = new Base("VG70"); + $base2 = new Base("VG50"); + + $ml1 = 60; + $ml2 = 30; + + $g1_1 = 0; + $g1_2 = 0; + $g2_1 = 0; + $g2_2 = 0; + + return [ + [ $recipe1, $base1, $percent1, $ml1, $g1_1 ], + [ $recipe1, $base2, $percent1, $ml1, $g1_2 ], + [ $recipe2, $base1, $percent2, $ml2, $g2_1 ], + [ $recipe2, $base2, $percent2, $ml2, $g2_2 ], + ]; + } + + /** + * @dataProvider getValuesForPropertyTest + */ + public function testCalculatedPropertiesOfMixedRecipe(Recipe $recipe, $base, $expectedPercent, $expectedMl, $expectedG) + { + $mixer = new Mixer(); + $mixed = $mixer->mixRecipe($recipe, $expectedMl, $base, 0, null); + + $this->assertEquals($expectedMl, $mixed->getVolume()); + $this->assertEquals($expectedPercent, $mixed->getTotalFlavorPercent()); + } + +} \ No newline at end of file