Close and re-open tickets from tests: Fogbugz PHPUnit TicketListener

When working with unit testing in PHP, you might already be using my favorite PHP unit testing tool PHPUnit. If you are, perhaps you’ve heard of the TicketListener interface. No? Then read on.

Raphael Stolt closes GitHub issues from his PHPUnit tests. Which is cool. He inspired me.

I wrote some code. You can now do the same from FogBugz. (FogBugz is a commercial project management system that includes bug tracking.)

To install this, you can now just head over to the PHPUnit PEAR channel:

pear install phpunit/PHPUnit_TicketListener_Fogbugz

Steps to do it

Have a nice failing test that can re-open your ticket.


< ?
class ExampleClassTest extends PHPUnit_Framework_TestCase
{
    /**
     * @ticket 2
     * @test
     */
    function example() {
        $this->assertTrue(FALSE);
    }

}

Please note the annotation documentation block above the test method: it denotes that the method is a test, and that the issue with ID 2 should be re-opened if this test should ever fail.

Then, set up a continuous integration-specific PHPUnit configuration file (oh, why? Well, this extra checking against the bugs system takes time, and we don’t want to burden our test suite with that):


<phpunit>
  <listeners>
    <listener class="PHPUnit_Extensions_TicketListener_Fogbugz" 
              file="../olleolleolle-phpunit/PHPUnit/Extensions/TicketListener/Fogbugz.php">
      <arguments>
        <string>username@xstream.dk</string>
        <string>secretpassword</string>
        <string>http://fogbugz.example.org/api.php</string>
        <boolean>false</boolean>
        <boolean>true</boolean>
        <string>Fixed</string>
        <string>Started</string>
      </arguments>
    </listener>
  </listeners>
</phpunit>

Run the PHPUnit test (or, more realistically, your whole test suite) with the specific configuration, like so:

phpunit -ddisplay_errors=1 --configuration fogbugzlistener.xml ExampleClassTest

One Reply to “Close and re-open tickets from tests: Fogbugz PHPUnit TicketListener”

Leave a Reply

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