One of my personal missions over the last six months has been to shave seconds off of the WordPress and BuddyPress automated test suites. (WP’s tests run in under half the time today than in WP 4.0 – and with the addition of nearly 1000 tests. Score!) One of the tools I use to track down problematic tests is John Kary’s excellent phpunit-speedtrap, which adds a listener to each test run, and produces a report of tests whose running time exceeds a configurable threshhold. phpunit-speedtrap is designed to be used as a Composer dependency, but this is not currently convenient or necessary for the purposes of working with WP/BP (for one thing, I’m the only person doing it). Here’s how I’ve rigged it up to run locally:
- Grab a copy of the listener class from Github https://github.com/johnkary/phpunit-speedtrap/blob/master/src/JohnKary/PHPUnit/Listener/SpeedTrapListener.php. I chose to remove the PHP namespacing, but you can do as you wish. Save it somewhere – I put it at
~/.speed-trap-listener.phpso that I can use it with all projects.
- WP and BP ship with a
phpunit.xml.distconfig file. The
.distextension means that you can run your own
phpunit.xml.dist– PHPUnit will prefer the non-dist version if available, while WP and BP’s version control config will ignore it. Copy
phpunit.xmland add the following block:
<listeners> <listener class="SpeedTrapListener" file="/home/bgorges/.speed-trap-listener.php"> <arguments> <array> <element key="slowThreshold"> <integer>250</integer> </element> </array> </arguments> </listener> </listeners>
slowThresholdand filepath to whatever you’d like.
phpunit. You’ll see something like this:
Keep on shavin’!