O'Reilly logo

PHPUnit Essentials by Zdenek Machek

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 8. Using Test Doubles

PHPUnit offers ways to modify the code on the fly and create test doubles. This means that you can create a double of your code (class), which might look and behave the same way, but it's going to be a simplified version that will reduce the complexity and solve dependencies. After reading how to write good tests, this doesn't sound right. You want to be sure that the executed code works as expected, but when you replace a part of the code, how can you be sure that it will work?

The reason for replacing a part of the code is to eliminate dependencies on other code, databases, and third-party APIs. When you have to use them, it's not a unit test but a functional or an integration test. However, you should always start ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required