diff --git a/README.md b/README.md index 1ac5be2b..37598d19 100644 --- a/README.md +++ b/README.md @@ -181,6 +181,15 @@ The following commands are available in VS Code's command palette, use the ID to } ``` +### Coverage + +```jsonc +{ + "phpunit.coveragePath": "${workspaceFolder}/coverage", + "phpunit.coverageFile": "phpunit.xml" +} +``` + ## Troubleshooting ### PHPUnit path mapping not working diff --git a/package.json b/package.json index 103b2dab..490b7ffc 100644 --- a/package.json +++ b/package.json @@ -150,6 +150,16 @@ "type": "integer", "default": 0, "description": "The port that is used to communicate between Xdebug in phpunit and the debug extension. 0 (default) will use a random port." + }, + "phpunit.coveragePath": { + "type": "string", + "default": null, + "description": "Path for code coverage results" + }, + "phpunit.coverageFile": { + "type": "string", + "default": null, + "description": "File name for code coverage results" } } } diff --git a/src/PHPUnit/CommandBuilder/Xdebug.ts b/src/PHPUnit/CommandBuilder/Xdebug.ts index ef973023..104863a6 100644 --- a/src/PHPUnit/CommandBuilder/Xdebug.ts +++ b/src/PHPUnit/CommandBuilder/Xdebug.ts @@ -24,7 +24,7 @@ export enum Mode { export class Xdebug { mode?: Mode; private port?: number; - private temporaryDirectory?: string; + private directory?: string; private index: number = 0; constructor(private configuration: IConfiguration) { @@ -39,7 +39,9 @@ export class Xdebug { return undefined; } - return join(this.temporaryDirectory!, `phpunit-${this.index}.xml`); + const fileName = this.configuration.get('coverageFile', `phpunit-${this.index}.xml`); + + return join(this.directory!, fileName); } setIndex(index: number) { @@ -48,8 +50,8 @@ export class Xdebug { return this; } - setTemporaryDirectory(temporaryDirectory: string) { - this.temporaryDirectory = temporaryDirectory; + setDirectory(temporaryDirectory: string) { + this.directory = temporaryDirectory; return this; } @@ -64,12 +66,14 @@ export class Xdebug { // export enum TestRunProfileKind { Run = 1, Debug = 2, Coverage = 3 } if (mode === 2) { this.mode = Mode.debug; - this.port = this.configuration.get('xdebugPort', 0) as number || await getFreePort(); + this.port = this.configuration.get('xdebugPort', 0) || await getFreePort(); } if (mode === 3) { this.mode = Mode.coverage; - this.setTemporaryDirectory(await mkdtemp(join(tmpdir(), 'phpunit'))); + const directory = this.configuration.get('coveragePath') || await mkdtemp(join(tmpdir(), 'phpunit')); + + this.setDirectory(directory); } return this; diff --git a/src/PHPUnit/Configuration.ts b/src/PHPUnit/Configuration.ts index d6bb0fc2..0fda840e 100644 --- a/src/PHPUnit/Configuration.ts +++ b/src/PHPUnit/Configuration.ts @@ -6,7 +6,8 @@ interface ConfigurationItem { } export interface IConfiguration { - get(key: string, defaultValue?: unknown): unknown | undefined; + get(key: string): T | undefined; + get(key: string, defaultValue: T): T; has(key: string): any; @@ -18,7 +19,8 @@ export interface IConfiguration { } export abstract class BaseConfiguration implements IConfiguration { - abstract get(key: string, defaultValue?: unknown): unknown | undefined; + abstract get(key: string): T | undefined; + abstract get(key: string, defaultValue: T): T; abstract has(key: string): any; @@ -57,8 +59,8 @@ export class Configuration extends BaseConfiguration { } } - get(key: string, defaultValue?: unknown): unknown | undefined { - return this.has(key) ? this.items.get(key) : defaultValue; + get(key: string, defaultValue?: T): T | undefined { + return this.has(key) ? this.items.get(key) as T : defaultValue; } has(key: string) {