Posts tagged with phpunit

Join thousands of developers

Every two weeks, I share practical tips, tutorials, and behind-the-scenes insights from maintaining 300+ open source packages.

No spam. Unsubscribe anytime. You can also follow me on X.

Tidying Up Your PHPUnit Tests with Data Providers

tighten.co

Over at the Tighten blog, Chris Trombley published a new post on how to use data providers in PHPUnit.

PHPUnit gives us a way to consolidate this common logic while varying our setup data, without losing the benefit of dedicated, smaller test methods. In this post, we'll explore PHPUnit's data providers. While data providers are available in any PHPUnit test suite, let's look at how they can help us tidy up our tests in a Laravel application.

Read more [tighten.co]

Tips to Speed up Your Phpunit Tests

laravel-news.com

On the Laravel News blog, Tim MacDonald wrote a nice collection of tips on how to make PHPUnit tests run faster.

Having a fast test suite can be just as important as having a fast application. As a developer, getting feedback quickly about the state of your code allows for a much quicker development turnaround. Here we are going to run through some tips you can implement today to make your tests run faster.

Read more [laravel-news.com]

The Five Types of Test Doubles & How to Create Them in PHPUnit

jmauerhan.wordpress.com

In a new post on her blog Jessica Mauerhan has some good examples on the various types of test doubles.

Did you know that a Mock is only one type of a test double? Most of us use the word “mock” to mean any kind of test double, but there’s actually five different types. It really can help you understand what you’re trying to accomplish with your test if you know a little bit more what you’re doing with your test doubles, so this article will explain the kinds of test doubles, when you use them, how you use them and why.

Read more [jmauerhan.wordpress.com]

Creating custom @requires annotations for PHPUnit

mattstauffer.com

In an older but still relevant blogpost Matt Stauffer explains how you can extend PHPUnit's native @requires annotation. It's pretty handy if you want to only run certain tests in certain environments.

I was primarily interested in learning—how do PHPUnit annotations work? What does it look like to extend a pre-existing annotation? How do you not just check for the annotation, but also check its value? I'll show you what I found and then you can run willy-nilly with your own naming schemes.

Read more [mattstauffer.com]

Separate Interactive Test Suites

If you find yourself having a bunch of slow tests that don't need to execute every time you run the tests, take a look at PHPUnit's defaultTestSuite setting. TJ Miller explains it in a blog post he wrote last year.

To avoid running the interactive test suite with the rest of my tests, manually or via a CI job, I had to explicitly include all the other suites using phpunit --testsuite Api,Feature,Unit. This felt a bit grim and I would rather exclude just that one suite. So I did some digging and found the defaultTestSuite configuration for phpunit.

https://medium.com/@sixlive/separate-interactive-test-suites-f6fd59316ec2

Read more