Book Image

Laravel 5 Essentials

By : Martin Bean
Book Image

Laravel 5 Essentials

By: Martin Bean

Overview of this book

Table of Contents (15 chapters)
Laravel 5 Essentials
About the Author
About the Reviewers

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:

  1. We arrange or initialize some data.

  2. We execute a function to act on this data.

  3. 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...