Using Symfony's Lime in phpUnderControl

Do you know phpUnderControl?
Do you know and use Lime?

If you answered ‘Yes’ to the questions above then you will likely have tried to integrate Lime into phpUnderControl. So have I..

What I discovered was that there are 3 ways in which this problem can be solved.

  1. Use Lime’s xUnit output mechanism, only available in Symfony 1.3 and higher (or so I have been told) available when Lime 2 is released (which is usable in symfony versions earlier than 1.3).
  2. Use Stefan Koopmanschap’s symfonyUnderControl plugin (http://www.leftontheweb.com/message/symfonyUnderControl_lime_integration_with_phpUnderControl), I only know for sure that it can be run in Symfony 1.2. Other versions of the framework might work as well.
  3. Or, and this is the subject of this post, directly use Lime from phpUnderControl

The order above is (in my opinion) from best to less best, xUnit xml output is always preferred above the direct inclusion in phpUnderControl.

Why I post this method?

There might be people who do not have the luxury of using the first two methods, for whatever reason. I have tried them because I want a light-weight solution until 1.3 Lime 2 hits the streets and the first option becomes available.

What do I get?

Funny that you should ask, or rather, that I asked it for you.

What we are going to do is add a new tab (page) to phpUnderControl where we show the output from Lime and add a task for it in CruiseControl. Whenever any test fails, the build fails and we will be able to view the information in our newly added tab.

What do I have to do?

Aside from creating unit tests you need to perform some actions before you will be able to use Lime. Luckily, I happen to know these steps and have written them down here. By the way: I do not intend to describe the process of adding a project to phpUnderControl, just adding the Lime checking to an existing project.

  1. Create a directory lime in the build directory of your CruiseControl project (i.e. /opt/cruisecontrol/projects/myproject/build/lime/)
  2. Open the build.xml of the project in your favourite text editor (i.e. /opt/cruisecontrol/projects/myproject/build.xml)
  3. Append a new task (target) in the project element with the following content,
    
    

    This task will execute Lime and store the results in a lime subfolder in your build folder of your CruiseControl project.

  4. Add the target unit-test-lime to the depends attribute of your build target (i.e. <target name=”build” depends=”checkout,clear-cache,php-codesniffer,unit-test-lime”/>). It will now be used in the build cycle of phpUnderControl.
  5. To make sure the results are publicly available we need to move it to an artifacts folder (usually /opt/cruisecontrol/logs/myproject/). We can do this by adding a new artifactspublisher to the config.xml of cruisecontrol (in /opt/cruisecontrol/). In the list of publishers you can add a new line (preferably after the api publisher) which moves the output of lime to a new folder in the artifacts folder. i.e. <artifactspublisher dir=”projects/${project.name}/build/lime” dest=”logs/${project.name}” subdirectory=”lime”/>
  6. To add a tab (page) to phpUnderControl you need to modify one of the templates of CruiseControl, main.jsp in the /opt/cruisecontrol/webapps/cruisecontrol folder. Search for the <%– phpUnderControl 8 –%> text and add the following code:
        <cruisecontrol:tab name="lime" label="Lime">
            <cruisecontrol:artifactsLink>
                <iframe src="<%=request.getContextPath() %>/< %= artifacts_url %>/lime/lime.log" class="tab-content">
                </iframe>
            </cruisecontrol:artifactsLink>
        </cruisecontrol:tab>
    
        <%-- phpUnderControl 9 --%>

    This code will add a new link to the menu and show the results in an iframe, just like the phpdoc view!

This is how you do it!
After the modifications show below and forcing a build, you have the results of your lime in phpUnderControl!

UPDATE: added some information from Bernhard in this post
UPDATE: fixed an error which was causing the snippets to become unavailable

6 thoughts on “Using Symfony's Lime in phpUnderControl

  1. Lime 2 is (mostly) independent of symfony. This means that you will be able to use it with versions < 1.3. And I confirm, xUnit XML output is included.

  2. This is actually great news! The integration with phpUnderControl will be so much better. I hope Lime 2 comes with html generated Code Coverage which can be used just as the PHPUnit one in phpuc.

  3. hi mike,
    this is actually a very helpful post or it would be if you actually included the mentioned of the build.xml. 🙂

    Apparently your wordpress rtf editor swallowed the XML for it.

     

    Could you please re-enter this?

    cheers
    /christian

  4. hmm and your comment form killed it again..

    <target name="unit-test-lime"> <exec executable="${basedir}/source/symfony" dir="${basedir}/source" output="${basedir}/build/lime/lime.log" logerror="on" failonerror="on"> <arg line="test-unit" /> </exec> </target>

    1. Hello Christian,

      This has unfortunately happened to me once before with this syntax highlighter. I will fix the code once more and prepare some attachments to prevent these kind of issues in the future.

Leave a Reply

Your email address will not be published. Required fields are marked *