Running VisualPHPUnit in Windows Azure

Author: Brian Swan <>

Date: Wednesday, March 21, 2012, 12:40:35 PM

Tags: Tutorial

Table of Contents

    Note:This article pertains to the CodePlex SDK initially released late 2009. The Windows Azure team has since then released a newer version of the Azure SDK for PHP on Github. Please refer to the Windows Azure PHP Developer Center for documentation on this more recent version of the SDK.

    Please stay tuned and come back here regularly as we are working on refreshing the tutorials to deliver up to date and useful content for our PHP developers.


    In this post I'll cover how to use a web-front end (VisualPHPUnitspecifically) 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:


    That's it!

    Hope that's helpful.


blog comments powered by Disqus

Related Content