Initial checkin
This commit is contained in:
28
tests/Ingredient/BaseTest.php
Normal file
28
tests/Ingredient/BaseTest.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace NoccyLabs\Juicer\Ingredient;
|
||||
|
||||
|
||||
class BaseTest extends \PhpUnit\Framework\TestCase
|
||||
{
|
||||
public function getBaseAsgData()
|
||||
{
|
||||
return [
|
||||
[ 'PG100', Base::MASS_PG ],
|
||||
[ 'VG100', Base::MASS_VG ],
|
||||
// NOTE: The internet claims we should get (for 50/50;) 1.1425g/mL
|
||||
// but calculating a 50/50 by volume base gives 1.149g/mL.
|
||||
[ 'VG50', 1.149 ]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getBaseAsgData
|
||||
*/
|
||||
public function testThatTheBaseHasTheProperApparentSpecificGravity($base, $expected)
|
||||
{
|
||||
$base = new Base($base);
|
||||
$this->assertEquals($expected, $base->getSpecificGravity());
|
||||
}
|
||||
|
||||
}
|
65
tests/Recipe/Exporter/JsonExporterTest.php
Normal file
65
tests/Recipe/Exporter/JsonExporterTest.php
Normal file
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace NoccyLabs\Juicer\Recipe\Exporter;
|
||||
|
||||
use NoccyLabs\Juicer\Recipe\Recipe;
|
||||
use NoccyLabs\Juicer\Ingredient\Ingredient;
|
||||
|
||||
class JsonExporterTest extends \PhpUnit\Framework\TestCase
|
||||
{
|
||||
public function testThatRecipesCanBeExportedToJson()
|
||||
{
|
||||
$recipe = new Recipe();
|
||||
$recipe->setRecipeName("foo");
|
||||
$recipe->setRecipeAuthor("bar");
|
||||
|
||||
$this->assertInstanceOf(Recipe::class, $recipe);
|
||||
$this->assertEquals("foo", $recipe->getRecipeName());
|
||||
$this->assertEquals("bar", $recipe->getRecipeAuthor());
|
||||
|
||||
$exporter = new JsonExporter();
|
||||
|
||||
$exported = $exporter->export($recipe);
|
||||
$expected = json_encode([
|
||||
'recipe' => 'foo',
|
||||
'author' => 'bar',
|
||||
'tags' => [],
|
||||
'description' => null,
|
||||
'extra' => [],
|
||||
'ingredients' => []
|
||||
], JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES);
|
||||
|
||||
$this->assertEquals($expected, $exported);
|
||||
}
|
||||
|
||||
public function testThatRecipesWithIngredientsCanBeExportedToJson()
|
||||
{
|
||||
$recipe = new Recipe();
|
||||
$recipe->setRecipeName("foo");
|
||||
$recipe->setRecipeAuthor("bar");
|
||||
$recipe->addIngredient(new Ingredient("Cherry", "FA", 1));
|
||||
$recipe->addIngredient(new Ingredient("Vanilla Swirl", "TFA", 2));
|
||||
|
||||
$this->assertInstanceOf(Recipe::class, $recipe);
|
||||
$this->assertEquals("foo", $recipe->getRecipeName());
|
||||
$this->assertEquals("bar", $recipe->getRecipeAuthor());
|
||||
|
||||
$exporter = new JsonExporter();
|
||||
|
||||
$exported = $exporter->export($recipe);
|
||||
$expected = json_encode([
|
||||
'recipe' => 'foo',
|
||||
'author' => 'bar',
|
||||
'tags' => [],
|
||||
'description' => null,
|
||||
'extra' => [],
|
||||
'ingredients' => [
|
||||
[ 'brand' => 'FA', 'flavor' => 'Cherry', 'percent' => 1 ],
|
||||
[ 'brand' => 'TFA', 'flavor' => 'Vanilla Swirl', 'percent' => 2 ]
|
||||
]
|
||||
], JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES);
|
||||
|
||||
$this->assertEquals($expected, $exported);
|
||||
}
|
||||
|
||||
}
|
45
tests/Recipe/Importer/JsonImporterTest.php
Normal file
45
tests/Recipe/Importer/JsonImporterTest.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace NoccyLabs\Juicer\Recipe\Importer;
|
||||
|
||||
use NoccyLabs\Juicer\Recipe\Recipe;
|
||||
use NoccyLabs\Juicer\Ingredient\Ingredient;
|
||||
use NoccyLabs\Juicer\Recipe\Exporter\JsonExporter;
|
||||
|
||||
class JsonImporterTest extends \PhpUnit\Framework\TestCase
|
||||
{
|
||||
public function testThatRecipesCanBeImportedFromJson()
|
||||
{
|
||||
|
||||
$json = '{ "recipe":"foo", "author":"bar", "ingredients": [{"flavor":"Cherry", "brand":"FA", "percent":1}] }';
|
||||
|
||||
$importer = new JsonImporter();
|
||||
$recipe = $importer->import($json);
|
||||
|
||||
$this->assertEquals("foo", $recipe->getRecipeName());
|
||||
$this->assertEquals("bar", $recipe->getRecipeAuthor());
|
||||
|
||||
$this->assertCount(1, $recipe->getIngredients());
|
||||
|
||||
}
|
||||
|
||||
public function testThatRecipesCanBeImportedFromExportedJson()
|
||||
{
|
||||
|
||||
$recipe = new Recipe();
|
||||
$recipe->setRecipeName("foo");
|
||||
$recipe->setRecipeAuthor("bar");
|
||||
$recipe->addIngredient(new Ingredient("Cherry", "FA", 1));
|
||||
$recipe->addIngredient(new Ingredient("Vanilla Swirl", "TFA", 2));
|
||||
|
||||
$exporter = new JsonExporter();
|
||||
$exported = $exporter->export($recipe);
|
||||
|
||||
$importer = new JsonImporter();
|
||||
$importedRecipe = $importer->import($exported);
|
||||
|
||||
$this->assertEquals($recipe, $importedRecipe);
|
||||
}
|
||||
|
||||
|
||||
}
|
59
tests/Recipe/Mixer/MixerTest.php
Normal file
59
tests/Recipe/Mixer/MixerTest.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace NoccyLabs\Juicer\Recipe\Mixer;
|
||||
|
||||
use NoccyLabs\Juicer\Recipe\Recipe;
|
||||
use NoccyLabs\Juicer\Ingredient\Ingredient;
|
||||
use NoccyLabs\Juicer\Ingredient\Base;
|
||||
|
||||
class MixerTest extends \PhpUnit\Framework\TestCase
|
||||
{
|
||||
public function testMixingEmptyRecipesWithVg()
|
||||
{
|
||||
$recipe = new Recipe();
|
||||
$mixer = new Mixer();
|
||||
|
||||
$base = new Base("VG100");
|
||||
$mixed = $mixer->mixRecipe($recipe, 10, $base, 0);
|
||||
|
||||
$this->assertCount(1, $mixed);
|
||||
$mixedVg = reset($mixed);
|
||||
|
||||
$this->assertEquals(10, $mixedVg->getVolume());
|
||||
$this->assertEquals("VG", $mixedVg->getFlavorName());
|
||||
}
|
||||
|
||||
public function testMixingEmptyRecipesWithPg()
|
||||
{
|
||||
$recipe = new Recipe();
|
||||
$mixer = new Mixer();
|
||||
|
||||
$base = new Base("PG100");
|
||||
$mixed = $mixer->mixRecipe($recipe, 10, $base, 0);
|
||||
|
||||
$this->assertCount(1, $mixed);
|
||||
$mixedPg = reset($mixed);
|
||||
|
||||
$this->assertEquals(10, $mixedPg->getVolume());
|
||||
$this->assertEquals("PG", $mixedPg->getFlavorName());
|
||||
}
|
||||
|
||||
public function testMixingEmptyRecipesWith70Vg30Pg()
|
||||
{
|
||||
$recipe = new Recipe();
|
||||
$mixer = new Mixer();
|
||||
|
||||
$base = new Base("VG70");
|
||||
$mixed = $mixer->mixRecipe($recipe, 10, $base, 0);
|
||||
|
||||
$this->assertCount(2, $mixed);
|
||||
|
||||
$mixedVg = array_shift($mixed);
|
||||
$this->assertEquals(10, $mixedVg->getVolume());
|
||||
$this->assertEquals("VG", $mixedVg->getFlavorName());
|
||||
$mixedPg = array_shift($mixed);
|
||||
$this->assertEquals(10, $mixedPg->getVolume());
|
||||
$this->assertEquals("PG", $mixedPg->getFlavorName());
|
||||
}
|
||||
|
||||
}
|
28
tests/Recipe/RecipeTest.php
Normal file
28
tests/Recipe/RecipeTest.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace NoccyLabs\Juicer\Recipe;
|
||||
|
||||
use NoccyLabs\Juicer\Ingredient\Ingredient;
|
||||
|
||||
class RecipeTest extends \PhpUnit\Framework\TestCase
|
||||
{
|
||||
|
||||
public function testCreatingAndModifyingRecipes()
|
||||
{
|
||||
$recipe = new Recipe();
|
||||
$recipe->setRecipeName("foo");
|
||||
$recipe->setRecipeAuthor("bar");
|
||||
|
||||
$ingredient1 = new Ingredient("Ingredient 1");
|
||||
$ingredient2 = new Ingredient("Ingredient 2");
|
||||
|
||||
$recipe->addIngredient($ingredient1);
|
||||
$recipe->addIngredient($ingredient2);
|
||||
|
||||
$this->assertInstanceOf(Recipe::class, $recipe);
|
||||
$this->assertEquals("foo", $recipe->getRecipeName());
|
||||
$this->assertEquals("bar", $recipe->getRecipeAuthor());
|
||||
$this->assertEquals([$ingredient1, $ingredient2], $recipe->getIngredients());
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user