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 Getting to 100%

Cristina Rosales
Cristina Rosales
10,929 Points

I feel like you just pulled this out of thin air...

How does this:

function canCallRecipeDirectly() { $recipe = new Recipe(); $this->assertStringContainsString( 'The following methods are available', $recipe );

}

actually work? I feel like I'm in a magic show. :/

1 Answer

Yes, Magic! As in Magic Function See: this article .

The assertStringContainsString function is looking for a string in the haystack argument and by passing it an object instead the magic function will automatically get called to convert it to a string (see the Recipe class implementation of __toString)

Note that this will not work if the following is set: declare(strict_types=1); I had this set at the top of the file and got an error.