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

Summary


Testing legacy code is not easy, but it's possible. In this chapter, we saw several different approaches, from the lightweight use of reflection and changing methods' visibility, to redefining functions with a third-party library, mocking the filestream, and then using runkit and changing anything that we wanted and needed to change.

It's up to you to decide when these methods are appropriate and when they are not. However, working with dirty code requires dirty methods. There are other libraries and extensions that do more or less the same things (for example, TestIt and ext/test_helpers).

This chapter explained to you the possibilities of what you can do when you want to write unit/integration tests for legacy code.

In the next chapter, we will see functional tests that were mentioned as another way to test legacy code—Selenium. It's something different and definitely something that you should know—you are running tests in the web browser, mimicking user behavior but still working...