Skip to content

Commit f263395

Browse files
committed
Added "test.dp.args" config option.
1 parent 98900be commit f263395

File tree

6 files changed

+46
-6
lines changed

6 files changed

+46
-6
lines changed

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,12 @@ Pip makes no attempt to modify the test summary; only runtime output is changed.
5555

5656
Pip's behaviour can be customized by adding `<parameter>` nodes as children of the `<bootstrap>` node in `phpunit.xml`, with `name` and `value` attributes corresponding to the table below.
5757
58-
| Parameter name | Default value | Description |
59-
|-----------------|---------------|------------------------------------------------------------|
60-
| perf.slow | 200 (ms) | Sets the performance threshold for _slow_ (yellow) tests |
61-
| perf.vslow | 1000 (ms) | Sets the performance threshold for _very slow_ (red) tests |
62-
| test.name.strip | '' | Strips the specified matching portion of the test name |
58+
| Parameter name | Default value | Description |
59+
|-----------------|---------------|------------------------------------------------------------------------|
60+
| perf.slow | 200 (ms) | Sets the performance threshold for _slow_ (yellow) tests |
61+
| perf.vslow | 1000 (ms) | Sets the performance threshold for _very slow_ (red) tests |
62+
| test.dp.args | true | True to show the arguments passed by the data provider, false to hide. |
63+
| test.name.strip | '' | Strips the specified matching portion of the test name |
6364
6465
## Requirements
6566

src/PipConfig.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ final class PipConfig
77
{
88
public int $perfSlow = 200;
99
public int $perfVslow = 1_000;
10+
public bool $testDpArgs = true;
1011
public string $testNameStrip = '';
1112
}

src/PipExtension.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public function bootstrap(Configuration $configuration, Facade $facade, Paramete
1515
$config = new PipConfig();
1616
$parameters->has('perf.slow') && $config->perfSlow = +$parameters->get('perf.slow');
1717
$parameters->has('perf.vslow') && $config->perfVslow = +$parameters->get('perf.vslow');
18+
$parameters->has('test.dp.args') && $config->testDpArgs = $parameters->get('test.dp.args') === 'true';
1819
$parameters->has('test.name.strip') && $config->testNameStrip = $parameters->get('test.name.strip');
1920

2021
$facade->registerTracer(new Printer($config));

src/Printer.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,15 @@ public function trace(Event $event): void
102102
// Data provider case.
103103
if ($event->test()->isTestMethod() && $event->test()->testData()->hasDataFromDataProvider()) {
104104
$id = substr($id, 0, strrpos($id, '#'));
105-
$id .= $event->test()->testData()->dataFromDataProvider()->dataAsStringForResultOutput();
105+
106+
$data = $event->test()->testData()->dataFromDataProvider()->dataAsStringForResultOutput();
107+
if (!$this->config->testDpArgs) {
108+
$data = substr($data, 0, 17 + strlen(
109+
$event->test()->testData()->dataFromDataProvider()->dataSetName())
110+
);
111+
}
112+
113+
$id .= $data;
106114
}
107115

108116
$ms = round($event->telemetryInfo()->time()->duration($this->start)->asFloat() * 1_000);

test/config/TestDpArgs.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<phpunit>
2+
<extensions>
3+
<bootstrap class="ScriptFUSION\Pip\PipExtension">
4+
<parameter name="test.dp.args" value="false"/>
5+
</bootstrap>
6+
</extensions>
7+
</phpunit>

test/config/test dp args.phpt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
Tests that when "test dp args" is disabled, the arguments passed from the data provider are hidden in the output.
3+
4+
--ARGS--
5+
-c test/config/TestDpArgs.xml --colors=always test/CapabilitiesTest.php --filter ::testDataProvider\h
6+
7+
--FILE_EXTERNAL--
8+
../PHPUnit runner.php
9+
10+
--EXPECTF--
11+
PHPUnit %s
12+
13+
Runtime: %s
14+
Configuration: %s
15+
16+
50% . ScriptFUSIONTest\Pip\CapabilitiesTest::testDataProvider with data set "foo" (%d ms)
17+
100% . ScriptFUSIONTest\Pip\CapabilitiesTest::testDataProvider with data set "baz" (%d ms)
18+
19+
20+
Time: %s
21+
22+
OK (2 tests, 2 assertions)

0 commit comments

Comments
 (0)