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
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Unit testing with PHPUnit


A positive effect of testing is that it forces you to split your code into manageable dependencies, so that you can test them in isolation. The testing of these individual classes and methods is referred to as unit testing. Since it relies on the PHPUnit testing framework, which already provides a large number of tools to set up test suites, Laravel does not need to provide any additional helpers for this type of testing.

A great way to learn about any framework, and at the same time learn about the different ways in which it can be tested, is to look at how its authors have written tests for it. Therefore, our next examples will be taken directly from Laravel's test suite, which is located at vendor/laravel/framework/tests/.

Defining what you expect with assertions

Assertions are the fundamental components of unit tests. Simply put, they are used to compare the expected output of a function with its actual output.

To see how assertions work, we will examine the test...