Book Image

PHPUnit Essentials

By : Zdenek Machek
Book Image

PHPUnit Essentials

By: Zdenek Machek

Overview of this book

<p>The ability to write unit tests and software testing have become skills that every PHP developer should master.<br /><br />This book is a practical guide to PHPUnit and unit testing, covering all aspects of writing PHPUnit tests and using them. The book shows why testable code is better code and how to write good tests with the help of simple and easy-to-understand examples.<br /><br />With this book, you will learn how to write, organize, and execute effective tests. Step-by-step techniques of how to write testable code, how to refactor the code, and how to run your tests are shown. You will also learn about advanced testing techniques, including how to test databases, APIs, and legacy code. PHPUnit Essentials is a guide for PHP developers who want to learn or improve their software testing skills. It is a book for developers who begin with testing but is also a good source of information for developers who are already familiar with PHPUnit.</p>
Table of Contents (21 chapters)
PHPUnit Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
5
Running Tests from the Command Line
Index

An example of integration testing


It is more useful to see a real-life example so that you can imagine everything that is involved. As a developer, you must know of a brilliant site named Stack Overflowhttp://stackoverflow.com. This site is a very good source of information about PHPUnit. It is definitely not only about PHPUnit; it also comprises many developers who have faced similar problems as you, and you can find many answers there. So, if you haven't used it before, you should definitely give it a try.

This site also has an interface that allows you to access its functionality and data through the API and get responses in the JSON format. This is not only very well-documented, but you can also try and see exactly what each method does. Documentation for this is available at https://api.stackexchange.com/docs.

For our example, let's use the search method to find something about PHPUnit.

At https://api.stackexchange.com/docs/search, you can find not only the method description but also...