Skip to content

Commit 9b889cf

Browse files
committed
Merge branch 'release/1.2.0'
2 parents 8c70010 + fa78728 commit 9b889cf

File tree

5 files changed

+40
-2
lines changed

5 files changed

+40
-2
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,16 @@ Optionally, you can add it to your project's `phpunit.xml` file instead:
3535

3636
<img src="https://raw.githubusercontent.com/Sempro/phpunit-pretty-print/master/preview.gif" width="100%" alt="phpunit-pretty-print">
3737

38+
### Optional
39+
40+
To view progress while tests are running you can set `PHPUNIT_PRETTY_PRINT_PROGRESS=true` as environment variable on your server or within your `phpunit.xml` config file.
41+
```xml
42+
<phpunit>
43+
<php>
44+
<env name="PHPUNIT_PRETTY_PRINT_PROGRESS" value="true" />
45+
</php>
46+
</phpunit>
47+
```
48+
3849
### License
3950
MIT © [Sempro AS](http://www.sempro.no)

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sempro/phpunit-pretty-print",
3-
"version": "1.1.11",
3+
"version": "1.2.0",
44
"description": "Prettify PHPUnit output",
55
"type": "library",
66
"license": "MIT",

phpunit.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@
1616
</testsuites>
1717
<php>
1818
<env name="APP_ENV" value="testing"/>
19+
<env name="PHPUNIT_PRETTY_PRINT_PROGRESS" value="false" />
1920
</php>
2021
</phpunit>

src/PrettyPrinter.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ protected function writeProgress(string $progress): void
111111

112112
$this->previousClassName = $this->className;
113113

114+
$this->printProgress();
115+
114116
switch (strtoupper(preg_replace('#\\x1b[[][^A-Za-z]*[A-Za-z]#', '', $progress))) {
115117
case '.':
116118
$this->writeWithColor('fg-green', '', false);
@@ -193,4 +195,16 @@ private function handleDataSetName($name, $testMethodName): string
193195

194196
return $name . ' [' . $dataSetMatch[1] . ']';
195197
}
198+
199+
private function printProgress()
200+
{
201+
if (filter_var(getenv('PHPUNIT_PRETTY_PRINT_PROGRESS'), FILTER_VALIDATE_BOOLEAN)) {
202+
$this->numTestsRun++;
203+
204+
$total = $this->numTests;
205+
$current = str_pad($this->numTestsRun, strlen($total), '0', STR_PAD_LEFT);
206+
207+
$this->write("[{$current}/{$total}]");
208+
}
209+
}
196210
}

tests/PrinterTest.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,18 @@ public function testTestNameCanStartOrEndWithANumber()
7474
$this->assertStringContainsString('✓ 123 can start or end with numbers 456', $lines[13]);
7575
}
7676

77+
public function testItCanShowProgressWhileRunningTests()
78+
{
79+
putenv('PHPUNIT_PRETTY_PRINT_PROGRESS=true');
80+
81+
$lines = array_slice($this->getOutput(), 4, 10);
82+
$count = count($lines);
83+
84+
foreach ($lines as $index => $line) {
85+
$this->assertStringContainsString(vsprintf('%s/%s', [$index+1, $count]), $line);
86+
}
87+
}
88+
7789
private function getOutput(): array
7890
{
7991
$command = [
@@ -83,7 +95,7 @@ private function getOutput(): array
8395
];
8496

8597
exec(implode(' ', $command), $out);
86-
98+
8799
return $out;
88100
}
89101
}

0 commit comments

Comments
 (0)