Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print duration of the tests events in the TeamCity logger #3251

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
46 changes: 29 additions & 17 deletions src/Util/Log/TeamCity.php
Expand Up @@ -60,9 +60,10 @@ public function addError(Test $test, \Throwable $t, float $time): void
$this->printEvent(
'testFailed',
[
'name' => $test->getName(),
'message' => self::getMessage($t),
'details' => self::getDetails($t),
'name' => $test->getName(),
'message' => self::getMessage($t),
'details' => self::getDetails($t),
'duration' => self::toMilliseconds($time),
]
);
}
Expand All @@ -77,9 +78,10 @@ public function addWarning(Test $test, Warning $e, float $time): void
$this->printEvent(
'testFailed',
[
'name' => $test->getName(),
'message' => self::getMessage($e),
'details' => self::getDetails($e)
'name' => $test->getName(),
'message' => self::getMessage($e),
'details' => self::getDetails($e),
'duration' => self::toMilliseconds($time),
]
);
}
Expand All @@ -92,9 +94,10 @@ public function addWarning(Test $test, Warning $e, float $time): void
public function addFailure(Test $test, AssertionFailedError $e, float $time): void
{
$parameters = [
'name' => $test->getName(),
'message' => self::getMessage($e),
'details' => self::getDetails($e),
'name' => $test->getName(),
'message' => self::getMessage($e),
'details' => self::getDetails($e),
'duration' => self::toMilliseconds($time),
];

if ($e instanceof ExpectationFailedException) {
Expand Down Expand Up @@ -129,7 +132,7 @@ public function addFailure(Test $test, AssertionFailedError $e, float $time): vo
*/
public function addIncompleteTest(Test $test, \Throwable $t, float $time): void
{
$this->printIgnoredTest($test->getName(), $t);
$this->printIgnoredTest($test->getName(), $t, $time);
}

/**
Expand All @@ -153,21 +156,22 @@ public function addSkippedTest(Test $test, \Throwable $t, float $time): void

if ($this->startedTestName !== $testName) {
$this->startTest($test);
$this->printIgnoredTest($testName, $t);
$this->printIgnoredTest($testName, $t, $time);
$this->endTest($test, $time);
} else {
$this->printIgnoredTest($testName, $t);
$this->printIgnoredTest($testName, $t, $time);
}
}

public function printIgnoredTest($testName, \Throwable $t): void
public function printIgnoredTest($testName, \Throwable $t, float $time): void
{
$this->printEvent(
'testIgnored',
[
'name' => $testName,
'message' => self::getMessage($t),
'details' => self::getDetails($t),
'name' => $testName,
'message' => self::getMessage($t),
'details' => self::getDetails($t),
'duration' => self::toMilliseconds($time),
]
);
}
Expand Down Expand Up @@ -273,7 +277,7 @@ public function endTest(Test $test, float $time): void
'testFinished',
[
'name' => $test->getName(),
'duration' => (int) (\round($time, 2) * 1000)
'duration' => self::toMilliseconds($time)
]
);
}
Expand Down Expand Up @@ -376,4 +380,12 @@ private static function getFileName($className): string

return $reflectionClass->getFileName();
}

/**
* @param float $time microseconds
*/
private static function toMilliseconds(float $time): int
{
return \round($time * 1000);
}
}
4 changes: 2 additions & 2 deletions tests/TextUI/teamcity-inner-exceptions.phpt
Expand Up @@ -19,13 +19,13 @@ PHPUnit %s by Sebastian Bergmann and contributors.

##teamcity[testStarted name='testPrintingChildException' locationHint='php_qn://%s%etests%e_files%eExceptionStackTest.php::\ExceptionStackTest::testPrintingChildException' flowId='%d']

##teamcity[testFailed name='testPrintingChildException' message='Child exception|nmessage|nFailed asserting that two arrays are equal.|n--- Expected|n+++ Actual|n@@ @@|n Array (|n- 0 => 1|n+ 0 => 2|n )|n' details=' %s_files%eExceptionStackTest.php:%d|n |n Caused by|n message|n Failed asserting that two arrays are equal.|n --- Expected|n +++ Actual|n @@ @@|n Array (|n - 0 => 1|n + 0 => 2|n )|n |n %s_files%eExceptionStackTest.php:%d|n ' flowId='%d']
##teamcity[testFailed name='testPrintingChildException' message='Child exception|nmessage|nFailed asserting that two arrays are equal.|n--- Expected|n+++ Actual|n@@ @@|n Array (|n- 0 => 1|n+ 0 => 2|n )|n' details=' %s_files%eExceptionStackTest.php:%d|n |n Caused by|n message|n Failed asserting that two arrays are equal.|n --- Expected|n +++ Actual|n @@ @@|n Array (|n - 0 => 1|n + 0 => 2|n )|n |n %s_files%eExceptionStackTest.php:%d|n ' duration='%d' flowId='%d']

##teamcity[testFinished name='testPrintingChildException' duration='%d' flowId='%d']

##teamcity[testStarted name='testNestedExceptions' locationHint='php_qn://%s%etests%e_files%eExceptionStackTest.php::\ExceptionStackTest::testNestedExceptions' flowId='%d']

##teamcity[testFailed name='testNestedExceptions' message='Exception : One' details=' %s%etests%e_files%eExceptionStackTest.php:%d|n |n Caused by|n InvalidArgumentException: Two|n |n %s%etests%e_files%eExceptionStackTest.php:%d|n |n Caused by|n Exception: Three|n |n %s%etests%e_files%eExceptionStackTest.php:%d|n ' flowId='%d']
##teamcity[testFailed name='testNestedExceptions' message='Exception : One' details=' %s%etests%e_files%eExceptionStackTest.php:%d|n |n Caused by|n InvalidArgumentException: Two|n |n %s%etests%e_files%eExceptionStackTest.php:%d|n |n Caused by|n Exception: Three|n |n %s%etests%e_files%eExceptionStackTest.php:%d|n ' duration='%d' flowId='%d']

##teamcity[testFinished name='testNestedExceptions' duration='%d' flowId='%d']

Expand Down