Skip to content

Commit c59f317

Browse files
[tests] Add PHPUnit output options (#84) (#85)
* Add PHPUnit output options * Update wiki submodule pointer for PR #85 --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 320a423 commit c59f317

9 files changed

Lines changed: 126 additions & 3 deletions

File tree

.github/wiki

Submodule wiki updated from 936be00 to fc18a8d

docs/commands/reports.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,7 @@ Behavior
6666
---------
6767

6868
- Runs ``docs`` and ``tests --coverage`` in parallel.
69+
- Runs tests with ``--no-progress`` and ``--coverage-summary`` so report builds
70+
keep PHPUnit output concise.
6971
- Used by the ``standards`` command as the final phase.
7072
- This is the reporting stage used by GitHub Pages.

docs/commands/tests.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ It supports:
1414
- Enforcing minimum coverage thresholds
1515
- Filtering tests by pattern
1616
- Cache management
17+
- Optional progress and coverage-text verbosity control
1718

1819
Usage
1920
-----
@@ -43,10 +44,16 @@ Options
4344
``--no-cache``
4445
Disable PHPUnit caching.
4546

47+
``--no-progress``
48+
Disable PHPUnit progress output.
49+
4650
``--coverage, -c`` (optional)
4751
Generate code coverage reports. If a path is provided, reports are saved there.
4852
Without a path, reports are saved to the cache directory.
4953

54+
``--coverage-summary``
55+
When coverage text is generated, show only the summary table.
56+
5057
``--filter, -f`` (optional)
5158
Filter which tests to run based on a pattern (regex supported).
5259

@@ -74,6 +81,12 @@ Run with coverage report:
7481
7582
composer tests --coverage=public/coverage
7683
84+
Run with concise coverage text output:
85+
86+
.. code-block:: bash
87+
88+
composer tests --coverage=public/coverage --coverage-summary
89+
7790
Run tests matching a pattern:
7891

7992
.. code-block:: bash
@@ -92,6 +105,12 @@ Run without cache:
92105
93106
composer tests --no-cache
94107
108+
Run without PHPUnit progress output:
109+
110+
.. code-block:: bash
111+
112+
composer tests --no-progress
113+
95114
Exit Codes
96115
---------
97116

@@ -113,5 +132,7 @@ Behavior
113132
- Local ``phpunit.xml`` is preferred over the packaged default.
114133
- Coverage filters are automatically applied to all PSR-4 paths from composer.json.
115134
- Multiple coverage formats are generated: HTML, Testdox HTML, Clover XML, and PHP.
135+
- ``--coverage-summary`` forwards PHPUnit's ``--only-summary-for-coverage-text``
136+
only when coverage text output is generated.
116137
- The command fails if minimum coverage is not met (when ``--min-coverage`` is set).
117138
- The packaged configuration registers the DevTools PHPUnit extension.

docs/running/reports.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ What the Command Runs
1111
``reports`` executes the following steps:
1212

1313
1. ``docs --target public``
14-
2. ``tests --coverage public/coverage``
14+
2. ``tests --coverage public/coverage --no-progress --coverage-summary``
1515

1616
Outputs
1717
-------

docs/running/specialized-commands.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Important details:
1818

1919
- local ``phpunit.xml`` is preferred over the packaged default;
2020
- ``--coverage=<path>`` creates HTML, Testdox, Clover, and raw coverage output;
21+
- ``--coverage-summary`` keeps coverage text output to PHPUnit's summary;
22+
- ``--no-progress`` disables PHPUnit progress output;
2123
- ``--no-cache`` disables ``tmp/cache/phpunit``;
2224
- the packaged configuration registers the DevTools PHPUnit extension.
2325

@@ -136,7 +138,7 @@ Runs the documentation and test-report pipeline used by GitHub Pages.
136138
Important details:
137139

138140
- it calls ``docs --target public``;
139-
- it calls ``tests --coverage public/coverage``;
141+
- it calls ``tests --coverage public/coverage --no-progress --coverage-summary``;
140142
- it is the reporting stage used by ``standards``.
141143

142144
``skills``

src/Console/Command/ReportsCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9494

9595
$coverage = $this->processBuilder
9696
->withArgument('--ansi')
97+
->withArgument('--no-progress')
98+
->withArgument('--coverage-summary')
9799
->withArgument('--coverage', $input->getOption('coverage'))
98100
->build('composer dev-tools tests --');
99101

src/Console/Command/TestsCommand.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ protected function configure(): void
112112
mode: InputOption::VALUE_OPTIONAL,
113113
description: 'Whether to generate code coverage reports.',
114114
)
115+
->addOption(
116+
name: 'coverage-summary',
117+
mode: InputOption::VALUE_NONE,
118+
description: 'Whether to show only the summary for text coverage output.',
119+
)
115120
->addOption(
116121
name: 'filter',
117122
shortcut: 'f',
@@ -122,6 +127,11 @@ protected function configure(): void
122127
name: 'min-coverage',
123128
mode: InputOption::VALUE_REQUIRED,
124129
description: 'Minimum line coverage percentage required for a successful run.',
130+
)
131+
->addOption(
132+
name: 'no-progress',
133+
mode: InputOption::VALUE_NONE,
134+
description: 'Whether to disable progress output from PHPUnit.',
125135
);
126136
}
127137

@@ -156,6 +166,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
156166
->withArgument('--display-incomplete')
157167
->withArgument('--display-skipped');
158168

169+
if ($input->getOption('no-progress')) {
170+
$processBuilder = $processBuilder->withArgument('--no-progress');
171+
}
172+
159173
if (! $input->getOption('no-cache')) {
160174
$processBuilder = $processBuilder->withArgument(
161175
'--cache-directory',
@@ -265,6 +279,10 @@ private function configureCoverageArguments(
265279
->withArgument('--coverage-html', $coveragePath)
266280
->withArgument('--testdox-html', $coveragePath . '/testdox.html')
267281
->withArgument('--coverage-clover', $coveragePath . '/clover.xml');
282+
283+
if ($input->getOption('coverage-summary')) {
284+
$processBuilder = $processBuilder->withArgument('--only-summary-for-coverage-text');
285+
}
268286
}
269287

270288
$coverageReportPath = $coveragePath . '/coverage.php';

tests/Console/Command/ReportsCommandTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,14 @@ public function executeWillRunDocsAndTestsCommandAsDetachedProcesses(): void
149149
->shouldBeCalledOnce()
150150
->willReturn($this->processBuilder->reveal());
151151

152+
$this->processBuilder->withArgument('--no-progress')
153+
->shouldBeCalledOnce()
154+
->willReturn($this->processBuilder->reveal());
155+
156+
$this->processBuilder->withArgument('--coverage-summary')
157+
->shouldBeCalledOnce()
158+
->willReturn($this->processBuilder->reveal());
159+
152160
$this->processQueue->add($this->docsProcess->reveal(), false, true)
153161
->shouldBeCalledOnce();
154162

tests/Console/Command/TestsCommandTest.php

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,18 @@ public function commandWillSetExpectedNameDescriptionAndHelp(): void
146146
self::assertSame('This command runs PHPUnit to execute your tests.', $this->command->getHelp());
147147
}
148148

149+
/**
150+
* @return void
151+
*/
152+
#[Test]
153+
public function commandWillHaveExpectedOutputOptions(): void
154+
{
155+
$definition = $this->command->getDefinition();
156+
157+
self::assertTrue($definition->hasOption('no-progress'));
158+
self::assertTrue($definition->hasOption('coverage-summary'));
159+
}
160+
149161
/**
150162
* @return void
151163
*/
@@ -172,6 +184,7 @@ public function executeWithCoverageWillIncludeCoverageArguments(): void
172184
$commandLine = $process->getCommandLine();
173185

174186
return str_contains($commandLine, '--coverage-text')
187+
&& ! str_contains($commandLine, '--only-summary-for-coverage-text')
175188
&& str_contains($commandLine, '--coverage-html=' . getcwd() . '/public/coverage');
176189
});
177190

@@ -181,6 +194,63 @@ public function executeWithCoverageWillIncludeCoverageArguments(): void
181194
$this->invokeExecute();
182195
}
183196

197+
/**
198+
* @return void
199+
*/
200+
#[Test]
201+
public function executeWithNoProgressWillForwardNoProgressToPhpUnit(): void
202+
{
203+
$this->willQueueProcessMatching(static fn(Process $process): bool => str_contains(
204+
$process->getCommandLine(),
205+
'--no-progress',
206+
));
207+
208+
$this->input->getOption('no-progress')
209+
->willReturn(true);
210+
211+
$this->invokeExecute();
212+
}
213+
214+
/**
215+
* @return void
216+
*/
217+
#[Test]
218+
public function executeWithCoverageSummaryWillIncludeCoverageTextSummaryArgument(): void
219+
{
220+
$this->willQueueProcessMatching(function (Process $process): bool {
221+
$commandLine = $process->getCommandLine();
222+
223+
return str_contains($commandLine, '--coverage-text')
224+
&& str_contains($commandLine, '--only-summary-for-coverage-text');
225+
});
226+
227+
$this->input->getOption('coverage')
228+
->willReturn('public/coverage');
229+
$this->input->getOption('coverage-summary')
230+
->willReturn(true);
231+
232+
$this->invokeExecute();
233+
}
234+
235+
/**
236+
* @return void
237+
*/
238+
#[Test]
239+
public function executeWithCoverageSummaryWithoutCoverageWillNotGenerateCoverageTextSummary(): void
240+
{
241+
$this->willQueueProcessMatching(static function (Process $process): bool {
242+
$commandLine = $process->getCommandLine();
243+
244+
return ! str_contains($commandLine, '--coverage-text')
245+
&& ! str_contains($commandLine, '--only-summary-for-coverage-text');
246+
});
247+
248+
$this->input->getOption('coverage-summary')
249+
->willReturn(true);
250+
251+
$this->invokeExecute();
252+
}
253+
184254
/**
185255
* @return void
186256
*/

0 commit comments

Comments
 (0)