Running VisualPHPUnit in Windows Azure

Last month, I wrote a post that outlined 3 ways to test PHP applications in Windows Azure, and since then I’ve covered two of those approaches: Running PHPUnit in Windows Azure (uses RDP) and Automating PHPUnit Tests in Windows Azure. In this post I’ll cover how to use a web-front end (VisualPHPUnit specifically) to run tests in Azure.

If you have PHPUnit installed locally (and I’m assuming you have it installed as a PEAR package), then running VisualPHPUnit locally is a breeze – simply follow the directions in the README:       

1.Download and extract the project to a web-accessible directory.
2. Open config.php with your favorite editor.
1.Change PEAR_PATH so that it points to the directory where PEAR is located.
2.Update TEST_DIRECTORY so that it points to the root directory where your tests are stored.
3.Point your browser to the location where you installed VisualPHPUnit!

Note: I put VisualPHPUnit in my application root directory, which seemed to cause one problem: My tests are in the ‘tests” directory (which is in my application root). Each test has a require_once “.\ClassName.php” statement (as required by PHPUnit). However, when I browse to the VisualPHPUnit directory, the working directory is one directory “down”. So, I needed to change the require statements to require_once “..\ClassName.php” in order for the referenced files to be found. This is unfortunate if you have lots of tests, but I haven’t found a workaround yet (I’m certainly open to suggestions).

Once VisualPHPUnit is installed, continue developing/testing your application locally. When all your tests are passing and you are ready to move your application to Windows Azure, you’ll need to make two changes to the VisualPHPUnit configuration. Here’s what you need to do:

1. Edit VisualPHPUnit config.php file like so:

// The directory where PEAR is located
define('PEAR_PATH', dirname(getcwd()).'\bin\PHP\PEAR');

// The directory where the tests reside
define('TEST_DIRECTORY', dirname(getcwd()).'\tests');

Note: This assumes your tests directory is in your application root directory.

2. (Optional, but suggested): Password protect the VisualPHPUnit directory. Instructions for doing this are in this post: How to Password Protect a PHP Website Directory in Windows Azure.

3. Follow the steps for packaging and deploying a custom PHP installation in this post: Packaging a Custom PHP Installation for Windows Azure.

After you have deployed your app, you should be able to browse to the VisualPHPUnit directory, select and run your tests, and see the results:

image

That’s it!

Hope that’s helpful.

-Brian

Share this on Twitter