Skip to content

Commit e1e20b1

Browse files
authored
Merge pull request #315 from recca0120/fix/test-result-without-details
fix without details
2 parents 186b9b9 + 6ab2be3 commit e1e20b1

File tree

4 files changed

+89
-2
lines changed

4 files changed

+89
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"displayName": "PHPUnit Test Explorer",
55
"icon": "img/icon.png",
66
"publisher": "recca0120",
7-
"version": "3.7.3",
7+
"version": "3.7.4",
88
"private": true,
99
"license": "MIT",
1010
"repository": {

src/PHPUnit/ProblemMatcher/PHPUnitProblemMatcher.test.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,4 +235,50 @@ describe('PHPUnit ProblemMatcher Text', () => {
235235
}),
236236
);
237237
});
238+
239+
fit('fix PHPUnit 10 without details', () => {
240+
const contents = [
241+
`##teamcity[testSuiteStarted name='Tests\\Feature\\ChatControllerTest' locationHint='php_qn:///var/www/html/tests/Feature/ChatControllerTest.php::\\Tests\\Feature\\ChatControllerTest' flowId='22946']`,
242+
`##teamcity[testIgnored name='test_permission' message='ChatControllerTest uses PlayerService' duration='0' flowId='22946']`,
243+
`##teamcity[testIgnored name='test_grant_chat_token' message='ChatControllerTest uses PlayerService' duration='57' flowId='22946']`,
244+
`##teamcity[testIgnored name='test_grant_chat_token_with_channels' message='ChatControllerTest uses PlayerService' duration='116' flowId='22946']`,
245+
`##teamcity[testIgnored name='test_grant_chat_token_missing_token_without_ttl' message='ChatControllerTest uses PlayerService' duration='171' flowId='22946']`,
246+
`##teamcity[testSuiteFinished name='Tests\\Feature\\ChatControllerTest' flowId='22946']`,
247+
];
248+
249+
problemMatcher.parse(contents[0]);
250+
expect(problemMatcher.parse(contents[1])).toEqual(
251+
expect.objectContaining({
252+
event: TeamcityEvent.testIgnored,
253+
name: 'test_permission',
254+
locationHint: 'php_qn:///var/www/html/tests/Feature/ChatControllerTest.php::test_permission',
255+
flowId: 22946,
256+
id: '/var/www/html/tests/Feature/ChatControllerTest.php::test_permission',
257+
file: '/var/www/html/tests/Feature/ChatControllerTest.php',
258+
message: 'ChatControllerTest uses PlayerService',
259+
details: [{
260+
file: '/var/www/html/tests/Feature/ChatControllerTest.php',
261+
line: 1,
262+
}],
263+
duration: 0,
264+
}),
265+
);
266+
267+
expect(problemMatcher.parse(contents[2])).toEqual(
268+
expect.objectContaining({
269+
event: TeamcityEvent.testIgnored,
270+
name: 'test_grant_chat_token',
271+
locationHint: 'php_qn:///var/www/html/tests/Feature/ChatControllerTest.php::test_grant_chat_token',
272+
flowId: 22946,
273+
id: '/var/www/html/tests/Feature/ChatControllerTest.php::test_grant_chat_token',
274+
file: '/var/www/html/tests/Feature/ChatControllerTest.php',
275+
message: 'ChatControllerTest uses PlayerService',
276+
details: [{
277+
file: '/var/www/html/tests/Feature/ChatControllerTest.php',
278+
line: 1,
279+
}],
280+
duration: 0,
281+
}),
282+
);
283+
});
238284
});

src/PHPUnit/ProblemMatcher/ProblemMatcher.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {
22
TeamcityEvent, TestFailed, TestFinished, TestIgnored, TestResult, TestResultParser, TestStarted, TestSuiteFinished,
33
TestSuiteStarted,
44
} from '.';
5-
import { PestV1Fixer } from '../Transformer';
5+
import { PestV1Fixer, PHPUnitFixer } from '../Transformer';
66

77
export class ProblemMatcher {
88
private results = new Map<string, TestResult>();
@@ -41,6 +41,7 @@ export class ProblemMatcher {
4141
let prevData = this.results.get(id) as (TestFailed | TestIgnored);
4242

4343
if (!prevData) {
44+
PHPUnitFixer.fixDetails(this.results, testResult);
4445
const file = testResult.details[0].file;
4546

4647
return { ...testResult, id: [file, testResult.name].join('::'), file, duration: 0 };

src/PHPUnit/Transformer/PHPUnitTransformer.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,47 @@
1+
import { TeamcityEvent, TestResult, TestStarted, TestSuiteStarted } from '../ProblemMatcher';
12
import { TestDefinition, TestType } from '../types';
23
import { capitalize, snakeCase, titleCase } from '../utils';
34
import { Transformer } from './Transformer';
45

6+
export class PHPUnitFixer {
7+
static fixDetails(results = new Map<string, TestResult>(), testResult: TestResult & {
8+
name: string,
9+
locationHint?: string,
10+
file?: string,
11+
details?: Array<{ file: string, line: number }>,
12+
}) {
13+
if (testResult.details && testResult.file) {
14+
return testResult;
15+
}
16+
17+
const result = Array.from(results.values()).reverse().find((result) => {
18+
return [TeamcityEvent.testSuiteStarted, TeamcityEvent.testStarted].includes(result.event);
19+
}) as (TestSuiteStarted | TestStarted | undefined);
20+
21+
if (!result) {
22+
return testResult;
23+
}
24+
25+
const file = result.file!;
26+
if (!testResult.file) {
27+
testResult.file = file;
28+
}
29+
30+
if (!testResult.details) {
31+
testResult.details = [{ file: file, line: 1 }];
32+
}
33+
34+
if (!testResult.locationHint) {
35+
const locationHint = result.locationHint?.split('::').slice(0, 1).join('::');
36+
testResult.locationHint = [locationHint, testResult.name]
37+
.filter(value => !!value)
38+
.join('::');
39+
}
40+
41+
return testResult;
42+
}
43+
}
44+
545
export class PHPUnitTransformer extends Transformer {
646
uniqueId(testDefinition: Pick<TestDefinition, 'type' | 'classFQN' | 'methodName' | 'annotations'>): string {
747
let { type, classFQN } = testDefinition;

0 commit comments

Comments
 (0)