Permalink
Browse files

- Merge [4665].

  • Loading branch information...
sebastianbergmann committed Feb 24, 2009
1 parent 69a9b3a commit 59ab1ccbec8494e4575428e1d7df90392b5274a7
Showing with 36 additions and 18 deletions.
  1. +12 −18 PHPUnit/Extensions/TicketListener.php
  2. +24 −0 PHPUnit/Util/Test.php
@@ -46,6 +46,7 @@
*/
require_once 'PHPUnit/Framework.php';
+require_once 'PHPUnit/Util/Test.php';
PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT');
@@ -64,8 +65,6 @@
*/
abstract class PHPUnit_Extensions_TicketListener implements PHPUnit_Framework_TestListener
{
- const REGEX_TICKET = '/@ticket\s+#?(\d+)/';
-
protected $ticketCounts = array();
protected $ran = FALSE;
@@ -146,14 +145,11 @@ public function startTest(PHPUnit_Framework_Test $test)
return;
}
- $class = new ReflectionClass(get_class($test));
+ $name = $test->getName();
+ $tickets = PHPUnit_Util_Test::getTickets(get_class($test), $name);
- foreach ($class->getMethods() as $method) {
- $docComment = $method->getDocComment();
-
- if (preg_match(self::REGEX_TICKET, $docComment, $matches)) {
- $this->ticketCounts[$matches[1]][$method->getName()] = 1;
- }
+ foreach ($tickets as $ticket) {
+ $this->ticketCounts[$ticket][$name] = 1;
}
$this->ran = TRUE;
@@ -189,22 +185,20 @@ public function endTest(PHPUnit_Framework_Test $test, $time)
return;
}
- $method = new ReflectionMethod(get_class($test), $test->getName());
- $docComment = $method->getDocComment();
-
- if (preg_match(self::REGEX_TICKET, $docComment, $matches)) {
- $ticketId = $matches[1];
-
+ $name = $test->getName();
+ $tickets = PHPUnit_Util_Test::getTickets(get_class($test), $name);
+
+ foreach ($tickets as $ticket) {
// Remove this test from the totals (if it passed).
if ($test->getStatus() == PHPUnit_Runner_BaseTestRunner::STATUS_PASSED) {
- unset($this->ticketCounts[$ticketId][$test->getName()]);
+ unset($this->ticketCounts[$ticket][$name]);
}
// Only close tickets if ALL referenced cases pass
// but reopen tickets if a single test fails.
if ($cumulative) {
// Determine number of to-pass tests:
- if (count($this->ticketCounts[$ticketId]) > 0) {
+ if (count($this->ticketCounts[$ticket]) > 0) {
// There exist remaining test cases with this reference.
$adjustTicket = FALSE;
} else {
@@ -216,7 +210,7 @@ public function endTest(PHPUnit_Framework_Test $test, $time)
}
if ($adjustTicket && in_array($ticketInfo[3]['status'], $ifStatus)) {
- $this->updateTicket($ticketId, $newStatus, $message, $resolution);
+ $this->updateTicket($ticket, $newStatus, $message, $resolution);
}
}
}
View
@@ -492,6 +492,30 @@ public static function getGroups($className, $methodName)
return array_unique($groups);
}
+ /**
+ * Returns the tickets for a test class or method.
+ *
+ * @param string $className
+ * @param string $methodName
+ * @return array
+ * @since Method available since Release 3.4.0
+ */
+ public static function getTickets($className, $methodName)
+ {
+ $annotations = self::parseTestMethodAnnotations($className, $methodName);
+ $tickets = array();
+
+ if (isset($annotations['class']['ticket'])) {
+ $tickets = $annotations['class']['ticket'];
+ }
+
+ if (isset($annotations['method']['ticket'])) {
+ $tickets = array_merge($tickets, $annotations['method']['ticket']);
+ }
+
+ return array_unique($tickets);
+ }
+
/**
* Returns the output buffering settings for a test.
*

0 comments on commit 59ab1cc

Please sign in to comment.