Skip to content

Ticket Listener

elblinkin edited this page Feb 27, 2011 · 4 revisions

This is a tutorial for using https://github.com/etsy/phpunit-extensions/tree/master/PHPUnit/Extensions/TicketListener.

PHPUnit has an extension point for adding a Test Listener.

Enabling a test listener requires setting up the test listener in the PHPUnit XML Config.

One particular class of test listeners are ticket listeners. Ticket listeners look at the @ticket annotation in the PHPDoc of the test method, and then re-opens closed tickets for failing tests and closes open tickets for passing tests.

/**
 * @ticket BUG-123
 */
public function testBug123Regression() {
    ... test code here ...
}

Jira


The Jira ticket listener set up requires Jira connection information:

  • Jira WSDL
  • Jira username
  • Jira username's password $wsdl $username $password

Jira allows customization of available statuses, so a list of open statuses

<array>
  <element key="0">
    <string>New</string>
  </element>
  <element key="1">
    <string>In Progress</string>
  </element>
  <element key="2">
    <string>Reopened</string>
  </element>
</array>

and a list of closed statuses

<array>
  <element key="0">
    <string>Completed</string>
  </element>
  <element key="1">
    <string>Closed</string>
  </element>
</array>

Jira then resolves and reopens via workflow actions, so the last two parameters that need to be specified are those workflow actions.

<string>Resolve Issue</string>
<string>Reopen Issue</string>

Put all of this together into a PHPUnit XML listener specification.

<listeners>
  <listener class="PHPUnit_Extensions_TicketListener_Jira">
    <arguments>
      <string>$wsdl</string>
      <string>$username</string>
      <string>$password</string>
      <array>
        <element key="0">
          <string>New</string>
        </element>
        <element key="1">
          <string>In Progress</string>
        </element>
        <element key="2">
          <string>Reopened</string>
        </element>
      </array>
      <array>
        <element key="0">
          <string>Completed</string>
        </element>
        <element key="1">
          <string>Closed</string>
        </element>
      </array>
      <string>Resolve Issue</string>
      <string>Reopen Issue</string>
    </arguments>
  </listener>
</listeners>

WARNING: Make sure you have a fast connection to Jira, and that you monitor usage of this feature. Each @ticket usage will result in a couple requests to Jira.

Clone this wiki locally