From ad254f95788bcda78a0d9fee6c2169b0f18e617d Mon Sep 17 00:00:00 2001 From: Kirill Smelov Date: Mon, 13 Aug 2018 15:35:07 +0300 Subject: [PATCH] Print duration of the tests events in the TeamCity logger --- src/Util/Log/TeamCity.php | 25 ++++++++++++++++----- tests/TextUI/teamcity-inner-exceptions.phpt | 4 ++-- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/Util/Log/TeamCity.php b/src/Util/Log/TeamCity.php index 1ff3ae94b1d..88f2a12c421 100644 --- a/src/Util/Log/TeamCity.php +++ b/src/Util/Log/TeamCity.php @@ -76,6 +76,7 @@ public function addError(Test $test, \Exception $e, $time) 'name' => $test->getName(), 'message' => self::getMessage($e), 'details' => self::getDetails($e), + 'duration' => self::toMilliseconds($time), ] ); } @@ -94,7 +95,8 @@ public function addWarning(Test $test, Warning $e, $time) [ 'name' => $test->getName(), 'message' => self::getMessage($e), - 'details' => self::getDetails($e) + 'details' => self::getDetails($e), + 'duration' => self::toMilliseconds($time), ] ); } @@ -112,6 +114,7 @@ public function addFailure(Test $test, AssertionFailedError $e, $time) 'name' => $test->getName(), 'message' => self::getMessage($e), 'details' => self::getDetails($e), + 'duration' => self::toMilliseconds($time), ]; if ($e instanceof ExpectationFailedException) { @@ -150,7 +153,7 @@ public function addFailure(Test $test, AssertionFailedError $e, $time) */ public function addIncompleteTest(Test $test, \Exception $e, $time) { - $this->printIgnoredTest($test->getName(), $e); + $this->printIgnoredTest($test->getName(), $e, $time); } /** @@ -177,14 +180,14 @@ public function addSkippedTest(Test $test, \Exception $e, $time) $testName = $test->getName(); if ($this->startedTestName != $testName) { $this->startTest($test); - $this->printIgnoredTest($testName, $e); + $this->printIgnoredTest($testName, $e, $time); $this->endTest($test, $time); } else { - $this->printIgnoredTest($testName, $e); + $this->printIgnoredTest($testName, $e, $time); } } - public function printIgnoredTest($testName, \Exception $e) + public function printIgnoredTest($testName, \Exception $e, $time) { $this->printEvent( 'testIgnored', @@ -192,6 +195,7 @@ public function printIgnoredTest($testName, \Exception $e) 'name' => $testName, 'message' => self::getMessage($e), 'details' => self::getDetails($e), + 'duration' => self::toMilliseconds($time), ] ); } @@ -302,7 +306,7 @@ public function endTest(Test $test, $time) 'testFinished', [ 'name' => $test->getName(), - 'duration' => (int) (\round($time, 2) * 1000) + 'duration' => self::toMilliseconds($time), ] ); } @@ -420,4 +424,13 @@ private static function getFileName($className) return $reflectionClass->getFileName(); } + + /** + * @param float $time microseconds + * @return int + */ + private static function toMilliseconds($time) + { + return \round($time * 1000); + } } diff --git a/tests/TextUI/teamcity-inner-exceptions.phpt b/tests/TextUI/teamcity-inner-exceptions.phpt index 0b245f8ad1d..b054617d37a 100644 --- a/tests/TextUI/teamcity-inner-exceptions.phpt +++ b/tests/TextUI/teamcity-inner-exceptions.phpt @@ -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' details=' %s%eExceptionStackTest.php:14|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 %s%eExceptionStackTest.php:10|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' details=' %s%eExceptionStackTest.php:14|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 %s%eExceptionStackTest.php:10|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:22|n |n Caused by|n InvalidArgumentException: Two|n |n %s%etests%e_files%eExceptionStackTest.php:21|n |n Caused by|n Exception: Three|n |n %s%etests%e_files%eExceptionStackTest.php:20|n ' flowId='%d'] +##teamcity[testFailed name='testNestedExceptions' message='Exception : One' details=' %s%etests%e_files%eExceptionStackTest.php:22|n |n Caused by|n InvalidArgumentException: Two|n |n %s%etests%e_files%eExceptionStackTest.php:21|n |n Caused by|n Exception: Three|n |n %s%etests%e_files%eExceptionStackTest.php:20|n ' duration='%d' flowId='%d'] ##teamcity[testFinished name='testNestedExceptions' duration='%d' flowId='%d']