The anatomy of a test
Your application tests will reside in tests/
. In this directory, you will find a base test case inside TestCase.php
, which is responsible for bootstrapping the application in the testing environment. This class extends Laravel's main TestCase
class, which in turn extends the PHPUnit_Framework_TestCase
class, along with many helpful testing methods that we will cover later in this chapter. All of your tests will extend this first TestCase
class and define one or more methods that are meant to test one or more features of your application.
In every test, we generally perform the following three distinct tasks:
We arrange or initialize some data.
We execute a function to act on this data.
We assert or verify that the output matches what we expected.
Given we had the following Helper class:
class Helper {public static function sum($arr) { return array_sum($arr); }}
An example test case, HelperTest.php
, which illustrates the three preceding steps, will look like this:
class HelperTest...