Skip to content

Commit 0bd0190

Browse files
committed
fix pest v2 dataset
1 parent eed4370 commit 0bd0190

File tree

3 files changed

+107
-2
lines changed

3 files changed

+107
-2
lines changed

src/PHPUnit/ProblemMatcher/PestProblemMatcher.test.ts

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,5 +487,99 @@ 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+
it('pest-v2 data set', () => {
530+
resultShouldBe(`##teamcity[testSuiteStarted name='Tests\\Unit\\ExampleTest::__pest_evaluable_it_has_emails' locationHint='file://tests/Unit/ExampleTest.php' flowId='57317']`, {
531+
event: TestResultEvent.testSuiteStarted,
532+
id: 'tests/Unit/ExampleTest.php::it has emails',
533+
testId: 'tests/Unit/ExampleTest.php::it has emails',
534+
name: 'Tests\\Unit\\ExampleTest::__pest_evaluable_it_has_emails',
535+
file: 'tests/Unit/ExampleTest.php',
536+
flowId: 57317,
537+
});
538+
539+
resultShouldBe(`##teamcity[testStarted name='it has emails with data set "(|'enunomaduro@gmail.com|')"' locationHint='pest_qn://tests/Unit/ExampleTest.php::it has emails with data set "(|'enunomaduro@gmail.com|')"' flowId='57317']`, {
540+
event: TestResultEvent.testStarted,
541+
id: 'tests/Unit/ExampleTest.php::it has emails with data set "(\'enunomaduro@gmail.com\')"',
542+
testId: 'tests/Unit/ExampleTest.php::it has emails with data set "(\'enunomaduro@gmail.com\')"',
543+
name: 'it has emails with data set "(\'enunomaduro@gmail.com\')"',
544+
file: 'tests/Unit/ExampleTest.php',
545+
flowId: 57317,
546+
});
547+
548+
resultShouldBe(`##teamcity[testFinished name='it has emails with data set "(|'enunomaduro@gmail.com|')"' duration='1' flowId='57317']`, {
549+
event: TestResultEvent.testFinished,
550+
id: 'tests/Unit/ExampleTest.php::it has emails with data set "(\'enunomaduro@gmail.com\')"',
551+
testId: 'tests/Unit/ExampleTest.php::it has emails with data set "(\'enunomaduro@gmail.com\')"',
552+
name: 'it has emails with data set "(\'enunomaduro@gmail.com\')"',
553+
file: 'tests/Unit/ExampleTest.php',
554+
flowId: 57317,
555+
});
556+
557+
resultShouldBe(`##teamcity[testStarted name='it has emails with data set "(|'other@example.com|')"' locationHint='pest_qn://tests/Unit/ExampleTest.php::it has emails with data set "(|'other@example.com|')"' flowId='57317']`, {
558+
event: TestResultEvent.testStarted,
559+
id: 'tests/Unit/ExampleTest.php::it has emails with data set "(\'other@example.com\')"',
560+
testId: 'tests/Unit/ExampleTest.php::it has emails with data set "(\'other@example.com\')"',
561+
name: 'it has emails with data set "(\'other@example.com\')"',
562+
file: 'tests/Unit/ExampleTest.php',
563+
flowId: 57317,
564+
});
565+
566+
resultShouldBe(`##teamcity[testFinished name='it has emails with data set "(|'other@example.com|')"' duration='0' flowId='57317']`, {
567+
event: TestResultEvent.testFinished,
568+
id: 'tests/Unit/ExampleTest.php::it has emails with data set "(\'other@example.com\')"',
569+
testId: 'tests/Unit/ExampleTest.php::it has emails with data set "(\'other@example.com\')"',
570+
name: 'it has emails with data set "(\'other@example.com\')"',
571+
file: 'tests/Unit/ExampleTest.php',
572+
flowId: 57317,
573+
});
574+
575+
resultShouldBe(`##teamcity[testSuiteFinished name='Tests\\Unit\\ExampleTest::__pest_evaluable_it_has_emails' flowId='57317']`, {
576+
event: TestResultEvent.testSuiteFinished,
577+
id: 'tests/Unit/ExampleTest.php::it has emails',
578+
testId: 'tests/Unit/ExampleTest.php::it has emails',
579+
name: 'Tests\\Unit\\ExampleTest::__pest_evaluable_it_has_emails',
580+
file: 'tests/Unit/ExampleTest.php',
581+
flowId: 57317,
582+
});
583+
});
490584
});
491585
});

src/PHPUnit/TestParser/Transformers/PestTransformer.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ import { TransformerFactory } from './TransformerFactory';
55

66
export class PestTransformer extends PHPUnitTransformer {
77
fromLocationHit(locationHint: string, name: string) {
8+
locationHint = this.fixPestV2DataSet(locationHint, name);
9+
810
let file = '';
911
const matched = locationHint.match(/(pest_qn|file):\/\/(?<id>(?<prefix>\w+)\s+\((?<classFQN>[\w\\]+)\)(::(?<method>.+))?)/);
1012
if (!matched) {
11-
const id = locationHint.replace(/(pest_qn|file):\/\//, '').replace(/\\/g, '/');
13+
let id = locationHint.replace(/(pest_qn|file):\/\//, '').replace(/\\/g, '/');
1214
const testId = id;
1315
file = id.split('::')[0];
1416

@@ -54,4 +56,13 @@ export class PestTransformer extends PHPUnitTransformer {
5456
protected normalizeMethodName(methodName: string) {
5557
return methodName.replace(/\*\//g, '{@*}');
5658
}
59+
60+
private fixPestV2DataSet(locationHint: string, name: string) {
61+
const matched = name.match(/__pest_evaluable_(?<name>.+)/);
62+
if (matched && matched.groups?.name) {
63+
locationHint += '::' + matched.groups.name.replace(/_/g, ' ');
64+
}
65+
66+
return locationHint;
67+
}
5768
}

src/extension.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ describe('Extension Test', () => {
386386
});
387387
});
388388

389-
if (semver.gte(PHP_VERSION, '8.2.0')) {
389+
if (semver.gte(PHP_VERSION, '8.1.0')) {
390390
describe('PEST', () => {
391391
const root = pestProject('');
392392

0 commit comments

Comments
 (0)