Archive for cruisecontrol

Setting up phpUnderControl (and CruiseControl) under debian etch

This might not be as useful since we finally have debian lenny available, but then again, maybe it will be useful for some people out there.

I had to setup phpUnderControl (and CruiseControl) at my job to manage our day to day work, and it took quite a bit of time to figure out how to setup everything properly from the ground up. This post is derived from my notes that we keep in our internal wiki.

  1. Edit /etc/apt/sources.list and make sure the unstable repo is listed in there
    deb http://ftp.debian.org/debian/ unstable non-free
    deb-src http://ftp.debian.org/debian/ unstable non-free
    
  2. apt-get update
  3. apt-get -t unstable install sun-java6-jre sun-java6-jdk
  4. Run “java -version” to verify the installation
    root@etch-64-dev-ui:~# java -version
    java version "1.6.0_10"
    Java(TM) SE Runtime Environment (build 1.6.0_10-b33)
    Java HotSpot(TM) 64-Bit Server VM (build 11.0-b15, mixed mode)
    
  5. Add JAVA_HOME to /etc/environment:
    JAVA_HOME="/usr/lib/jvm/java-6-sun"
    
  6. source /etc/environment
  7. Download binary distribution of CruiseControl (available here: http://cruisecontrol.sourceforge.net/download.html)
  8. Install CruiseControl:
    $ unzip cruisecontrol-bin-2.7.3.zip -d /opt
    $ ln -s /opt/cruisecontrol-bin-2.7.3 /opt/cruisecontrol
    
  9. Install PEAR (if it’s not already there):
    $ apt-get install php-pear
    
  10. Upgrade PEAR to latest release:
    $ pear upgrade-all
    
  11. Install PHPUnit and phpUnderControl:
    $ pear channel-discover pear.phpunit.de
    $ pear install phpunit/PHPUnit
    $ pear install --force --alldeps phpunit/phpUnderControl
    $ phpuc install /opt/cruisecontrol
    
  12. Install Xdebug (needed for code coverage analysis):
    $ pear install pecl/xdebug
    
  13. Add Xdebug zend extension to php.ini (on our case /etc/php5/cli/php.ini):
    zend_extension="/full/path/to/xdebug.so"
    
  14. Create a CruiseControl project for your existing PHP project’s unit tests:
    $ phpuc project --version-control svn --username "cruisecontrol" --password "password_here" --version-control-url svn://svn.domain.com/repository/project-name/trunk --test-case MyProjectTestSuite --test-dir "/opt/cruisecontrol/projects/my-project/source/unit_tests" --test-file "MyProjectTestSuite.php" --project-name MyProject /opt/cruisecontrol
    
  15. Edit projects/MyProject/build.xml so it contains the following content:
    <?xml version="1.0" encoding="UTF-8"?>
    <project name="MyProject" default="build" basedir=".">
      <target name="build" depends="php-documentor,php-codesniffer,phpunit"/>
      <target name="php-documentor">
        <exec executable="phpdoc" dir="${basedir}/source" logerror="on">
          <arg line="--title '${ant.project.name}' -i *pear/*,*Smarty/*,*fpdf/*,*jpgraph/* -ue on -t ${basedir}/build/api -d ${basedir}/source/lib -tb '/usr/share/php/data/phpUnderControl/data/phpdoc' -o HTML:Phpuc:phpuc"/>
        </exec>
      </target>
      <target name="php-codesniffer">
        <exec executable="phpcs" dir="${basedir}/source" output="${basedir}/build/logs/checkstyle.xml" error="/tmp/checkstyle.error.log">
          <arg line="--ignore=*/PEAR/*,*/Smarty/*,*/fpdf/*,*/jpgraph/*,*/misc/* --report=checkstyle --standard=PEAR ${basedir}/source"/>
        </exec>
      </target>
      <target name="phpunit">
        <exec executable="phpunit" dir="${basedir}/source/unit_tests" failonerror="on">
          <arg line=" --log-xml ${basedir}/build/logs/phpunit.xml --log-pmd ${basedir}/build/logs/phpunit.pmd.xml --coverage-xml ${basedir}/build/logs/phpunit.coverage.xml --coverage-html ${basedir}/build/coverage MyProjectTestSuite /opt/cruisecontrol/projects/MyProject/source/unit_tests/MyProjectTestSuite.php"/>
        </exec>
      </target>
    </project>
    

You will need to tweak a few things, like the “MyProject” name and probably some of the “ignore rules” for phpCodeSniffer, but it should be a great starting point for most projects.