Using Mockery to test controllers
Sometimes, we need to test the code that uses our database. The commonly accepted practice is that we shouldn't actually do live queries on the database while running a unit test. To get around this, we can use the Mockery package to fake our data.
Getting ready
For this recipe, we need to have Laravel installed and working, as well as PHPUnit from the Setting up and configuring PHPUnit recipe.
How to do it...
To complete this recipe, follow the given steps:
Open up our
composer.json
file, and make sure the following code is included:"require-dev": { "phpunit/phpunit": "3.7.*", "mockery/mockery": "dev-master" },
Open the command line terminal and run the Composer update with the following command:
php composer.phar update
After the update, in the
app/controllers
directory, create theShipsController.php
file using the following code:<?php class ShipsController extends BaseController { protected $ships; public function __construct(Spaceship ...