3
Running PHPUnit tests for your symfony plugin in phpUnderControl
5 Comments · Posted by Christian in The real job
As I’ve just started to look into phpUnderControl again I thought why not try to setup a project for testing sfImageTransformExtraPlugin running all the PHPUnit tests that I wrote about last week.
So the goal is to setup a phpuc project for a single plugin but with all dependencies (symfony itself) provided. This was a bit tricky so here we go!The first thing I have to say is that although I frequently link to Andries Seutens for installing phpUnderControl for the subject of this post it is not recommended to create a project by running $ phpuc project ..! With this post I will follow the phpuc getting started guide instead.
Creating the project
First we need a project directory.
$ mkdir /path/to/cruisecontrol/projects/yourProjectName
Next we need a very basic ant build.xml file.
// /path/to/cruisecontrol/projects/yourProjectName/build.xml
Now CruiseControl must be told about this new project in its config.xml.
// /path/to/cruisecontrol/config.xml
That the very basic project setup. Next we will need the subject.
Checkout the sources
First we need to create a sources folder for the new project.
$ mkdir /path/to/cruisecontrol/projects/yourProjectName/source
There we checkout the source of our symfony plugin.
// in /path/to/cruisecontrol/projects/yourProjectName/source/
$ svn co http://svn.symfony-project.org/plugins/sfImageTransformExtraPlugin/trunk sfImageTransformExtraPlugin
This alone will not do as there are dependencies that are not included in the plugin. The most important one being symfony itself so we have to check that out as well.
// in /path/to/cruisecontrol/projects/yourProjectName/source/
$ svn co http://svn.symfony-project.org/branches/1.4/ symfony
For sfImageTransformExtraPlugin there is an additional dependency towards sfImageTransformPlugin.
// in /path/to/cruisecontrol/projects/yourProjectName/source/
$ svn co http://svn.symfony-project.org/plugins/sfImageTransformPlugin/trunk sfImageTransformPlugin
So now we have three fresh copies of the two plugins and symfony.
Preparing the build
Before every build we want to update all the sources to test against the latest commits. For this we edit the build.xml again and add the following.
// /path/to/cruisecontrol/projects/yourProjectName/build.xml
...
...
The above will run svn up on all three working copies. You can varify this by running the following.
// in /path/to/cruisecontrol/projects/yourProjectName/
$ ../../apache-ant-1.7.0/bin/ant checkout
Buildfile: build.xml
checkout:
[exec] ...
...
BUILD SUCCESSFUL
Total time: 17 seconds
Running the tests
Before we run the tests we have to create a logs folder to store the build results and we also want a coverage folder to store our coverage reports for the build.
// in /path/to/cruisecontrol/projects/yourProjectName/
$ mkdir -p build/{logs,coverage}
Now we can add a new target to the build.xml.
// in /path/to/cruisecontrol/projects/yourProjectName/build.xml
...
...
All this is more or less copied from the getting started page linked above except for the paths and this on line.
// in /path/to/cruisecontrol/projects/yourProjectName/build.xml
...
...
This line does the same as $ export SYMFONY=/path/to/cruisecontrol/projects/yourProjectName/source/symfony/lib and is needed for the testing bootstrap explained here to find the symfony library.
Of course all this can be tested again.
// in /path/to/cruisecontrol/projects/yourProjectName/
$ ../../apache-ant-1.7.0/bin/ant phpunit
Buildfile: build.xml
phpunit:
[exec] PHPUnit 3.3.1 by Sebastian Bergmann.
[exec]
[exec] .........................................................S.. 60 / 72
[exec] ............
[exec]
[exec] Time: 33 seconds
[exec]
[exec] OK, but incomplete or skipped tests!
[exec] Tests: 72, Assertions: 92, Skipped: 1.
[exec]
[exec] Writing code coverage data to XML file, this may take a moment.
[exec]
[exec] Writing metrics report XML file, this may take a moment.
[exec]
[exec] Writing violations report XML file, this may take a moment.
[exec]
[exec] Generating code coverage report, this may take a moment.
BUILD SUCCESSFUL
Total time: 47 seconds
Activating the targets
The two targets above now need to be triggered. This is done by the build target which can be dependant on other targets.
// in /path/to/cruisecontrol/projects/yourProjectName/build.xml
...
...
Configuring CruiseControl to build your project
Of course now cruisecontrol needs to be told about the details of the build so we edit the config.xml again.
First we need to include the required plugins in this case its for Subversion.
// in /path/to/cruisecontrol/config.xml
Now we want to build the project whenever there was a change to any of the Subversion repositories testing every 60 seconds.
// in /path/to/cruisecontrol/config.xml
...
...
The following tells CruiseControl what to do (running the build.xml through ant).
// in /path/to/cruisecontrol/config.xml
...
...
The following listener adds the build status to the dashboard.
// in /path/to/cruisecontrol/config.xml
...
...
Now let's tell CruiseControl where to find the logs and reports.
// in /path/to/cruisecontrol/config.xml
...
...
Now publish the coverage report and some build metrics produced by phpuc.
// in /path/to/cruisecontrol/config.xml
...
...
Now you can fire up CruiseControl and look at your project.
Of course now you can start thinking about integrating PHP documentor, pdepend, PHP_Codesniffer and the lot.
Next steps for me will be to write the same post again for Hudson-CI and then compare the two.
The final files
Now here are the two XML files.
/path/to/cruisecontrol/projects/yourProjectName/build.xml
/path/to/cruisecontrol/config.xml
Clover · Continuous Integration · CruiseControl · Integrations Tests · phpUnderControl · phpUnit · Plugin · sfImageTransformExtraPlugin · symfony · Test Coverage · Tests · Unit Tests


Pingback: Tweets that mention • Running PHPUnit tests for your symfony plugin in phpUnderControl | test.ical.ly -- Topsy.com
Pingback: • Running PHPUnit tests for your symfony plugin in phpUnderControl … | Programming Blog Imagik.org
Pingback: • Running PHPUnit tests for your symfony plugin in phpUnderControl … « svn
Pingback: • Continuous Integration: Hudson vs phpUnderControl | test.ical.ly