Skip to content

Commit 310dea9

Browse files
committed
fix pest v1
1 parent eed4370 commit 310dea9

File tree

8 files changed

+524
-5
lines changed

8 files changed

+524
-5
lines changed

.github/workflows/jest.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
run: cd ${{ env.PHPUNIT_PROJECT }} && composer update --prefer-dist --no-interaction --no-progress
5757

5858
- name: Install Composer dependencies (PEST)
59-
if: matrix.php >= '8.1'
59+
if: matrix.php >= '8.0'
6060
run: cd ${{ env.PEST_PROJECT }} && composer update --prefer-dist --no-interaction --no-progress
6161

6262
# Install required deps for action

src/Observers/MessageObserver.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export class MessageObserver implements TestRunnerObserver {
66
constructor(private configuration: IConfiguration) {}
77

88
async error(error: string) {
9+
console.log(error);
910
if (error.indexOf('Pest\\Exceptions\\InvalidPestCommand') === -1) {
1011
await window.showErrorMessage(error);
1112
return;

src/PHPUnit/ProblemMatcher/PestProblemMatcher.test.ts

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,5 +487,139 @@ describe('Pest ProblemMatcher Text', () => {
487487
flowId: 57317,
488488
});
489489
});
490+
491+
it('pest-v2 tests/Fixtures/CollisionTest.php', () => {
492+
resultShouldBe(`##teamcity[testSuiteStarted name='Tests\\Fixtures\\CollisionTest' locationHint='file://tests/Fixtures/CollisionTest.php' flowId='57317']`, {
493+
event: TestResultEvent.testSuiteStarted,
494+
id: 'tests/Fixtures/CollisionTest.php',
495+
testId: 'tests/Fixtures/CollisionTest.php',
496+
name: 'Tests\\Fixtures\\CollisionTest',
497+
file: 'tests/Fixtures/CollisionTest.php',
498+
flowId: 57317,
499+
});
500+
501+
resultShouldBe(`##teamcity[testStarted name='success' locationHint='pest_qn://tests/Fixtures/CollisionTest.php::success' flowId='57317']`, {
502+
event: TestResultEvent.testStarted,
503+
id: 'tests/Fixtures/CollisionTest.php::success',
504+
testId: 'tests/Fixtures/CollisionTest.php::success',
505+
name: 'success',
506+
file: 'tests/Fixtures/CollisionTest.php',
507+
flowId: 57317,
508+
});
509+
510+
resultShouldBe(`##teamcity[testFinished name='success' duration='0' flowId='57317']`, {
511+
event: TestResultEvent.testFinished,
512+
id: 'tests/Fixtures/CollisionTest.php::success',
513+
testId: 'tests/Fixtures/CollisionTest.php::success',
514+
name: 'success',
515+
file: 'tests/Fixtures/CollisionTest.php',
516+
flowId: 57317,
517+
});
518+
519+
resultShouldBe(`##teamcity[testSuiteFinished name='Tests\\Fixtures\\CollisionTest' flowId='57317']`, {
520+
event: TestResultEvent.testSuiteFinished,
521+
id: 'tests/Fixtures/CollisionTest.php',
522+
testId: 'tests/Fixtures/CollisionTest.php',
523+
name: 'Tests\\Fixtures\\CollisionTest',
524+
file: 'tests/Fixtures/CollisionTest.php',
525+
flowId: 57317,
526+
});
527+
});
528+
});
529+
530+
describe('Pest v1', () => {
531+
it('testStarted without flowId', () => {
532+
resultShouldBe(`##teamcity[testSuiteStarted name='Tests\\Feature\\ExampleTest' locationHint='pest_qn://Tests\\Feature\\ExampleTest' flowId='58024']`, {
533+
event: TestResultEvent.testSuiteStarted,
534+
id: 'Tests/Feature/ExampleTest',
535+
testId: 'Tests/Feature/ExampleTest',
536+
name: 'Tests\\Feature\\ExampleTest',
537+
flowId: 58024,
538+
});
539+
540+
resultShouldBe(`##teamcity[testStarted name='test_example' locationHint='php_qn://${pestProject('tests/Feature/ExampleTest.php')}::\\Tests\\Feature\\ExampleTest::test_example']`, {
541+
event: TestResultEvent.testStarted,
542+
id: 'Example (Tests\\Feature\\Example)::Example',
543+
testId: 'Example (Tests\\Feature\\Example)::Example',
544+
name: 'test_example',
545+
flowId: 58024,
546+
});
547+
548+
resultShouldBe(`##teamcity[testFinished name='test_example' duration='1' flowId='58024']`, {
549+
event: TestResultEvent.testFinished,
550+
id: 'Example (Tests\\Feature\\Example)::Example',
551+
testId: 'Example (Tests\\Feature\\Example)::Example',
552+
name: 'test_example',
553+
flowId: 58024,
554+
});
555+
556+
resultShouldBe(`##teamcity[testSuiteFinished name='Tests\\Feature\\ExampleTest' locationHint='pest_qn://Tests\\Feature\\ExampleTest' flowId='58024']`, {
557+
event: TestResultEvent.testSuiteFinished,
558+
id: 'Tests/Feature/ExampleTest',
559+
testId: 'Tests/Feature/ExampleTest',
560+
name: 'Tests\\Feature\\ExampleTest',
561+
flowId: 58024,
562+
});
563+
});
564+
565+
it('pest-v1 tests/Fixtures/CollisionTest.php', () => {
566+
resultShouldBe(`##teamcity[testSuiteStarted name='Tests\\Fixtures\\CollisionTest' locationHint='pest_qn://${pestProject('tests/Fixtures/CollisionTest.php')}' flowId='12667']`, {
567+
event: TestResultEvent.testSuiteStarted,
568+
id: 'tests/Fixtures/CollisionTest.php',
569+
testId: 'tests/Fixtures/CollisionTest.php',
570+
name: 'Tests\\Fixtures\\CollisionTest',
571+
file: 'tests/Fixtures/CollisionTest.php',
572+
flowId: 12667,
573+
});
574+
575+
576+
resultShouldBe(`##teamcity[testStarted name='error' locationHint='pest_qn://${pestProject('tests/Fixtures/CollisionTest.php')}::error' flowId='12667']`, {
577+
event: TestResultEvent.testStarted,
578+
id: 'tests/Fixtures/CollisionTest.php::error',
579+
testId: 'tests/Fixtures/CollisionTest.php::error',
580+
name: 'error',
581+
file: 'tests/Fixtures/CollisionTest.php',
582+
flowId: 12667,
583+
});
584+
585+
resultShouldBe(`##teamcity[testIgnored name='error' message='' details=' /Users/recca0120/Desktop/vscode-phpunit/src/PHPUnit/__tests__/fixtures/pest-stub/tests/Fixtures/CollisionTest.php:5|n ' duration='6']`, undefined);
586+
587+
588+
resultShouldBe(`##teamcity[testFinished name='error' duration='6' flowId='12667']`, {
589+
event: TestResultEvent.testIgnored,
590+
id: 'tests/Fixtures/CollisionTest.php::error',
591+
testId: 'tests/Fixtures/CollisionTest.php::error',
592+
name: 'error',
593+
file: 'tests/Fixtures/CollisionTest.php',
594+
flowId: 12667,
595+
});
596+
597+
resultShouldBe(`##teamcity[testStarted name='success' locationHint='pest_qn://${pestProject('tests/Fixtures/CollisionTest.php')}::success' flowId='12667']`, {
598+
event: TestResultEvent.testStarted,
599+
id: 'tests/Fixtures/CollisionTest.php::success',
600+
testId: 'tests/Fixtures/CollisionTest.php::success',
601+
name: 'success',
602+
file: 'tests/Fixtures/CollisionTest.php',
603+
flowId: 12667,
604+
});
605+
606+
resultShouldBe(`##teamcity[testFinished name='success' duration='0' flowId='12667']`, {
607+
event: TestResultEvent.testFinished,
608+
id: 'tests/Fixtures/CollisionTest.php::success',
609+
testId: 'tests/Fixtures/CollisionTest.php::success',
610+
name: 'success',
611+
file: 'tests/Fixtures/CollisionTest.php',
612+
flowId: 12667,
613+
});
614+
615+
resultShouldBe(`##teamcity[testSuiteFinished name='Tests\\Fixtures\\CollisionTest' locationHint='pest_qn://${pestProject('tests/Fixtures/CollisionTest.php')}' flowId='12667']`, {
616+
event: TestResultEvent.testSuiteFinished,
617+
id: 'tests/Fixtures/CollisionTest.php',
618+
testId: 'tests/Fixtures/CollisionTest.php',
619+
name: 'Tests\\Fixtures\\CollisionTest',
620+
file: 'tests/Fixtures/CollisionTest.php',
621+
flowId: 12667,
622+
});
623+
});
490624
});
491625
});

src/PHPUnit/ProblemMatcher/ProblemMatcher.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
TestFailed, TestFinished, TestIgnored, TestResult, TestResultEvent, TestResultParser, TestStarted,
33
TestSuiteFinished, TestSuiteStarted,
44
} from '.';
5+
import { PestTransformer } from '../TestParser';
56

67
export class ProblemMatcher {
78
private results = new Map<string, TestResult>();
@@ -19,12 +20,13 @@ export class ProblemMatcher {
1920

2021
parse(input: string | Buffer): TestResult | undefined {
2122
const result = this.testResultParser.parse(input.toString());
23+
PestTransformer.fixPestV1(this.results, result);
2224

2325
return this.isResult(result) ? this.lookup[result!.event]?.call(this, result) : result;
2426
}
2527

2628
private isResult(result?: TestResult): boolean {
27-
return !!(result && 'event' in result && 'name' in result && 'flowId' in result);
29+
return !!result && 'event' in result && 'name' in result && 'flowId' in result;
2830
}
2931

3032
private handleStarted(testResult: TestSuiteStarted | TestStarted) {

src/PHPUnit/TestParser/Transformers/PestTransformer.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { TestResult } from '../../ProblemMatcher';
12
import { uncapitalize } from '../../utils';
23
import { TestDefinition, TestType } from '../types';
34
import { PHPUnitTransformer } from './PHPUnitTransformer';
@@ -8,7 +9,8 @@ export class PestTransformer extends PHPUnitTransformer {
89
let file = '';
910
const matched = locationHint.match(/(pest_qn|file):\/\/(?<id>(?<prefix>\w+)\s+\((?<classFQN>[\w\\]+)\)(::(?<method>.+))?)/);
1011
if (!matched) {
11-
const id = locationHint.replace(/(pest_qn|file):\/\//, '').replace(/\\/g, '/');
12+
let location = locationHint.replace(/(pest_qn|file):\/\//, '').replace(/\\/g, '/');
13+
const id = /^tests\//.test(location) ? location : location.substring(location.lastIndexOf('tests/'));
1214
const testId = id;
1315
file = id.split('::')[0];
1416

@@ -51,6 +53,35 @@ export class PestTransformer extends PHPUnitTransformer {
5153
return [uncapitalize(classFQN).replace(/\\/g, '/') + '.php', this.getMethodName(testDefinition)].join('::');
5254
};
5355

56+
static fixPestV1(results = new Map<string, TestResult>(), testResult?: TestResult) {
57+
if (!testResult) {
58+
return;
59+
}
60+
61+
const events = ['testStarted', 'testFailed', 'testIgnored'];
62+
if ('event' in testResult && !events.includes(testResult.event)) {
63+
return testResult;
64+
}
65+
66+
if ((testResult as any).flowId) {
67+
return testResult;
68+
}
69+
70+
const result = Array.from(results.values()).reverse().find((result: TestResult) => {
71+
if (testResult.event !== 'testStarted') {
72+
return result.event === 'testStarted' && (result as any).name === (testResult as any).name;
73+
}
74+
75+
const matched = (testResult as any).id?.match(/\((?<id>.+)\)/);
76+
77+
return matched && (result as any).id === matched.groups?.id.replace(/\\/g, '/') + 'Test';
78+
});
79+
80+
(testResult as any).flowId = (result as any)?.flowId;
81+
82+
return;
83+
}
84+
5485
protected normalizeMethodName(methodName: string) {
5586
return methodName.replace(/\*\//g, '{@*}');
5687
}

src/PHPUnit/__tests__/fixtures/pest-stub/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"type": "project",
44
"require-dev": {
55
"mockery/mockery": "^1.5 || 1.3",
6-
"pestphp/pest": "^2.36 || ^3.6"
6+
"pestphp/pest": "^1.23.1 || ^2.36 || ^3.6"
77
},
88
"license": "MIT",
99
"autoload": {

0 commit comments

Comments
 (0)