Unit testing in PHP with PHPUnit
With this dynamic data model that I am currently building in PHP, I found that for quite a complicated solution I had no unit testing at all.
After searching around I found PHPUnit, however, it all hinted at a Linux only environment. A short while later I found a blog that described how to set it up for Windows: http://usingzendframework.blogspot.com/2007/12/setting-up-phpunit.html. I use Xampp, so I did not have to change the memory limit.
Once installed I used the online pocket guide to start me off: http://www.phpunit.de/pocket_guide/index.en.php
Inside my code folderĀ I created a tests folder where I placed all my php tests, inside that I created an includes folder for all the test related code.

The first thing that the common include does is turn on all the error reporting an strict reporting. This should ensure the most quality coding.
<?php
error_reporting(E_ALL | E_STRICT);
require_once('PHPUnit/Framework.php');
?>
Once that is done, I could start with writing all the tests.
<?php
include('includes/common.php');
class ExampleTests extends PHPUnit_Framework_TestCase
{
public function testSomeObjectTest()
{
/* Test code here */
}
}
?>
Once that was done, I created a msbuild script to test them all using the TestSuite class
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
<PropertyGroup>
<BuildDir>$(MSBuildProjectDirectory)</BuildDir>
</PropertyGroup>
<ItemGroup>
<CodeFiles Include="$(BuildDir)***.php" Exclude="$(BuildDir)**.svn***.*;
$(BuildDir)**tests***.*" />
</ItemGroup>
<Target Name="Build">
<CallTarget Targets="RunTests" />
</Target>
<Target Name="RunTests">
<Exec Command='phpunit --verbose "$(BuildDir)testsTestSuite.php"' WorkingDirectory="$(BuildDir)tests" />
</Target>
</Project>
I had to add the framework folder and the php folder onto the PATH environment variable so that I could just call msbuild from the commandline