Execute blackfire assertions inside atoum
@agallou - 08 Feb 2016
Blackfire provides a PHP SDK that, among other things, allows to integrate performance tests inside PHPUnit: You can check that your code doesn’t exhaust a memory limit, an execution time or a number of calls for a function/method.
How could we integrate those tests inside atoum in order to benefit from the greatness of atoum assertions?
First, we need to install atoum’s Blackfire extension via Composer.
Then we need to configure the client ID and token to access to Blackfire. We do that by adding a few lines in the
.atoum.php file. For example here is how to do it when those variables are accessible as environnement variables:
The extension provides a new asserter:
Those methods can be called from this new asserter:
Let’s consider the following test as an example:
This test checks that the code inside the anonymous function will not take more than 2 seconds to be executed.
Here we’ve added a
sleep(4) to make the test fail, so the following output will be displayed:
This is an example based on the execution time. You can define more usefull assertions like this:
Avoid running those tests
In order to only execute those tests, you can use the
extensions tag (read the documentation about it) and atoum’s
ruler-extension that allows you to filter the tests that needs Blackfire (or filter the tests that does not need Blackfire).
For example, you can launch all the tests that do not need the Blackfire PHP extension like this:
This extension requires a least the version 2.5.0 of atoum: read the 2.5.0 announcement.