Initial checkin
This commit is contained in:
		
							
								
								
									
										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);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user