03.12.2015 Views

laravel4cookbook

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Controller Testing 375<br />

.<br />

You can find out more about PHPUnit at: http://phpunit.de.<br />

http://phpunit.de<br />

The Rabbit Hole<br />

The process of test-writing can take as much time as you want to give it. It’s best just to decide<br />

exactly what you need to test, and step away after that.<br />

We’ve just looked at a very narrow area of testing, in our applications. You’re likely to have a richer<br />

data layer, and need a ton of tests for that. You’re probably going to want to test the rendering of<br />

views.<br />

Don’t think this is an exhaustive reference for how to test, or even that this is the only way to<br />

functionally test your controller code. It’s simply a method I’ve found works for the applications I<br />

write.<br />

Alternatives<br />

The closest alternative to testing with PHPUnit is probably PHPSpec (http://www.phpspec.net³).<br />

It uses a similar dialect of assertions and mocking.<br />

If you’re looking to test, in a broader sense, consider looking into Behat (http://behat.org⁴). It uses<br />

a descriptive, text-based language to define what behaviour a service/library should have.<br />

³http://www.phpspec.net<br />

⁴http://behat.org

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!