Archive for PHP

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.

Follow-up on HttpWatch integration with Selenium

Simon Perkins of Simtec Ltd (makers of the HttpWatch plugin for Internet Explorer that I mentioned before) was kind enough to get in touch with me via email about my wishlist for YSlow / HttpWatch / AOL Pagetest.

He wasn’t familiar with Selenium, but said that it might be possible to hook up HttpWatch to retrieve performance data dynamically. He pointed to a blog post describing how to do so with Watir, an automated web testing tool written in Ruby. Simtec even has a tutorial about this on their own web site.

While that does sound interesting, it looks like Watir interfaces with HttpWatch with a COM object on Windows, and that’s how it gets the performance information.

The way to do this integration with Selenium would be to expose a set of JavaScript APIs (maybe the same set of objects available through the COM layer?), so one could write JavaScript code to export the HttpWatch information. That’s really what I would love to see.

If that was available, I could write a simple Selenium RC test suite in PHP, remote control a set of browsers from my Linux box, and get access to this performance data from HttpWatch by simply running some JavaScript function.

Using Selenium RC with multiple users

Zachary Fox (from Alert Logic too) wrote a very good tutorial on how to run Selenium RC to execute unit tests in a team environment.

If you have multiple users running unit tests concurrently against the same Selenium RC server, some nasty things may happen. Zach explains how to properly setup multiple Selenium RC servers, so everyone can work on their own server.

FirePHP – Debugging PHP applications with Firebug

FirePHP Screenshot

FirePHP seems like a very cool project, allowing PHP developers to debug applications without having to disrupt the normal process of a script. It works by sending the debug content to the browser in special HTTP headers, and the Firefox extension add-on to Firebug will parse those and display them in a special panel within Firebug.

It’s so useful I’m going to install this right now. I can’t believe nobody else thought about doing this before!

Generating Graphs with PHP and Google Charts API

Ludwig Pettersson has a really good overview of the Google Charts API, and how you can integrate your PHP scripts with it. He created a PHP library that wraps around the API, and makes it really easy to generate graphs that way.

I’m not sure if I would move away from JpGraph to this new library, but it seems really cool no matter what. I guess it could be an option if you wanted to avoid doing all of the manual work associated with different types of graphs, and offload some graph generation to Google.

« Previous entries Next Page » Next Page »