Skip to content

Commit 3707f99

Browse files
Emit location hint for repeated test method suites in TeamCity log
The testSuiteStarted message for a repeated test method's suite carried no locationHint, unlike the suites for test classes and for test methods that use data providers, so IDEs could not navigate from the suite node to the test method. The location hint is built from the class and method name rather than from the suite name, because the suite name of a repetition group that represents a single data set carries a "#dataSetName" suffix that does not belong in a php_qn:// URL.
1 parent 75c71f3 commit 3707f99

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

src/Logging/TeamCity/TeamCityLogger.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
use PHPUnit\Event\TestSuite\Finished as TestSuiteFinished;
3636
use PHPUnit\Event\TestSuite\Skipped as TestSuiteSkipped;
3737
use PHPUnit\Event\TestSuite\Started as TestSuiteStarted;
38+
use PHPUnit\Event\TestSuite\TestSuiteForRepeatedTestMethod;
3839
use PHPUnit\Event\TestSuite\TestSuiteForTestClass;
3940
use PHPUnit\Event\TestSuite\TestSuiteForTestMethodWithDataProvider;
4041
use PHPUnit\Framework\Exception as FrameworkException;
@@ -96,6 +97,15 @@ public function testSuiteStarted(TestSuiteStarted $event): void
9697
);
9798

9899
$parameters['name'] = $testSuite->methodName();
100+
} elseif ($testSuite->isForRepeatedTestMethod()) {
101+
assert($testSuite instanceof TestSuiteForRepeatedTestMethod);
102+
103+
$parameters['locationHint'] = sprintf(
104+
'php_qn://%s::\\%s::%s',
105+
$testSuite->file(),
106+
$testSuite->className(),
107+
$testSuite->methodName(),
108+
);
99109
}
100110

101111
$this->writeMessage('testSuiteStarted', $parameters);
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
--TEST--
2+
--repeat with --log-teamcity reports a test suite with a location hint per repeated test method
3+
--FILE--
4+
<?php declare(strict_types=1);
5+
$_SERVER['argv'][] = '--no-configuration';
6+
$_SERVER['argv'][] = '--do-not-cache-result';
7+
$_SERVER['argv'][] = '--repeat';
8+
$_SERVER['argv'][] = '2';
9+
$_SERVER['argv'][] = '--no-output';
10+
$_SERVER['argv'][] = '--log-teamcity';
11+
$_SERVER['argv'][] = 'php://stdout';
12+
$_SERVER['argv'][] = __DIR__ . '/_files/SuccessTest.php';
13+
14+
require __DIR__ . '/../../bootstrap.php';
15+
16+
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
17+
--EXPECTF--
18+
##teamcity[testCount count='4' flowId='%d']
19+
##teamcity[testSuiteStarted name='PHPUnit\TestFixture\Repeat\SuccessTest' locationHint='php_qn:%sSuccessTest.php::\PHPUnit\TestFixture\Repeat\SuccessTest' flowId='%d']
20+
##teamcity[testSuiteStarted name='PHPUnit\TestFixture\Repeat\SuccessTest::testOne' locationHint='php_qn:%sSuccessTest.php::\PHPUnit\TestFixture\Repeat\SuccessTest::testOne' flowId='%d']
21+
##teamcity[testStarted name='testOne (repetition 1 of 2)' locationHint='php_qn:%sSuccessTest.php::\PHPUnit\TestFixture\Repeat\SuccessTest::testOne (repetition 1 of 2)' flowId='%d']
22+
##teamcity[testFinished name='testOne (repetition 1 of 2)' duration='%s' flowId='%d']
23+
##teamcity[testStarted name='testOne (repetition 2 of 2)' locationHint='php_qn:%sSuccessTest.php::\PHPUnit\TestFixture\Repeat\SuccessTest::testOne (repetition 2 of 2)' flowId='%d']
24+
##teamcity[testFinished name='testOne (repetition 2 of 2)' duration='%s' flowId='%d']
25+
##teamcity[testSuiteFinished name='PHPUnit\TestFixture\Repeat\SuccessTest::testOne' flowId='%d']
26+
##teamcity[testSuiteStarted name='PHPUnit\TestFixture\Repeat\SuccessTest::testTwo' locationHint='php_qn:%sSuccessTest.php::\PHPUnit\TestFixture\Repeat\SuccessTest::testTwo' flowId='%d']
27+
##teamcity[testStarted name='testTwo (repetition 1 of 2)' locationHint='php_qn:%sSuccessTest.php::\PHPUnit\TestFixture\Repeat\SuccessTest::testTwo (repetition 1 of 2)' flowId='%d']
28+
##teamcity[testFinished name='testTwo (repetition 1 of 2)' duration='%s' flowId='%d']
29+
##teamcity[testStarted name='testTwo (repetition 2 of 2)' locationHint='php_qn:%sSuccessTest.php::\PHPUnit\TestFixture\Repeat\SuccessTest::testTwo (repetition 2 of 2)' flowId='%d']
30+
##teamcity[testFinished name='testTwo (repetition 2 of 2)' duration='%s' flowId='%d']
31+
##teamcity[testSuiteFinished name='PHPUnit\TestFixture\Repeat\SuccessTest::testTwo' flowId='%d']
32+
##teamcity[testSuiteFinished name='PHPUnit\TestFixture\Repeat\SuccessTest' flowId='%d']

0 commit comments

Comments
 (0)