Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Browse all series

PHP Testing Jargon

There's no two ways about it: terminology in the testing world is incredibly overwhelming. Mocks, stubs, and dummies oh my!

Let's see if we can cut through the noise. Come along as, bit by bit, we break all of these confusing concepts down into something you can easily understand and implement within your own projects.

Progress

Series Info

Episodes
14
Run Time
2h 12m
Difficulty
Intermediate
Last Updated
Sep 15, 2021
Version
PHPUnit 9.5

Series Episodes

  1. Unit Testing (7)
    1. Intro to PHP Testing Jargon

      Before we dive into actual code, let's take a few minutes for an animated overview of what we hope to cover in this series.
    2. Unit Test a Simple Class

      Let's dive in and discuss the basics of unit testing. While some tests interact with your entire application - known as end-to-end tests - unit tests are more isolated and targeted. They focus on a single or small collection of classes. In this opening lesson, we'll use TDD to drive out a simple TagParser class that is responsible for splitting a comma or pipe-separated list of tags into an array.
    3. Setup the World

      Before we move on to a new testing term, let's take a bit of time to discuss a few ways to structure and organize your unit tests. First up is the setUp method, which will run before each test.
    4. When to Reach for Data Providers

      Notice how all of our current tests follow the same basic shape: we create a TagParser instance, we call a parse() method and pass input to it, and then we assert that the result matches what we expect. In these cases, we can drastically simplify our test class by reaching for PHPUnit data providers. Let's learn how in this lesson.
    5. A Unit Test is Not Locked to a Single Class

      You would be forgiven for assuming that a unit test may only act upon a single class: one unit test, one class. This is not the case. In plenty of situations, a unit test may touch multiple classes - and even the database if it makes sense.
    6. Homework Solutions

      At the conclusion of the previous episode, I gave you a short bit of homework: two new tests to write and make pass. Let's go over the homework solutions now.
    7. Green is When You Refactor

      Now that the full suite for our little Quiz app is passing, we can optionally take a few moments to refactor the code. There's no harm in doing so. If we make a mistake, the tests will immediately return red to notify us. Perhaps this is a good time to extract a Questions collection class.
  2. Test Doubles (4)
    1. A Dummy is a Stand-in for the Real Thing

      Let's now move on to test doubles. A double is an all-encompassing term to represent some kind of stand-in for your tests. First up is test dummies.
    2. Let PHPUnit Create Your Test Doubles

      In the previous episode, we manually created a test double; however, we can alternatively let our tooling do this work on the fly. In this episode, we'll review PHPUnit's createMock() method.
    3. Stubs Versus Mocks

      Now that you're comfortable creating basic dummies, let's move on and discuss the difference between stubs and mocks. To illustrate this, we'll expand the previous example to require that our gateway returns a receipt number, which should then be passed to a Mailer.
    4. The Downside to Mocking

      In the previous episode, you got your first taste of mocking. Now, let's take a few moments to discuss a potential downside to this approach. As part of this discussion, we'll review the Classical and Mockist approaches to testing.
  3. Feature Testing (2)
    1. Feature Testing Defined

      Let's move on to a different style of testing that unfortunately might go by many names, dependent upon the development community. Some communities refer to it as feature testing. Others call it end-to-end testing. You might even hear it called acceptance testing or functional testing. While there are often slight differences between these terms, they still generally fall under the same umbrella. Let's have a look in this episode.
    2. When to Reach for Browser Testing

      There's one obvious issue with the feature tests that we reviewed in the previous episode: they all skip the front-end. While often this is what you want, there will certainly be cases where you need to open a browser, click links, fill out forms, and interact with JavaScript. We refer to this as browser testing. In this episode, I'll use Laravel Dusk to quickly demonstrate the difference between these two approaches to feature testing.
  4. Related Jargon (1)
    1. Continuous Integration Testing

      Next up, let’s move on to an approach known as Continuous Integration (CI). This approach was rather confusing to me when I originally learned it, but these days, you’re probably already doing it without realizing it. In this episode, we’ll review a basic workflow for merging content into a central repository that then triggers automated builds and test suites.

Continue Learning