Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed Getting Started with PHP Unit Testing!
You have completed Getting Started with PHP Unit Testing!
Preview
Fixtures allow you to setup all the code and data you'll need to run your test and share that set up across multiple tests.
Documentation for Fixtures
tests/FullRecipeTest.php
<?php
use the PHPUnit\Framework\TestCase;
class FullRecipeTest extends TestCase
{
protected $recipe;
protected function setUp(): void
{
$this->recipe = new Recipe("Belgian Waffles");
$this->recipe->addIngredient("Egg", 2);
$this->recipe->addIngredient("Butter", 1, "Cup");
$this->recipe->addIngredient("sugar", .5, "Cup");
$this->recipe->addIngredient("milk", 1.5, "cup");
$this->recipe->addIngredient("vanilla", 2, "tsp");
$this->recipe->addIngredient("flour", 2, "cup");
$this->recipe->addIngredient("baking powder", 1, "tbsp");
$this->recipe->addInstruction("Separate eggs. Whip egg whites until stiff peaks form. Set asside.");
$this->recipe->addInstruction("Melt butter, and combine with sugar. Add egg yokes and mix well.");
$this->recipe->addInstruction("Add milk and vanilla and mix well.");
$this->recipe->addInstruction("Add flour and sugar until just combined. ");
$this->recipe->addInstruction("Fold in egg whites.");
$this->recipe->addInstruction("Follow instructions on waffle maker or add .5 cup of batter to waffle iron and cook for 4 minutes.");
$this->recipe->setYield("10 waffles");
$this->recipe->setSource("Alena Holligan");
$this->recipe->addTag("breakfast, quick bread");
}
/** @test */
function hasTitle()
{
$this->assertEquals(
"Belgian Waffles",
$this->recipe->getTitle()
);
}
}
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
I could setup a full recipe for
each test, but there is an easier way.
0:00
Fixtures allow you to
setup all the code and
0:01
the data that you'll need for your tests
and show that across multiple tests.
0:04
We can use the setUp.
0:09
Much like a constructor,
our setUp function will allow us to add
0:13
code that needs to happen
when a test is run.
0:17
You'll notice the return type
of void because test case is
0:21
an abstract class that defines
the framework for this function.
0:25
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up