Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Laravel News:
Defense Programming: Anticipating Failures with Tests
Feb 14, 2018 @ 15:45:25

On the Laravel News site there's a tutorial posted that makes some suggestions about how to anticipate application failures by using effective unit testing.

When you start working on a new feature, it is wise to plan out not only how it is expected to work, but what happens if something fails. Taking the time up front to anticipate failure is a quality of a great developer.

[...] Since we don’t know when a dependency might fail, it’s best to plan for failure by having tests so we can be more confident in failed states. Laravel can help us write tests that plan for failure using real-time facades.

In their example, they create a simple "article" repository class that makes use of a HTTP client to fetch the information for each article (by ID). In this case the client is Guzzle. They then add a singleton to the configuration to fetch the API class and show how to implement it in a controller. With this structure, they then move on to testing for failure via real-time facades and mocking a Guzzle response using a "Client" facade instead of calling it directly.

tagged: failure test defensive programming unittest laravel tutorial

Link: https://laravel-news.com/defense-programming-anticipating-failures-tests


Trending Topics: