Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
Expand Down
16 changes: 10 additions & 6 deletions src/PHPUnit/CommandBuilder/Xdebug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -48,8 +50,8 @@ export class Xdebug {
return this;
}

setTemporaryDirectory(temporaryDirectory: string) {
this.temporaryDirectory = temporaryDirectory;
setDirectory(temporaryDirectory: string) {
this.directory = temporaryDirectory;

return this;
}
Expand All @@ -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<string>('coveragePath') || await mkdtemp(join(tmpdir(), 'phpunit'));

this.setDirectory(directory);
}

return this;
Expand Down
10 changes: 6 additions & 4 deletions src/PHPUnit/Configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ interface ConfigurationItem {
}

export interface IConfiguration {
get(key: string, defaultValue?: unknown): unknown | undefined;
get<T = unknown>(key: string): T | undefined;
get<T = unknown>(key: string, defaultValue: T): T;

has(key: string): any;

Expand All @@ -18,7 +19,8 @@ export interface IConfiguration {
}

export abstract class BaseConfiguration implements IConfiguration {
abstract get(key: string, defaultValue?: unknown): unknown | undefined;
abstract get<T = unknown>(key: string): T | undefined;
abstract get<T = unknown>(key: string, defaultValue: T): T;

abstract has(key: string): any;

Expand Down Expand Up @@ -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<T = unknown>(key: string, defaultValue?: T): T | undefined {
return this.has(key) ? this.items.get(key) as T : defaultValue;
}

has(key: string) {
Expand Down
Loading