Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP Getting Started with PHP Unit Testing Testing Existing Projects Fixtures

How is the hasTags() test passing?

In the Getting Started with PHP Unit Testing course Fixtures video (I believe this is in the third section of this course), Alena creates a hasTags() test in the FullRecipeTest.php file. In this test, there are two assertions:

$this->assertCount(2, $this->recipe->getTags()); $this->assertEquals( ["breakfast", "quick bread"], $this->recipe->getTags() );

However, in the setUp() function in the same FullRecipeTest.php file there is this statement to add a tag to the recipe (it’s the same in the teacher’s notes):

$this->recipe->addTag("breakfast, quick bread");

In the recipes.php file to set up a recipe, the addTag() function only takes a single parameter that isn’t an array.

public function addTag($tag) { $this->tags[] = strtolower($tag); }

So, it seems to me, there should only be one tag containing both breakfast and quick bread. But, when she creates the assertCount assertion, the expected value is two. How is this passing for her? It won’t pass for me even though my code is the same as hers.

==> FullRecipeTest ✔ ✔ ✔ ✔ ✔ ✖
==> RecipiesTest ✔

Time: 170 ms, Memory: 6.00 MB

✖ There was 1 failure:

1) FullRecipeTest::hasTags ✖ Failed asserting that actual size 1 matches expected size 2.

I have looked over the code and watched the video a couple of times to make sure I did everything correctly. I also commented out each of the assertions in that function individually to make sure I knew where the error was happening. It happens with the assertCount() assertion.

I’m really new to the world of testing and PHP Unit, so it’s quite possible I’m missing something.

Any help would be appreciated.

Thanks!