Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Laravel 5 Essentials

You're reading from   Laravel 5 Essentials Explore the fundamentals of Laravel, one of the most expressive and robust PHP frameworks available

Arrow left icon
Product type Paperback
Published in Apr 2015
Publisher Packt
ISBN-13 9781785283017
Length 144 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Martin Bean Martin Bean
Author Profile Icon Martin Bean
Martin Bean
Arrow right icon
View More author details
Toc

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...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image