Phpunit

Analyze your tests with PHPStan

Use PHPStan to analyze your tests, to make them more effective, and reduce bugs

Jun 10, 2024

Mastering PHPUnit: Using Mocks and Stubs

Learn how to use mocks and stubs in PHPUnit to make your tests faster and more focused.

May 30, 2024

Mastering PHPUnit: Using data providers

Learn how to use data providers in PHPUnit, to test a lot of scenarios and reduce code duplication

May 22, 2024

Mastering PHPUnit: Writing Your First Test with PHPUnit

Learn how to write your first tests in PHPUnit, using assertions. Use methods like setUp and tearDown, to reduce code duplication

May 17, 2024

Mastering PHPUnit: an introduction

In this blog series we’ll go from writing our first unit test to being a PHPUnit master. This first post will go over the basics, and introduce you to PHPUnit

May 3, 2024

Testing Exceptions in PHPUnit

Last week i gave 10 phpunit tips. This week we’ll take a look at testing exceptions, which wasn’t covered in that post. Lets start with some example code that we will be testing. We have the Email and EmailValidator classes. Email is a value object that makes sure it is a valid email. We use the EmailValidator to make sure that the emails are only from our company.

Apr 9, 2021

10 PHPUnit Tips

PHPUnit is the defacto testing framework for PHP. In this post i want to share with you my top 10 tips for PHPUnit. I’m using PHPUnit 9.5, but most of these apply to older versions as well. So, lets get this party started.

Apr 2, 2021

PHPUnit beyond basics: Dataproviders

Once you have set up your first unit tests, and you have a good configuration, its time to add a lot of tests. Lets take a look at using data providers, as a way to test with a lot of data.

Feb 26, 2021

PHPUnit beyond basics: configuration

If you just got started with PHPUnit, its configuration file may be a bit daunting. Today we’re gonna walk through (what i consider) the ideal config file. If you’re just here to copy paste the config, then you can find it at thebottom 👇.

Feb 19, 2021

Testing code that generates warnings

Our code base has a lot of code that looks like this: <?php try { $this->doScaryThing(); } catch(Exception $e) { trigger_error("Downgraded: " . get_class($e) . ":" . $e->getMessage(), E_USER_WARNING); }

Nov 21, 2019