Skip to content

Commit

Permalink
Merge pull request #15 from zf2timo/develop
Browse files Browse the repository at this point in the history
1.0.0
  • Loading branch information
zf2timo committed Jan 11, 2016
2 parents 18c50e2 + 292c4db commit 93a3f10
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
# PHPUnit Pretty Result Printer

This Result Printer for PHPUnit shows more information in a more readable format during a test run
This Result Printer for PHPUnit shows more information in a more readable format during a test run

# Installation

Installation is provided via composer and can be done with the following command:
```bash
$ composer require --dev zf2timo/phpunit-pretty-result-printer:1.0.0
```

To activate the Printer for PHPUnit, just add it to your configuration XML:
```xml
<?xml version="1.0" encoding="UTF-8"?>
<phpunit printerClass="PrettyResultPrinter\Printer">
// ....
</phpunit>
```
31 changes: 30 additions & 1 deletion src/Printer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use PHPUnit_Framework_Test;
use PHPUnit_TextUI_ResultPrinter;


/**
* Class Printer
*
Expand All @@ -28,6 +27,27 @@ class Printer extends \PHPUnit_TextUI_ResultPrinter
*/
private $maxClassNameLength = 40;

/**
* @var int
*/
private $maxNumberOfColumns;

/**
* {@inheritdoc}
*/
public function __construct(
$out = null,
$verbose = false,
$colors = self::COLOR_DEFAULT,
$debug = false,
$numberOfColumns = 80
) {
parent::__construct($out, $verbose, $colors, $debug, $numberOfColumns);

$this->maxNumberOfColumns = $numberOfColumns;
$this->maxClassNameLength = intval($numberOfColumns * 0.6);
}

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -62,6 +82,13 @@ protected function writeProgressWithColor($color, $buffer)
*/
private function printTestCaseStatus($color, $buffer)
{
if ($this->column == $this->maxNumberOfColumns) {
$this->writeNewLine();
$padding = $this->maxClassNameLength;
$this->column = $padding;
echo str_pad(' ', $padding) . "\t";
}

switch (strtoupper($buffer)) {
case '.':
$color = 'fg-green,bold';
Expand All @@ -74,6 +101,7 @@ private function printTestCaseStatus($color, $buffer)
}

echo parent::formatWithColor($color, $buffer);
$this->column++;
}

/**
Expand Down Expand Up @@ -101,6 +129,7 @@ protected function printClassName()
} else {
$this->write($className);
}
$this->column += strlen($className) + 4;
echo "\t";

$this->lastClassName = $this->className;
Expand Down

0 comments on commit 93a3f10

Please sign in to comment.