Skip to content

Commit 65bbdc9

Browse files
committed
Added testing section to readme.
1 parent f2848fe commit 65bbdc9

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

README.md

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ Immediate Exception Printer is a [PHPUnit][PHPUnit] plug-in that prints out exce
1515
* Display the execution time of each test in tiered colour bands.
1616
* Display the name of each test case as it is executed.
1717

18+
## Preview
19+
20+
The following preview is somewhat atypical but shows all tested output cases this printer supports.
21+
22+
![Preview image](https://raw.githubusercontent.com/ScriptFUSION/PHPUnit-Immediate-Exception-Printer/master/doc/images/test%20run%201.0.png)
23+
24+
Not shown: the normal test summary output you're used to seeing at the end of a test run. This library makes no attempt to modify the summary; only runtime output is changed.
25+
1826
## Usage
1927

2028
1. Add the library to your Composer file's `require-dev` section.
@@ -40,18 +48,32 @@ Immediate Exception Printer is a [PHPUnit][PHPUnit] plug-in that prints out exce
4048

4149
4. Enjoy immediate test execution feedback.
4250

43-
## Preview
51+
## Requirements
4452

45-
The following preview is somewhat atypical but shows all tested output cases this printer supports.
53+
* PHP 5.6 or newer.
54+
* [PHPUnit][PHPUnit] 5.5 or newer. PHPUnit 6 not yet supported.
4655

47-
![Preview image](https://raw.githubusercontent.com/ScriptFUSION/PHPUnit-Immediate-Exception-Printer/master/doc/images/test%20run%201.0.png)
56+
## Testing
4857

49-
Not shown: the normal test summary output you're used to seeing at the end of a test run. This library makes no attempt to modify the summary; only runtime output is changed.
58+
The printer's capabilities are exploited via `CapabilitiesTest`. However, this test file isn't run directly because many of these tests are designed to fail. Instead, we write tests that run PHPUnit internally, each of which invokes one of the capability test cases and verifies its output.
5059

51-
## Requirements
60+
The real tests, also known as *functional tests*, are located in `test/functional`, written in PHPT format. PHPT is a [scarcely documented format](http://qa.php.net/phpt_details.php) designed to support [testing PHP itself](https://qa.php.net/write-test.php). An undocumented feature of PHPUnit is its limited support for a subset of the PHPT test specification, which we exploit to test PHPUnit itself with our printer implementation loaded.
61+
62+
To run the tests, simply specify `vendor/bin/phpunit -c test` on the command line from the project directory. By default, we run all the functional PHPT tests. To run `CapabilitiesTest` instead, specify `vendor/bin/phpunit -c test test/CapabilitiesTest`.
63+
64+
### Writing a functional test
65+
66+
To test the output of a particular capability we run `CapabilitiesTest` with the `--filter` option to target a specific test case. Each functional test contains the arguments passed to PHPUnit in the `--ARGS--` section of the file. These arguments can be pasted directly after the PHPUnit command to see the resulting output from that test case. We verify the output in the `--EXPECTF--` section of the file.
67+
68+
One challenge we must overcome is verifying coloured output including ANSI escape sequences. To see these escape sequences we can pipe the output of a specific capability test to `cat -v` as shown in the following example.
69+
70+
```bash
71+
vendor/bin/phpunit -c test --colors=always test/CapabilitiesTest --filter ::testSuccess$ | cat -v
72+
```
73+
74+
The output from `cat` will print the "escape" character as `^[`. We must replace each occurrence of this character sequence with the literal escape character (ASCII character 27). The easiest way to obtain the real escape character is to just copy it from an existing functional test.
5275

53-
* PHP 5.6 or newer
54-
* [PHPUnit][PHPUnit] 5.5 or newer
76+
Create a new functional test by copying an existing test as a template, then modify the PHPUnit arguments and the expected output to match what we expect using the techniques just described. Don't forget to give the test a clear description in the `--TEST--` section!
5577

5678
## Inspiration
5779

0 commit comments

Comments
 (0)