jenkins, paraunit, junit, and saucelabs

Jenkins has great support for taking JUnit-style test reports and tracking successes and failures.

Saucelabs has an extension for running parallel tests, but only reports a total pass/fail with aggregated PHPUnit output. This doesn’t help Jenkins since it needs the XML to properly report.

I noticed Jenkins will also take multiple XML results and combine them into a test report. So, I figured that if we made each parallel process generate an XML, we could just get Jenkins to combine them until this functionality gets built into PHPUnit.

And it worked! Let’s modify vendor/bin/paraunit


$cmd = "$PHPUNIT --filter=$testName $testFile";


$cmd = "$PHPUNIT --log-junit result-$testName.xml --filter=$testName $testFile";

Then, in Jenkins, add a new “Publish JUnit report” and add all your XML files as a result (e.g., “result-*.xml”)

Make sure to delete the XML results before each test run!

This brings back the reporting functionality that you get running plain PHPUnit with –log-junit 🙂

converting phpunit-selenium assertTextPresent to spinAssert

Just started using SauceOnDemand and was working on adding some new functionality that they offered. One of them is the spinAssert, which is the equivalent of pausing or issuing a waitFor* before asserting something. That’s bad practice because it slows down tests, so spinAssert keeps trying the assertion a set number of times until it fails. This should get rid of our intermittently failing tests!

So I had

But there isn’t really an assertTextPresent in the driver. So here’s the spinAssert alternative:

Ta da!

ssh as a proxy

Sometimes ports are blocked to your local machine and you can only get to them if you are on the client’s machine.

Let’s say you want to connect to port 21 on, but that port is only open to

ssh -N -L

This opens port 1337 on your local machine, and fowards it to port 21 on, using as a proxy.

quick start Linux + PHP + XDebug howto

Ever really debugged before? It’s a life changer. Forget dpm, dd, print_r, var_dump…

1) Install a debugger of your choice (NetBeans, protoeditor, Komodo, Eclipse…)

2) Install/Configure XDebug extension

pecl install xdebug

If you get errors regarding pecl, phpize or missing libraries, try installing the php-pecl and php-devel packages.

Go to /etc/php.d, or wherever your PHP configuration files live. If you see “xdebug.ini” move it to “00xdebug.ini”. THIS IS THE MOST IMPORTANT PART. We have to rename it because XDebug has to run before all other extensions. If you have other extensions like datacache, other debuggers (Zend), or optimizers, you should disable them. Otherwise, XDebug will show as loaded but it won’t work.

Edit 00xdebug.ini and put the following code in:
xdebug.idekey=netbeans-xdebug ;change to same ide key in your debugger

3) Check configuration
Check the output of “php -i” and paste it into It will yell at you if you did anything wrong.

4) Install the XDebug helper for Firefox or Chrome
This allows you to toggle debugging on and off for local sites.

Figure out how to enable debugging in the debugger of your choice and set a break point at a function call. Open up the page in your browser and make sure you use the XDebug helper to set debugging on. Your debugger should halt at the line. Now you can see all your local variables and dive into function calls.

XDebug also profiles. Making a web request with ?XDEBUG_PROFILE=1 in the URL will enable the profile and dump to xdebug.profiler_output_dir. You can take these dumps and use a program like cachegrind to analyze the request.

I use Fedora on a daily basis to debug using Zend Server as my stack, but this will also work on any other configuration (Debian, Mac) – just change the paths to what they are on your system.

taking a screenshot with phpunit and selenium RC

PHPUnit has built in support for taking a screenshot with Selenium and storing it locally (as in, on the server that is running the firefox instance)

This doesn’t work well when you’re running selenium RC, because you won’t know what server firefox eventually runs on.

Fortunately, PHPUnit also implements captureEntirePageScreenshotToString(), which will return a base64-encoded PNG that you can decode and store locally (for example, to provide to Jenkins as an artifact)

In this example, I want to capture the screenshot when the test ends, or when it fails.

You can implement this code elsewhere if you wanted to take screenshots on failure only, after each test, etc…

raid5: cannot start dirty degraded array for mdN

rebuilding a software raid array and stuck with this error? for example, I was rebuilding on a live array and the server took a dive.

try tricking the array into believing its clean, then try to add a new drive or start the array again.

echo "clean" > /sys/block/md0/md/array_state
mdadm /dev/mdN -a /dev/sdXN
mdadm --manage /dev/md0 --run

then do a cat /proc/mdstat

raid should be rebuilding!