Testing your route in PHPUnit
As seen in the preceding recipe, I used the browser to show that the API is working. Here, I want to show how you can speed up your workflow by using PHPUnit to do this and then, more importantly, you end up with long term testing.
Getting ready
The previous recipes will help show how to lay the foundation. In this one, I will continue from there.
How to do it…
Follow these steps to test your route:
- Make a test:
> php artisan make:test SearchComicsApiTest
- Then, edit the file
tests/SearchComicsApiTest.php
: - And run
phpunit
:> phpunit --filter=api_results_from_search_verify_format
- Now let's make it do something by hitting that API:
- And let's verify some data, first, I will dump the data to my terminal to get a sense of what I can look for:
We will get the following output:
- Then, I decide to assert a few things:
- That's it, I now know my route is working, without going in the browser, and can now start working with the AngularJS code to display this...