Posts Tagged ‘PHPUnit’


Zend_PHPUnit_Fixtures uploaded to GitHub

December 4, 2008

Well I’ve been working on this project (Zend PHPUnit Fixtures) along with a few collegues over the past few months, It was my intension to submit it to Zend some point in the new year but thought I’d put it out in the wild for others to pick at.

Well I use TDD (PHPUnit is my friend) on a daily basis within ZendFramework and soon found it cumbersome to create test data (fixtures) ending up in huge test cases with more test data setup than actual assertions, this matched up with the fact that I hate integrating DB into my tests (mainly because the tables would still contain old test data & fail depending on whether the data was added in previous tests or not) So I decided to do some digging, the best solution seemed to be to create a fixture handling system that plugs into ZendFramework, leaving myself and others with more time actually testing and less time building up test data and removing fixtures from a database (which can be near impossible when it comes to automated testing).

With this realisation I decided to create my own which I’ve reversed engineered from CakePHP. When I have the time (hopefully over the holidays) I’ll go into how the mini framework can be used. For now I’ll just describe the features or each class and what they are for:-


Basic fixture handler, used for creating test data that does not interact with a DB. With this object we are able to create basic fixtures that we can use for dummy data with our test cases. Each piece of test data can have an alias (‘ALIAS’) with the aliases name as the value, doing so will allow us to use the PHPUnit_Fixtures::find($aliasName) which will retrieve the desired fixture.


Has the same functionality as PHPUnit_Fixtures but used specifically for DB centric tests, DB test data will be added to our ‘_test’ DB, and cleaned up (truncated) on each test case, to make sure that we have the expected data.


Has the same functionality as PHPUnit_Fixture_DB, with the added functionality of being able to create tables setup my MySQL Workbench. With an child object of this class we are able to specify retrieving all schema or a specific on (denoted by the schema table name).


Used to handle our development environments, there are times when we want to quickly place test data on our staging DB for functionality testing and the such like, this class along with one of our PHPUnit_Fixtures, will easily allow us to populate this environment with the data we have been using for our unit tests, making it quicker to migrate test data from one place to another.

You can find the project at GitHub, If anyones interested in adding to this project or have any comments/questions drop me a line.


Installing ZendStudio 6.1

October 20, 2008

Okay, I’ve done this so many times & helped a few people do the same that I thought It would be a good idea to actually document the process. I’ll explain the basic steps to getting ZendStudio working with PHP5.2.6 & PHPUnit3, this setup will allow you to use the same library files as the actual system instead of the environment prepacked with ZS6.1 (I prefer this way as running tests in ZS6.1 should produce the same results when run via CLI.

ZF latest version
ZendStudio for Eclipse 6.1

Make sure that php is atleast at version 5.2 (php -v will tell you the version), update if needed. Download Zend Framework and place in your php include path (typically /usr/share/php or /usr/share/pear).

If pear is not installed we’ll need install it using the following for Debian based systems (remember you’ll need to be root to install via apt or yum).
apt-get install php-pear
yum install php-pear
for RHEL based systems.

cd /opt &&
wget &&
unzip &&
cd ZendFramework-1.7.0PR/library/ &&

Now we have ZF within our include path we need to setup PHPUnit & ZendStudio.
pear channel-discover
pear install phpunit/PHPUnit

We need to download ZendStudio from here & running the file
./ZendStudioForEclipse-6_1_0.bin Follow the instructions & wait for the installation to complete.

Now we’ll need to customise ZS so that it will work with using the systems PHP & PHPUnit instead of the ones packed with ZS.

We’ll need to setup ZendDebugger to work with our systems php.ini file, so we will need to copy ZendDebugger from ZS and place in with the other modules.
cp /PATH/TO/ZEND/plugins/org.zend.php.debug.debugger.linux.x86_5.2.14.v20080602/resources/php5/ /usr/lib/php5/

Here we need to add the below text into our php.ini file, ideally at the bottom, so it is easy to find.

Once installed and started, select Window, Preferences & you’ll be given a window simular to below.

Click Add, which will bring up the dialog box below.

Enter the following, the path to the systems php executable & your php.ini file as entered in the above screenshot and click Finish.

The dialog box will close and leave you with Figure 1.1, select the newly added settings and click Default. We have now setup ZS to work with our systems PHP version instead of the one packed with ZS.

We now need to add a our PHP include path to ZS so that we have all our library files available for ZS.

Click New, which will display the below dialog box, this is where we need to set our current PHP path, the screenshot below displays an example.

Once the include path has been added we click OK and OK again, now when ever we create a new project, we will just remove the predefined paths and just include our one.

Well that’s it, now we should be able to run tests within ZendStudio & the shell, knowing that our results come from the same environment..