PhpUnderControl Framework For Symfony Projects

Just another WordPress.com weblog

  • July 2008
    M T W T F S S
         
     123456
    78910111213
    14151617181920
    21222324252627
    28293031  

Posted by anoopvdk on July 29, 2008

Introduction

phpUnderControl is an extension for Cruise Control that integrates several PHP development tools, such as

  • PHPUnit
    • Which contains a rich set of features like Unit Testing and Functional Testing, Code Coverage, Project Mess Detection and Software Metrics etc,
  • PHP_Code Sniffer
    • For static code analysis
  • PHPDocumentor
    • For API documentation generation. It comes with a powerful command-line tool that can, among other things, automatically create Cruise Control’s XML configuration files for your project.

Initial Setups for phpUnder Control

Prerequisites

  1. JDK Version 1.5 or above
  2. Symfony Framework

Setting Up JDK

  1. Download & extract Latest JDK from SUN Java to /usr/java (Standard path)
  2. Setup the environment (Linux)
    1. Edit /etc/profile and add the below to make it available global
    2. export JAVA_HOME=/usr/java/jdk1.6.0_06
    3. export PATH=$PATH:$JAVA_HOME/bin
    4. save and exit.
    5. A restart or #source /etc/profile would require to make the changes effective.
    6. Check the version details Execute the command “java -version”. Should see something like
java version “1.6.0_06”
Java(TM) SE Runtime Environment (build 1.6.0_06-b02)
Java HotSpot(TM) Client VM (build 10.0-b22, mixed mode, sharing)

Setting symfony and plugins

  1. Install the symfony framework.
Further information on installing symfony framework can be obtained from http://www.symfony-project.org/installation/1_1
  1. Install the sgtest4cruise plugin.
    1. Download plugin from symfony plugins for cruise control.
    2. Put this file in the plugins directory of your application.
    3. Add the plugin to “enabled_modules” in settings.yml of your application.
    4. Modify the following variables to the needs of your project in app.yml of your application:
  • app_test4cruise_lime_file: path to the lime.php file in Symfony
  • app_test4cruise_sg_lime_file: path to the extended library
  • app_test4cruise_log: path to generated log file

Setting CruiseControl CodeBase

As mentioned earlier phpUnderControl is extension of Cruise Control, so we want to set up Cruise Control first.

  1. Just download cruise control 2.7.2 (or recent version) archives from “sourceforge.net”.
  2. Unzip the contents into an arbitrary folder (CCHOME)

Install phpUnderControl

The preferred way to install phpUnderControl is PEAR installation. The following steps will helps to install phpunderControl on to your system

  1. pear config-set preferred_state beta
  2. pear channel-discover components.ez.no
  3. pear channel-discover pear.phpunit.de
  4. pear install –alldeps phpunit/phpUnderControl

Patch your phpUnderControl with cruise control

Simple ! Execute the following command from terminal window.

  • phpUnderControl/bin/phpuc(.php|.bat) install /path/to/cruise control

Folder Structure

Now you should create a well defined folder structure for the phpundercontrol framework. First of all we need to

  1. create a new folder with your project name in” ./cruise control/project/ “ path. After that we can use svn checkout for getting the latest version of the application and put it under “/path/to/cruisecontrol/project/project name/ “ folder with a new folder name as source. Else we can also create symbolic link with same name(source) and pointed to your actual application path (Only if the website is hosted locally on that particular server).

Now the time to create your log files, it is better to create all log files under a common folder. So create a folder with name build under “/path/to/cruise control/project/project name/ “ cruisecontrol latest

Create separate folders for log doc etc under build folder

Now your framework’s folder structure looks like below

+ cruisecontrol

+ projects

+ <Your project name>

+ source

+ build

+ logs

+ doc

+ coverage

Now your phpundercontrol Framework is ready. Now you can create a build file for your application under project name folder and edit config file for phpundercontrol under cruise control folder. Now the folder structure like

+ cruisecontrol

config.xml

+ projects

+ Your project name

build.xml

+ source

+ build

+ logs

+ doc

+ coverage

Create Build.xml

This section describes how to configure your project using “ant” build method

At first the file should contain the following lines.

<?xml version=”1.0″ encoding=”UTF-8″?>

<project name=”project name” basedir=”/path/to/cruisecontrol/projects/project name/”>

</project>

Working Copy Target

We need a working copy of our application on which the build process is executed . Its much preferred to create a symbolic link to the actual path of your application if both application and phpUnderControl are running on same server. Otherwise go for svn checkout option, For that create a new target method under <project>. The parameter for svn update is

<target name=”checkout”>

<exec executable=”svn” dir=”${basedir}/source”>

<arg line=”up” />

</exec>

</target>

* Please note that we need to do an initial checkout before starting an svn update.


Unit Test Target

Here we use lime test for running the tests rather than phpunit because symfony framework does not support phpunit. Unit test command are as follows

<target name=”unitTest” >

<exec dir=”${project.dir}” executable=”php” failonerror=”true”>

<arg line=”symfony sg-test4cruise ${test.app.name}” />

</exec>

</target>

Before that mention {project.dir} and {test.app.name}. Here {project.dir} is ${basedir}/source and {test.app.name} is depends on your application.

PHPDocumentor Target

We have to add new target Phpdocumentor for generate documentation of our php files on each build. The commands are as follows

<target name=”phpDocumentor”>

<exec executable=”phpdoc” dir=”${application.dir}”>

<arg line=”-i om/,map/ -d src/ -t ${log.dir}/doc” />

</exec>

</target>

Where

-i –ignore : file(s) that will be ignored, multiple separated by ‘,’. Wildcards * and ? are ok

-d –directory : name of a directory(s) to parse directory1,directory2

-t –target : path where to save the generated files

{log.dir} : ${basedir}/build/

{application.dir}: Depends on your application

CodeSniffer Target

PHP_CodeSniffer is a PHP5 script that tokenises and “sniffs” PHP and JavaScript code to detect violations of a defined coding standard. It is an essential development tool that ensures your code remains clean and consistent. It can also help prevent some common semantic errors made by developers. The build commands for this

<target name=”phpCodeSniffer”>

<exec executable=”phpcs” dir = “$${project.dir}” output= “${log.dir}/log/ CodesnifferResult.xml”/> <arg line=”–report=checkstyle –standard=Symfony –ignore= what are the files you want to exclude from code sniffs activity”/>

</exec>

</target>

Deleting the Existing Log files

If you want delete all log files before run the build then you need to create a new target ‘init’for that

<target name=”init”>

<delete>

<fileset dir=”${log.dir}/” includes=”**/*.*”/>

</delete>

</target>

Finishing the ant build file

Finally we have to combine the four independent targets into a single target. So create we create a new target ‘all’ that depends on the other four. And the commands

<target name=”all” depends=”init, phpCodeSniffer, phpDocumentor, unitTest” />

</project>

The final build.xml file look like this

<?xml version=”1.0″ encoding=”UTF-8″?>

<project name=”project name” basedir=”/path/to/cruisecontrol/projects/project name/”>

<property name=”base.dir” value=”source”/>

<property name=”log.dir” value=”build” />

<property name=”application.dir” value=”${base.dir}/to your application working patht”/>

<property name=”test.app.name” value=”Applicatin name” />

<property name=”project.name” value=”projectname”/>

<target name=”all” depends=”init, phpCodeSniffer, phpDocumentor, unitTest” />

<target name=”init”>

<delete>

<fileset dir=”${log.dir}/” includes=”**/*.*”/>

</delete>

</target>

<target name=”unitTest” >

<exec dir=”${project.dir}” executable=”php” failonerror=”true”>

<arg line=”symfony sg-test4cruise ${test.app.name}” />

</exec>

</target>

<target name=”phpDocumentor”>

<exec executable=”phpdoc” dir=”${application.dir}”>

<arg line=”-i om/,map/ -d src/ -t ${log.dir}/doc” />

</exec>

</target>

<target name=”phpCodeSniffer”>

<exec executable=”phpcs” dir = “$${project.dir}” output= “${log.dir}/log/ CodesnifferResult.xml”/> <arg line=”–report=checkstyle –standard=Symfony –ignore= what are the files you want to exclude from code sniffs activity”/>

</exec>

</target>

</project>

Cruisecontrol Config File

CruiseControl have one configuration file config.xml that holds all projects. This file can be found the CruiseControl main directory. The main steps are

a) First of all we need to add project element for our projet.

<project name=”phpundercontrol.org” buildafterfailed=”false”> the buildafterfailed can be used to force CruiseControl that it retries to build a project, after a failed build without changes to the project sources. This option can be useful if the build process is based on an external resource, like a database server that could timeout during the build process.

b) Including required plugins

if we use svn checkout for getting the application then we must load corresponding plugin to the config.xml file

<plugin name=”svn”

classname=”net.sourceforge.cruisecontrol.sourcecontrols.SVN” />

c) Modificationset

It describe when will a new build happen, We can configure it in two methods first one by defining time intervells and second one is when there was a source.

<modificationset quietperiod=”60″>

<svn localWorkingCopy=”projects/${project.name}/source/”/>

</modificationset>

d) Schedule

schedule element defines the number seconds to wait between two builds. The default schedule interval is 300 seconds(five minutes).

<schedule interval=”6000″>

<ant anthome=”apache-ant-1.7.0″ buildfile=”projects/${project.name}/build.xml”/>

</schedule>

e) Listeners

<listeners>

<currentbuildstatuslistener file=”logs/${project.name}/status.txt”/>

</listeners>

f) Bootstrappers

<bootstrappers>

<antbootstrapper anthome=”apache-ant-1.7.0″ buildfile=”projects/${project.name}/build.xml” />

</bootstrappers>

g) Logging

Here we merge the logfiles

<log>

<merge dir=”projects/${project.name}/build/”/>

</log>

h) Publishers

By using this we publish our results and send build status to the corresponding team members

<execute command=”phpuc graph logs/${project.name} artifacts/${project.name}” />

<artifactspublisher dir=”projects/${project.name}/build/doc” dest=”artifacts/${project.name}” subdirectory=”doc”/>

<artifactspublisher dir=”projects/${project.name}/build/coverage-report” dest=”artifacts/${project.name}” subdirectory=”coverage”/>

<email mailhost=”host”

returnaddress=”Daily-build@qburst.com”

buildresultsurl=”${build.url}/buildresults/${project.name}”

skipusers=”false”>

<!–Add the SVN commit users ID and e-mail address–>

<map alias=”PL” address=”pl@urcomapany.com”/>

<always address=”me@urcomapany .com” />

</email>

</publishers>

The final config file look like

<cruisecontrol>

<plugin name=”svn” classname=”net.sourceforge.cruisecontrol.sourcecontrols.SVN”/>

<project name=”project name”>

<listeners>

<currentbuildstatuslistener file=”logs/${project.name}/status.txt”/>

</listeners>

<bootstrappers>

<antbootstrapper anthome=”apache-ant-1.7.0″ buildfile=”projects/${project.name}/build.xml” />

</bootstrappers>

<modificationset quietperiod=”10″ requiremodification=”false”>

<svn filesystem folder=”projects/${project.name}”/>

</modificationset>

<schedule interval=”6000″>

<ant anthome=”apache-ant-1.7.0″ buildfile=”projects/${project.name}/build.xml”/>

</schedule>

<log>

<merge dir=”projects/${project.name}/build/log”/>

<merge dir=”projects/${project.name}/source/log”/>

</log>

<publishers>

<execute command=”phpuc graph logs/${project.name} artifacts/${project.name}” />

<artifactspublisher dir=”projects/${project.name}/build/doc” dest=”artifacts/${project.name}” subdirectory=”doc”/>

<artifactspublisher dir=”projects/${project.name}/build/coverage-report” dest=”artifacts/${project.name}” subdirectory=”coverage”/>

<email mailhost=”host”

returnaddress=”Daily-build@qburst.com”

buildresultsurl=”${build.url}/buildresults/${project.name}”

skipusers=”false”>

<!–Add the SVN commit users ID and e-mail address–>

<map alias=”PL” address=”pl@urcomapany.com”/>

<always address=”me@urcomapany .com” />

</email>

</publishers>

</project>

</cruisecontrol>

Notes :

1) By defult we can see the result using URL http://localhost:8080. But we can config this URL by adding a extra property in the config file <property name=”build.url” value=”http://your URL:5001″ />

If we enter different port other than 8080, then you should also change the jmxport -webport -rmiport in cruisecontrol.sh/cruisecontrol.bat file

2) You can make sure that file names coverage and doc are same in the main.jsp file

3) You can change the styles of the phpundercontrol page by editing the jsp files in the cruisecontrol/webapps/cruisecontrol/

Reference

http://www.phpundercontrol.org

Symfony plugins for Cruisecontrol

Advertisements

19 Responses to “”

  1. Alex said

    Your blog is interesting!

    Keep up the good work!

  2. Teikweidi said

    Where does the Symfony PHP_CodeSniffer coding standard come from? I have been searching and searching for something that would enforce the standard that is published in the Symfony wiki. I had hoped that it already existed, but a question to the Symfony forum didn’t turn up much. If you have some sniffs that you use, would you mind sharing?

  3. anoopvdk said

    Hi Teikweidi,
    I am always happy to share my limited knowldge.
    Could you please give your any contact id? then
    I will send a folder, that contains all the documents you needed.

    Thanks
    Anoop

  4. Teikweidi said

    Hi Anoop,

    I had submitted my email via the post (required), can you see it as the post moderator? If not my email is teikweidi at the domain yahoo.

    Thanks for sharing, and for this post. I am interested in phpUnderControl, mostly because of this post, and one that I saw on the forum.

  5. anoopvdk said

    Hi Teikweidi,
    I have just sent a mail with some some code sniffer standards, we have used in our projects to you. Please check your mail inbox. Sorry for the delay, actually I was not in office for last few days.
    Thanks
    Anoop

  6. Teikweidi said

    Hi Anoop,

    Its rare that you get the true spirit of public domain, and real sharing of code/ideas. Thanks for such generosity! Not only does it save time, but it helps me and my developers think about solutions in a different light. I work at a University, and we are doing excellent work in the Public Domain. If we make any decent modifications or additions, I’ll make sure to check back in to see if they’ll be useful to you. After I have had some time to digest the sniffs, I can also follow up on the Symfony list with some ideas (and give credit where its due).

    Once again, thanks, and have a great weekend 🙂

  7. Bob said

    Hi Anoop,

    It would be very helpfull if you can send the Symfony PHP_CodeSniffer files to me.
    Thanks a lot for sharing your work.

    Best regards,
    Vincent.

  8. Jan Markmann said

    Would you mind sharing that sniffs with the symfony community? Maybe post them in the symfony wiki as quite some other useful development resources are shared there.
    Thanks in advance….

  9. Teikweidi said

    The Coding Standard/Sniffs you sent us have proved tremendously useful, thanks so much and happy holidays!

  10. anoopvdk said

    Hi Teikwedi,

    It’s really good to hear that “Coding Standard/Sniffs” really useful for you.

    Thanks for your wish, and wish you a great holidays for you also.

  11. Patrick said

    hi,

    nice tutorial 🙂

    but i am trying to install the plugin in my symfony app, but the package does not seem to be a proper plugin package and thus cannot be installed through symfony plugin:install. do i have to install the plugin or is it enough to put the files in the plugin folder?

  12. Salim said

    Hi Anoop,

    I found your post very interesting, but I have some trouble making it work on my project.
    I put this line in my setting.yml file “enabled_modules: [default, sgTest4CruisePlugin]” but it doesn’t seem to work as I have a “Task ‘sg-test4cruise’ is not defined” error when trying to run the task.

    It would be very helpful if you can paste your configuration files.

    Thanks in advance

  13. anoopvdk said

    Hi Patrick,

    Download plugin from symfony plugins for cruise control.
    Put this file in the plugins directory of your application.

    Its Enough, and do the changes in setting.yml and app.yml file.

  14. Jan Markmann said

    Hi Anoopvdk,
    could you please email me that Code Sniffer Standard for Symfony too? Thanks in advance =)

  15. Piero Recchia said

    Hi Anoopvdk, i found symfonyUnderControlPlugin at the symfony’s plugins section for symfony 1.2 here. I’ll try use it to work with this tutorial. Thanks for this post. Can you send me that Code Sniffer Standard for Symfony at piero dot recchia at gmail dot com.

    Thanks, sorry for my english.

  16. Hi.. thank you for the post. Could you also send me your Symfony coding standards? Maybe if you publish them somewhere and write a post about it we wouldn’t be asking for it independently I also wrote my email in the form.

    Again, thank you very much.

    • I’m creating this script that allows me to generate phpunit code-coverage usint lime tests


      /**
      * Test unit
      *
      * @package test
      * @category test
      */

      require_once 'PHPUnit/Framework.php';

      /**
      * Sweeps all functional and unit test in lime from PHPUnit
      *
      * This is done this way to use the code coverage, PMD, etc from
      * PHPunit. This was just an idea on how to do it
      *
      *
      * @author Stuardo Rodríguez
      */
      class Speed_Test_PHPUnitSweeper extends PHPUnit_Framework_TestCase
      {
      /**
      * Search for all test files in the test/ folder and includes them
      *
      * @todo Change the clases or find someway to run asserts alson and not only lime checks
      * @todo Find a way to split the require in independant tests
      *
      * @return void
      */
      public function testSweepAll()
      {
      $output = array();
      exec('find test/ | grep -e "Test.php$"', $output);
      foreach($output as $file) {
      require_once $file;
      }
      }
      }

  17. pligg.com said

    PhpUnderControl Framework For Symfony Projects…

    Article traitant de la mise en place d’une chaine de montage pour un projet PHP symfony avec phpUnderControl (extension de cruise control)….

  18. […] https://anoosphpundercontrol.wordpress.com/2008/07/29/phpundercontrol-framework-for-symfony-projects/ […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: