Skip to content

Commit

Permalink
Merge branch 'release/1.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
ventrec committed Nov 13, 2019
2 parents 8c70010 + fa78728 commit 9b889cf
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 2 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,16 @@ Optionally, you can add it to your project's `phpunit.xml` file instead:

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

### Optional

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.
```xml
<phpunit>
<php>
<env name="PHPUNIT_PRETTY_PRINT_PROGRESS" value="true" />
</php>
</phpunit>
```

### License
MIT © [Sempro AS](http://www.sempro.no)
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sempro/phpunit-pretty-print",
"version": "1.1.11",
"version": "1.2.0",
"description": "Prettify PHPUnit output",
"type": "library",
"license": "MIT",
Expand Down
1 change: 1 addition & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
</testsuites>
<php>
<env name="APP_ENV" value="testing"/>
<env name="PHPUNIT_PRETTY_PRINT_PROGRESS" value="false" />
</php>
</phpunit>
14 changes: 14 additions & 0 deletions src/PrettyPrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ protected function writeProgress(string $progress): void

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

$this->printProgress();

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

return $name . ' [' . $dataSetMatch[1] . ']';
}

private function printProgress()
{
if (filter_var(getenv('PHPUNIT_PRETTY_PRINT_PROGRESS'), FILTER_VALIDATE_BOOLEAN)) {
$this->numTestsRun++;

$total = $this->numTests;
$current = str_pad($this->numTestsRun, strlen($total), '0', STR_PAD_LEFT);

$this->write("[{$current}/{$total}]");
}
}
}
14 changes: 13 additions & 1 deletion tests/PrinterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,18 @@ public function testTestNameCanStartOrEndWithANumber()
$this->assertStringContainsString('✓ 123 can start or end with numbers 456', $lines[13]);
}

public function testItCanShowProgressWhileRunningTests()
{
putenv('PHPUNIT_PRETTY_PRINT_PROGRESS=true');

$lines = array_slice($this->getOutput(), 4, 10);
$count = count($lines);

foreach ($lines as $index => $line) {
$this->assertStringContainsString(vsprintf('%s/%s', [$index+1, $count]), $line);
}
}

private function getOutput(): array
{
$command = [
Expand All @@ -83,7 +95,7 @@ private function getOutput(): array
];

exec(implode(' ', $command), $out);

return $out;
}
}

0 comments on commit 9b889cf

Please sign in to comment.