Skip to content

Commit

Permalink
- Merge [4655].
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Feb 20, 2009
1 parent 658d33e commit 64fbd32
Showing 1 changed file with 55 additions and 51 deletions.
106 changes: 55 additions & 51 deletions PHPUnit/Extensions/TicketListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,21 +141,23 @@ public function endTestSuite(PHPUnit_Framework_TestSuite $suite)
*/
public function startTest(PHPUnit_Framework_Test $test)
{
if ($this->ran) {
return;
}
if (!$test instanceof PHPUnit_Framework_Warning) {
if ($this->ran) {
return;
}

$class = new ReflectionClass(get_class($test));

foreach ($class->getMethods() as $method) {
$docComment = $method->getDocComment();
$class = new ReflectionClass(get_class($test));
foreach ($class->getMethods() as $method) {
$docComment = $method->getDocComment();

if (preg_match(self::REGEX_TICKET, $docComment, $matches)) {
$this->ticketCounts[$matches[1]][$method->getName()] = 1;
if (preg_match(self::REGEX_TICKET, $docComment, $matches)) {
$this->ticketCounts[$matches[1]][$method->getName()] = 1;
}
}
}

$this->ran = TRUE;
$this->ran = TRUE;
}
}

/**
Expand All @@ -166,54 +168,56 @@ public function startTest(PHPUnit_Framework_Test $test)
*/
public function endTest(PHPUnit_Framework_Test $test, $time)
{
if ($test->getStatus() == PHPUnit_Runner_BaseTestRunner::STATUS_PASSED) {
$ifStatus = array('assigned', 'new', 'reopened');
$newStatus = 'closed';
$message = 'Automatically closed by PHPUnit (test passed).';
$resolution = 'fixed';
$cumulative = TRUE;
}
if (!$test instanceof PHPUnit_Framework_Warning) {
if ($test->getStatus() == PHPUnit_Runner_BaseTestRunner::STATUS_PASSED) {
$ifStatus = array('assigned', 'new', 'reopened');
$newStatus = 'closed';
$message = 'Automatically closed by PHPUnit (test passed).';
$resolution = 'fixed';
$cumulative = TRUE;
}

else if ($test->getStatus() == PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE) {
$ifStatus = array('closed');
$newStatus = 'reopened';
$message = 'Automatically reopened by PHPUnit (test failed).';
$resolution = '';
$cumulative = FALSE;
}
else if ($test->getStatus() == PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE) {
$ifStatus = array('closed');
$newStatus = 'reopened';
$message = 'Automatically reopened by PHPUnit (test failed).';
$resolution = '';
$cumulative = FALSE;
}

else {
return;
}
else {
return;
}

$method = new ReflectionMethod(get_class($test), $test->getName());
$docComment = $method->getDocComment();
$method = new ReflectionMethod(get_class($test), $test->getName());
$docComment = $method->getDocComment();

if (preg_match(self::REGEX_TICKET, $docComment, $matches)) {
$ticketId = $matches[1];

// Remove this test from the totals (if it passed).
if ($test->getStatus() == PHPUnit_Runner_BaseTestRunner::STATUS_PASSED) {
unset($this->ticketCounts[$ticketId][$test->getName()]);
}

// 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) {
// There exist remaining test cases with this reference.
$adjustTicket = FALSE;
if (preg_match(self::REGEX_TICKET, $docComment, $matches)) {
$ticketId = $matches[1];

// Remove this test from the totals (if it passed).
if ($test->getStatus() == PHPUnit_Runner_BaseTestRunner::STATUS_PASSED) {
unset($this->ticketCounts[$ticketId][$test->getName()]);
}

// 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) {
// There exist remaining test cases with this reference.
$adjustTicket = FALSE;
} else {
// No remaining tickets, go ahead and adjust.
$adjustTicket = TRUE;
}
} else {
// No remaining tickets, go ahead and adjust.
$adjustTicket = TRUE;
}
} else {
$adjustTicket = TRUE;
}

if ($adjustTicket && in_array($ticketInfo[3]['status'], $ifStatus)) {
$this->updateTicket($ticketId, $newStatus, $message, $resolution);
if ($adjustTicket && in_array($ticketInfo[3]['status'], $ifStatus)) {
$this->updateTicket($ticketId, $newStatus, $message, $resolution);
}
}
}
}
Expand Down

0 comments on commit 64fbd32

Please sign in to comment.