Phpunit

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.

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.

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); } Or sometimes trigger_error is used as a way to log other thigns.

Nov 21, 2019