Skip to content
This repository was archived by the owner on May 26, 2021. It is now read-only.

Commit 30a5430

Browse files
committed
Initial commit.
0 parents  commit 30a5430

File tree

4 files changed

+214
-0
lines changed

4 files changed

+214
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/vendor/

README.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# PHPUnit Result Printer
2+
3+
[![Source](http://img.shields.io/badge/source-skyzyx/phpunit-result-printer-blue.svg?style=flat-square)](https://github.com/skyzyx/phpunit-result-printer)
4+
[![Latest Stable Version](http://img.shields.io/packagist/v/skyzyx/phpunit-result-printer.svg?style=flat-square)](https://packagist.org/packages/skyzyx/phpunit-result-printer)
5+
[![Total Downloads](http://img.shields.io/packagist/dt/skyzyx/phpunit-result-printer.svg?style=flat-square)](https://packagist.org/packages/skyzyx/phpunit-result-printer)
6+
[![Open Issues](http://img.shields.io/github/issues/skyzyx/phpunit-result-printer.svg?style=flat-square)](https://github.com/skyzyx/phpunit-result-printer/issues)
7+
[![License](http://img.shields.io/packagist/l/skyzyx/phpunit-result-printer-blue.svg?style=flat-square)](https://packagist.org/packages/skyzyx/phpunit-result-printer)
8+
[![Author](http://img.shields.io/badge/[email protected]?style=flat-square)](https://twitter.com/skyzyx)
9+
10+
A custom result printer for PHPUnit.
11+
12+
13+
## Examples
14+
15+
{Fill-in: Example usage of this code.}
16+
17+
18+
## Installation
19+
20+
Using [Composer]:
21+
```bash
22+
composer require skyzyx/phpunit-result-printer=^1.0
23+
```
24+
25+
And include it in your scripts:
26+
27+
```php
28+
require_once 'vendor/autoload.php';
29+
```
30+
31+
32+
## Testing
33+
34+
Firstly, run `composer install --optimize-autoloader` to download and install the dependencies.
35+
36+
You can run the tests as follows:
37+
```bash
38+
bin/phpunit
39+
```
40+
41+
42+
## Contributing
43+
Here's the process for contributing:
44+
45+
1. Fork PHPUnit Result Printer to your GitHub account.
46+
2. Clone your GitHub copy of the repository into your local workspace.
47+
3. Write code, fix bugs, and add tests with 100% code coverage.
48+
4. Commit your changes to your local workspace and push them up to your GitHub copy.
49+
5. You submit a GitHub pull request with a description of what the change is.
50+
6. The contribution is reviewed. Maybe there will be some banter back-and-forth in the comments.
51+
7. If all goes well, your pull request will be accepted and your changes are merged in.
52+
53+
54+
## Authors, Copyright & Licensing
55+
56+
* Copyright (c) 2014-2016 [Ryan Parman](http://ryanparman.com).
57+
58+
See also the list of [contributors](https://github.com/skyzyx/phpunit-result-printer/contributors) who participated in this project.
59+
60+
Licensed for use under the terms of the [MIT] license.
61+
62+
63+
## Coding Standards
64+
65+
PSR-0/1/2 are a solid foundation, but are not an entire coding style by themselves. I have taken the time to document all of the nitpicky patterns and nuances of my personal coding style. It goes well-beyond brace placement and tabs vs. spaces to cover topics such as docblock annotations, ternary operations and which variation of English to use. It aims for thoroughness and pedanticism over hoping that we can all get along.
66+
67+
<https://github.com/skyzyx/php-coding-standards>
68+
69+
[PHP]: http://php.net
70+
[Composer]: https://getcomposer.org
71+
[MIT]: http://www.opensource.org/licenses/mit-license.php
72+
[Apache 2.0]: http://opensource.org/licenses/Apache-2.0

ResultPrinter.php

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
<?php
2+
/**
3+
* Copyright (c) 2014-2016 Ryan Parman
4+
*/
5+
6+
namespace Skyzyx\ResultPrinter;
7+
8+
class ResultPrinter extends PHPUnit_TextUI_ResultPrinter
9+
{
10+
/** @var string */
11+
protected $test_name_status = '';
12+
13+
/** @var string */
14+
protected $errorEmoji = "!"; // Single exclamation
15+
16+
/** @var string */
17+
protected $failureEmoji = "\xE2\x80\xBC"; // Double exclamation
18+
19+
/** @var string */
20+
protected $incompleteEmoji = "I";
21+
22+
/** @var string */
23+
protected $riskyEmoji = "R";
24+
25+
/** @var string */
26+
protected $skippedEmoji = "S";
27+
28+
/** @var string */
29+
protected $passEmoji = "\xE2\x9c\x93"; // Checkmark
30+
31+
/**
32+
* {@inheritdoc}
33+
*/
34+
protected function writeProgress($progress)
35+
{
36+
switch ($progress) {
37+
case 'E':
38+
return parent::writeProgress(sprintf('%s %s',
39+
$this->errorEmoji,
40+
$this->test_name_status));
41+
42+
case 'F':
43+
return parent::writeProgress(sprintf('%s %s',
44+
$this->failureEmoji,
45+
$this->test_name_status));
46+
47+
case 'I':
48+
return parent::writeProgress(sprintf('%s %s',
49+
$this->incompleteEmoji,
50+
$this->test_name_status));
51+
52+
case 'R':
53+
return parent::writeProgress(sprintf('%s %s',
54+
$this->riskyEmoji,
55+
$this->test_name_status));
56+
57+
case 'S':
58+
return parent::writeProgress(sprintf('%s %s',
59+
$this->skippedEmoji,
60+
$this->test_name_status));
61+
62+
case '.':
63+
return parent::writeProgress(sprintf('%s %s',
64+
$this->passEmoji,
65+
$this->test_name_status));
66+
67+
default:
68+
return parent::writeProgress(sprintf('%s %s',
69+
$progress,
70+
$this->test_name_status));
71+
}
72+
}
73+
74+
/**
75+
* {@inheritdoc}
76+
*/
77+
public function startTestSuite(\PHPUnit_Framework_TestSuite $suite)
78+
{
79+
if ($this->numTests == -1) {
80+
$this->numTests = count($suite);
81+
$this->numTestsWidth = strlen((string) $this->numTests);
82+
$this->maxColumn = 0;
83+
}
84+
}
85+
86+
/**
87+
* {@inheritdoc}
88+
*/
89+
public function endTest(\PHPUnit_Framework_Test $test, $time)
90+
{
91+
$test_name = \PHPUnit_Util_Test::describe($test);
92+
93+
if (!empty($test_name)) {
94+
$this->test_name_status = sprintf("%s (%s)\n",
95+
$test_name,
96+
sprintf("%s ms",
97+
round($time * 1000)));
98+
}
99+
100+
if (!$this->lastTestFailed) {
101+
$this->writeProgress('.');
102+
}
103+
104+
if ($test instanceof \PHPUnit_Framework_TestCase) {
105+
$this->numAssertions += $test->getNumAssertions();
106+
} elseif ($test instanceof \PHPUnit_Extensions_PhptTestCase) {
107+
$this->numAssertions++;
108+
}
109+
110+
$this->lastTestFailed = false;
111+
112+
if ($test instanceof \PHPUnit_Framework_TestCase) {
113+
if (method_exists($this, 'hasExpectationOnOutput') && !$test->hasExpectationOnOutput()) {
114+
$this->write($test->getActualOutput());
115+
}
116+
}
117+
}
118+
119+
/**
120+
* {@inheritdoc}
121+
*/
122+
protected function writeProgressWithColor($color, $buffer)
123+
{
124+
return $this->writeProgress($buffer);
125+
}
126+
}

composer.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "skyzyx/phpunit-result-printer",
3+
"description": "A custom printer for PHPUnit.",
4+
"type": "library",
5+
"require": {
6+
"phpunit/phpunit": "*"
7+
},
8+
"license": "MIT",
9+
"authors": [
10+
{
11+
"name": "Ryan Parman",
12+
"email": "[email protected]"
13+
}
14+
]
15+
}

0 commit comments

Comments
 (0)