Dominique Stender Good software is only the beginning

30Nov/092

HOWTO: Continuous integration for PHP, pt. 4

cloudsThis is the fourth article in my series about continuous integration for PHP. You might want to read the first, second and third article prior to this.

We're getting closer and closer to full test automation and continuous integration. The last article introduced you to how to write PHPUnit tests for SeleniumRC so that we can test website frontends through PHPUnit. After that we wrote our own phing build script that ran our backend as well as the frontend tests automatically, generated an code coverage report based on Xdebug as well as an comprehensive APIDoc based on PHPDoc comments.

The phing build script we used for this - test.xml - was executed manually by calling

phing -f test.xml

on the command line. Everything happened on the development virtual host.

The next logical step is to automate this and perform the additional tasks required to run continuous integration.

The first step is to do a manual svn checkout on the integration virtual host, so we have setup that is identical to the development virtual host.

Now, what the automation will have to do is a Subversion update of the integration virtual host in order to retrieve the latest copy. If the revision changes in that process (that is, if we indeed fetched newer files from Subversion) we again run the tests and generate the reports. If all tests succeed we can safely assume that we have a running system, and we can decide to create a tarball from it or update the staging system for our project manager / client to check it out. On the other hand, if a test fails we'd like to be notified by email.

This is exactly what a second phing build script will do.

27Nov/092

HOWTO: Continuous Integration for PHP, pt. 3

gourdThis is the third article in my series about continuous integration for PHP. You might want to read the first and second article prior to this.

In this article I want to introduce you to the way I run the continuous integration tests, what to run when, and where. If you're unsure how to write unittests, this will not be covered in this article but phpunit.de has an excellent documentation section just covering how to write tests. Another section is there covering how to write tests for SeleniumRC.

Let me start this article with a short summary of what we have installed in the second part: We have a pretty standard LAMP server based on Ubuntu Linux. Then there is PHPUnit for unit and regression testing as well as phing, our integration server. We added SeleniumRC as a frontend test tool, then Xvfb and Firefox to facilitate the frontend tests. xdebug is used by PHPUnit for code coverage reports and phpDocumentor will be used by phing for automatic APIdoc generation.

A Subversion client to fetch latest updates out of the repository completes the setup.

Ok, let's dig a little deeper into the filesystem structure and how to use it, shall we?

22Nov/094

HOWTO: Continuous Integration for PHP, pt. 2

This is the second in the series of articles on continuous integration for PHP. You might want to start reading the first article, covering the basic tools in the setup before you continue here.

Here I will give you a step-by-step guide how to set up a LAMP server with all the necessary tools to run a thorough set of tests and reports.

As of this writing Ubuntu Linux version 9.10 (Karmic Koala) has just been released. Personally I like Ubuntu for its ease of use, so this howto will focus on that. I assume that the general setup will be slightly different if you use another flavor of Linux, though.

If you don't have a spare computer lying around just yet, install VMWare Server. That will get you going well enough to convince your manager that a few hundred bucks for a medium-spec server will be well invested money.

This step of the tutorial assumes that you're at least somewhat familiar with the Linux command line. If you are not, do yourself a favor and get in touch with one of your system administrators. Make him understand what you want and convince him to divert from the typical company guidelines for server installation. You might want to show him this:

This will be a test server. It will not run in production. It will never be accessible by the public. It'll be a proof of concept and will be replaced by a server compliant to all guidelines once this proof of concept is approved by management.

For those of you who do this on their own: The above paragraph is for you. All aspects of creating a secure, well administered server with backup are ignored in this tutorial. Do not attempt to run this box online.

One more comment. Even if you're convinced that you'll not be using one of the packages or reports described below, just install them for now. The whole setup is well under 2GB and it works. Removing a package might break things.

This being said, are you ready for the installation?

20Nov/090

HOWTO: Continuous Integration for PHP, pt. 1

bubblesAfter my initial post which gave only a rough outline on how to install all the various components for a continuous integration environment for PHP I had to struggle quite a bit to get everything to work. There doesn't seem to be a tutorial or howto online that goes to the level of depth required. Hence I decided to make my own.

This will be a series of several posts where I will try to cover all basic aspects of continuous integration for PHP:

An informational article about what continuous integration is all about.

After that I'll give you a step-by-step guide on how to set up a continuous integration environment using a virtual environment.

I will provide you with an example build script for automated local tests in the third article.

The fourth article will put all things together and establish continuous integration.

This article will cover the first topic "What is continuous integration all about?".

Continuous integration is an important aspect in agile development methodologies and test driven development.

The whole idea behind continuous integration is to have a process running in the background that integrates and tests the various pieces of source code that you generated continuously and automatically. In a nutshell, that's it.

Why would we want to automate our testing? Well I believe that is obvious:

  1. Testing is hard.
  2. Testing is boring.
  3. Testing is time consuming.
14Nov/090

New VM, first tests with Phing

I spent some time today to set up a new Virtual Machine. My current development system is based on Ubuntu Intrepid and starts acting up. I can't really isolate the issue, some network trouble is there.

Anyways... originally I just wanted to tap a bit into test automation [1, 2] but I ended up downloading the 32bit server version of Ubuntu Koala. With my crappy Tata Photon+ it took a while until the CD .iso file was there but after that it went smooth. The installation system is pretty straight forward and did a decent job of detecting my keyboard.

I chose the LAMP, OpenSSH, Samba packages and let it install.

After that it was just a matter of installing a few more php packages, along with PEAR. This enabled me to set up everything I needed to get a glimpse of what test automation is all about.

# install PHPUnit (make sure you catch the dependencies)
> pear channel-discover pear.phpunit.de
> pear install phpunit/PHPUnit

# install PhpDocumentor
> pear install PhpDocumentor

# install Phing (once more, cover the dependencies)
> pear channel-discover pear.phing.info
> pear install phing/phing
 

In case you're in doubt what all this means:

PHPUnit is the unittesting tool for PHP, a clone of JUnit basically...
PhpDocumentor generates a Html (.pdf, ...) API Doc out of your source code comments...
and finally Phing is a build tool written in and for PHP.

The whole setup tool me less than two hours after the .iso file was there, and that includes additional things like setting up a Samba share and configuring two VirtualHosts for Apache. Really cool and really really smooth.

Now with a short but to-the-point article on Linux.com I got a test scenario running. What joy! you simply enter 'phing' on the commandline and the tools clear up the build filesystem, fill the build again with the latest version of the software, run PhpDocumentor to generate the up-to-date APIDoc, then run all unittests and in case those succeed they generate a tarball with the whole system.

How cool is that?! Really impressive. Those who know me also know that it's hard to impress me ;) .
[Update: By now there is a much more in depth series of articles online here in my blog]