Set a max timeout for your PHPUnit tests

Smaine Milianni
1 min readAug 18, 2022

πŸ“š You can set your tests as risky if they reach a timeout
by adding an annotation on top of the method. (@large, @medium or @small)

Example:

πŸ’‘ But what about having the possibility to set a global timeout and allow to customize it for each test?

🌸 1- Create the timeout configuration

I’ll create a class with a static public property as it’s straightforward for configuration.

βœ… 2- Create the Assertion

PHPUnit allows us to hook the end of each test and recover the execution time, we will add our assertion in this hook πŸ˜„

--

--

Smaine Milianni

Fullstack Developer- certified Symfony 4,5 and certified AWS Solution Architect - Freelancer - Remote Worker