phpunit-speedtrap and WordPress/BuddyPress automated tests

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:

  1. 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.php so that I can use it with all projects.
  2. WP and BP ship with a phpunit.xml.dist config file. The .dist extension means that you can run your own phpunit.xml alongside of 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.xml.dist to phpunit.xml and 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>
    

    Change the slowThreshold and filepath to whatever you’d like.

  3. Run phpunit. You’ll see something like this:
    Screenshot_2015-03-07_11-50-30

Keep on shavin’!

One thought on “phpunit-speedtrap and WordPress/BuddyPress automated tests

  1. krisidious

    I’m enjoying buddypress… I’m using it to make a kind of digital legacy vault. It’s called Passed2You.com if you want to check it out. I’m not nearly as adept as you or your peers, but things have been working pretty smoothly for me using the system and I think that says something about how well it’s built. I found your site while looking for a way to email users from groups. Wanted to take a minute to say thanks for all the hard work.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *