Skip to content

Commit 2a8e73c

Browse files
committed
refactor: rename TestRunnerObserverFactory to ObserverFactory, export PresetName type
- Shorten factory class and file name - Extract PresetName type from resolveFormat for shared use - Fix package.json preset enum to match actual values: progress, collision, pretty - Update README EN/ZH with correct preset descriptions
1 parent e0b9148 commit 2a8e73c

9 files changed

Lines changed: 21 additions & 25 deletions

File tree

packages/extension/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ Add to `.vscode/settings.json`. All settings use the `phpunit.*` prefix.
6868
// Save all open files before running tests (default: false)
6969
"phpunit.saveBeforeTest": false,
7070

71-
// Output format preset: "collision" (detailed per-test) or "phpunit" (dot-progress)
71+
// Output format preset: "collision" (detailed per-test), "progress" (dot-progress), or "pretty" (per-test without icons)
7272
"phpunit.output.preset": "collision",
7373

7474
// Override individual format fields from the preset (see phpunit package docs)

packages/extension/README.zh-TW.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
// 執行測試前儲存所有開啟的檔案(預設:false)
6969
"phpunit.saveBeforeTest": false,
7070

71-
// 輸出格式預設:"collision"(逐條詳細顯示)或 "phpunit"(點進度模式
71+
// 輸出格式預設:"collision"(逐條詳細顯示)、"progress"(點進度模式)或 "pretty"(逐條無圖示
7272
"phpunit.output.preset": "collision",
7373

7474
// 覆寫預設的個別格式欄位(詳見 phpunit 套件文件)

packages/extension/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,12 @@
137137
"phpunit.output.preset": {
138138
"type": "string",
139139
"enum": [
140-
"phpunit",
141-
"collision"
140+
"progress",
141+
"collision",
142+
"pretty"
142143
],
143144
"default": "collision",
144-
"description": "Output format preset. 'collision' shows detailed per-test results; 'phpunit' shows dot-progress.",
145+
"description": "Output format preset. 'collision' shows detailed per-test results; 'progress' shows dot-progress; 'pretty' shows per-test without icons.",
145146
"scope": "resource"
146147
},
147148
"phpunit.output.format": {

packages/extension/src/Observers/TestRunnerObserverFactory.test.ts renamed to packages/extension/src/Observers/ObserverFactory.test.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import type { OutputChannel, TestItem, TestRun } from 'vscode';
44
import type { Configuration } from '../Configuration';
55
import type { TestCollection } from '../TestCollection/TestCollection';
66
import { DatasetObserver } from './DatasetObserver';
7+
import { ObserverFactory } from './ObserverFactory';
78
import { PrinterObserver } from './PrinterObserver';
89
import { TestResultObserver } from './TestResultObserver';
9-
import { TestRunnerObserverFactory } from './TestRunnerObserverFactory';
1010

11-
describe('TestRunnerObserverFactory', () => {
12-
let factory: TestRunnerObserverFactory;
11+
describe('ObserverFactory', () => {
12+
let factory: ObserverFactory;
1313
let outputChannel: OutputChannel;
1414

1515
beforeEach(() => {
@@ -25,12 +25,7 @@ describe('TestRunnerObserverFactory', () => {
2525
} as unknown as OutputChannel;
2626
const configuration = { get: vi.fn() } as unknown as Configuration;
2727
const phpUnitXML = new PHPUnitXML();
28-
factory = new TestRunnerObserverFactory(
29-
testCollection,
30-
outputChannel,
31-
configuration,
32-
phpUnitXML,
33-
);
28+
factory = new ObserverFactory(testCollection, outputChannel, configuration, phpUnitXML);
3429
});
3530

3631
it('should create observers including DatasetObserver, TestResultObserver, and PrinterObserver', () => {

packages/extension/src/Observers/TestRunnerObserverFactory.ts renamed to packages/extension/src/Observers/ObserverFactory.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
type IConfiguration,
33
PHPUnitXML,
4+
type PresetName,
45
Printer,
56
type PrinterFormat,
67
resolveFormat,
@@ -20,7 +21,7 @@ import { TestResultObserver } from './TestResultObserver';
2021
import { TestRunWriter } from './Writers';
2122

2223
@injectable()
23-
export class TestRunnerObserverFactory {
24+
export class ObserverFactory {
2425
constructor(
2526
@inject(TestCollection) private testCollection: TestCollection,
2627
@inject(TYPES.OutputChannel) private outputChannel: OutputChannel,
@@ -31,10 +32,7 @@ export class TestRunnerObserverFactory {
3132
create(queue: Map<TestDefinition, TestItem>, testRun: TestRun): TestRunnerObserver[] {
3233
const testItemById = new Map([...queue.values()].map((item) => [item.id, item]));
3334
const format = resolveFormat(
34-
(this.configuration.get('output.preset') ?? 'collision') as
35-
| 'progress'
36-
| 'collision'
37-
| 'pretty',
35+
(this.configuration.get('output.preset') ?? 'collision') as PresetName,
3836
this.configuration.get('output.format') as Partial<PrinterFormat> | undefined,
3937
);
4038

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export * from './DatasetObserver';
22
export * from './ErrorDialogObserver';
3+
export * from './ObserverFactory';
34
export * from './PrinterObserver';
45
export * from './RawOutputObserver';
56
export * from './TestResultObserver';
6-
export * from './TestRunnerObserverFactory';
77
export * from './Writers';

packages/extension/src/TestExecution/TestRunHandler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
import { inject, injectable } from 'inversify';
1010
import type { CancellationToken, TestController, TestItem, TestRun, TestRunRequest } from 'vscode';
1111
import { FileCoverageAdapter } from '../FileCoverageAdapter';
12-
import { TestRunnerObserverFactory } from '../Observers';
12+
import { ObserverFactory } from '../Observers';
1313
import { TestCollection } from '../TestCollection';
1414
import { TYPES } from '../types';
1515
import { DebugSessionManager } from './DebugSessionManager';
@@ -25,7 +25,7 @@ export class TestRunHandler {
2525
@inject(TYPES.TestController) private ctrl: TestController,
2626
@inject(ProcessBuilderFactory) private processBuilderFactory: ProcessBuilderFactory,
2727
@inject(TestCollection) private testCollection: TestCollection,
28-
@inject(TestRunnerObserverFactory) private observerFactory: TestRunnerObserverFactory,
28+
@inject(ObserverFactory) private observerFactory: ObserverFactory,
2929
@inject(TestQueueBuilder) private testQueueBuilder: TestQueueBuilder,
3030
@inject(DebugSessionManager) private debugSession: DebugSessionManager,
3131
) {}

packages/extension/src/container.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
workspace,
1717
} from 'vscode';
1818
import { Configuration } from './Configuration';
19-
import { TestRunnerObserverFactory } from './Observers';
19+
import { ObserverFactory } from './Observers';
2020
import { TestCollection } from './TestCollection';
2121
import { TestFileDiscovery, TestFileWatcher, TestWatchManager } from './TestDiscovery';
2222
import {
@@ -90,7 +90,7 @@ function createChildContainer(parent: Container, workspaceFolder: WorkspaceFolde
9090

9191
// Per-folder services
9292
child.bind(ProcessBuilderFactory).toSelf().inSingletonScope();
93-
child.bind(TestRunnerObserverFactory).toSelf().inSingletonScope();
93+
child.bind(ObserverFactory).toSelf().inSingletonScope();
9494
child.bind(TestCollection).toSelf().inSingletonScope();
9595
child.bind(TestQueueBuilder).toSelf().inSingletonScope();
9696
child.bind(DebugSessionManager).toSelf().inSingletonScope();

packages/phpunit/src/Printer/PrinterConfig.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,10 @@ export const PRESET_PRETTY: PrinterFormat = {
152152
},
153153
};
154154

155+
export type PresetName = 'progress' | 'collision' | 'pretty';
156+
155157
export function resolveFormat(
156-
preset: 'progress' | 'collision' | 'pretty',
158+
preset: PresetName,
157159
overrides?: Partial<PrinterFormat>,
158160
): PrinterFormat {
159161
const presets: Record<string, PrinterFormat> = {

0 commit comments

Comments
 (0)