Skip to content

Commit b64dcd0

Browse files
committed
Changed unique traces to exclude suppressed traces so they don't have to be filtered later.
Changed ClassicTheme to emit line break before trace colour block instead of inside. Renamed CapabilitiesTest::testGigaSlow -> testVerySlow. Updated Readme.
1 parent 8d4a895 commit b64dcd0

File tree

13 files changed

+51
-52
lines changed

13 files changed

+51
-52
lines changed

README.md

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Pip is a [PHPUnit][] extension that immediately prints exceptions and assertion
1515
## Benefits
1616

1717
* Display the name of each test case as it is executed.
18-
* Display the execution time of each test in tiered colour bands.
18+
* Display the execution time of each test in configurable, tiered colour bands.
1919
* Immediately print exceptions, assertion failures, warnings, notice and deprecation messages as they occur.
2020
* Flawless test suite indicator: success dot turns to red exclamation mark if any prior tests failed. Useful for CI consoles without a scrollback buffer.
2121

@@ -57,10 +57,10 @@ Pip's behaviour can be customized by adding `<parameter>` nodes as children of t
5757
5858
| Parameter name | Default value | Description |
5959
|-----------------|---------------|------------------------------------------------------------------------|
60-
| perf.slow | 200 (ms) | Sets the performance threshold for _slow_ (yellow) tests |
61-
| perf.vslow | 1000 (ms) | Sets the performance threshold for _very slow_ (red) tests |
60+
| perf.slow | 200 (ms) | Sets the performance threshold for _slow_ (yellow) tests. |
61+
| perf.vslow | 1000 (ms) | Sets the performance threshold for _very slow_ (red) tests. |
6262
| test.dp.args | true | True to show the arguments passed by the data provider, false to hide. |
63-
| test.name.strip | '' | Strips the specified matching portion of the test name |
63+
| test.name.strip | '' | Strips the specified matching portion of the test name. |
6464
6565
## Requirements
6666
@@ -72,13 +72,21 @@ Pip's behaviour can be customized by adding `<parameter>` nodes as children of t
7272
7373
## Testing Pip
7474
75-
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.
75+
To run the full test suite, use the following command.
7676
77-
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.
77+
```sh
78+
composer test
79+
```
80+
81+
Pip'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. To run `CapabilitiesTest`, specify the following command
7882
79-
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.php`.
83+
```sh
84+
composer test test/CapabilitiesTest.php
85+
```
86+
87+
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.
8088
81-
### Writing a functional test
89+
### Writing functional tests
8290
8391
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.
8492

src/PipExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
declare(strict_types = 1);
2+
declare(strict_types=1);
33

44
namespace ScriptFUSION\Pip;
55

src/Printer.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,6 @@ public function __construct(private readonly PipConfig $config)
4343
{
4444
}
4545

46-
private function addUniqueTrace(Trace $trace): void
47-
{
48-
$this->uniqueTraces[$trace->getIssueId()] = $trace;
49-
}
50-
5146
public function trace(Event $event): void
5247
{
5348
if ($event instanceof ExecutionStarted) {
@@ -155,4 +150,9 @@ public function trace(Event $event): void
155150
echo PHP_EOL, PHP_EOL;
156151
}
157152
}
153+
154+
private function addUniqueTrace(Trace $trace): void
155+
{
156+
$trace->suppressed || $this->uniqueTraces[$trace->getId()] ??= $trace;
157+
}
158158
}

src/Theme/ClassicTheme.php

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,17 @@ public function onTestFinished(TestResult $result): void
4747
$throwable = $throwable->previous();
4848
}
4949

50-
$firstIssue = true;
50+
$result->uniqueTraces && print PHP_EOL;
5151
foreach ($result->uniqueTraces as $trace) {
52-
if (!$trace->suppressed) {
53-
$issueStatusColour = self::getColour($trace->issueStatus);
54-
printf(
55-
Color::colorize("fg-$issueStatusColour", '%s%s: %s in %s on line %d%s'),
56-
$firstIssue ? PHP_EOL : '',
57-
$trace->issueStatus->name,
58-
$trace->message,
59-
$trace->file,
60-
$trace->line,
61-
PHP_EOL . PHP_EOL,
62-
);
63-
$firstIssue = false;
64-
}
52+
$issueStatusColour = self::getColour($trace->issueStatus);
53+
printf(
54+
Color::colorize("fg-$issueStatusColour", '%s: %s in %s on line %s%s%5$s'),
55+
$trace->issueStatus->name,
56+
$trace->message,
57+
$trace->file,
58+
$trace->line,
59+
PHP_EOL,
60+
);
6561
}
6662
}
6763

src/Trace.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,12 @@ public static function fromEvent(PhpWarningTriggered|PhpNoticeTriggered|PhpDepre
3333
}
3434

3535
/**
36-
* Key to identify identical issues, using the same rules as PHPUnit.
36+
* Gets a unique identifier for the source of this trace, using the same rules as PHPUnit.
3737
*
3838
* @see \PHPUnit\TestRunner\TestResult\Collector::issueId
3939
*/
40-
public function getIssueId(): string
40+
public function getId(): string
4141
{
42-
return sprintf(
43-
'%s:%s:%s',
44-
$this->file,
45-
$this->line,
46-
$this->message,
47-
);
42+
return "$this->file:$this->line:$this->message";
4843
}
4944
}

test/CapabilitiesTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use PHPUnit\Framework\TestCase;
66

77
/**
8-
* Tests the capabilities of the PIP printer.
8+
* Tests the capabilities of the Pip printer.
99
*/
1010
final class CapabilitiesTest extends TestCase
1111
{
@@ -155,7 +155,7 @@ public function testSlow(): void
155155
self::assertTrue(true);
156156
}
157157

158-
public function testGigaSlow(): void
158+
public function testVerySlow(): void
159159
{
160160
sleep(1);
161161

test/functional/errors & exceptions/E_DEPRECATED.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ Runtime: %s
1414
Configuration: %s
1515

1616
100% D ScriptFUSIONTest\Pip\CapabilitiesTest::testDeprecation (%d ms)
17-
[33;1m
18-
Deprecated: Serializable@anonymous implements the Serializable interface, which is deprecated. Implement __serialize() and __unserialize() instead (or in addition, if support for old PHP versions is necessary) in %s%eCapabilitiesTest.php on line %d
17+
18+
[33;1mDeprecated: Serializable@anonymous implements the Serializable interface, which is deprecated. Implement __serialize() and __unserialize() instead (or in addition, if support for old PHP versions is necessary) in %s%eCapabilitiesTest.php on line %d
1919

2020

2121

test/functional/errors & exceptions/E_NOTICE.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ Runtime: %s
1414
Configuration: %s
1515

1616
100% N ScriptFUSIONTest\Pip\CapabilitiesTest::testNotice (%d ms)
17-
[33;1m
18-
Notice: Only variables should be assigned by reference in %s%eCapabilitiesTest.php on line %d
17+
18+
[33;1mNotice: Only variables should be assigned by reference in %s%eCapabilitiesTest.php on line %d
1919

2020

2121

test/functional/errors & exceptions/E_WARNING duplicates.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ Runtime: %s
1414
Configuration: %s
1515

1616
100% W ScriptFUSIONTest\Pip\CapabilitiesTest::testWarningDuplicates (%d ms)
17-
[33;1m
18-
Warning: foreach() argument must be of type array|object, int given in %s%eCapabilitiesTest.php on line %d
17+
18+
[33;1mWarning: foreach() argument must be of type array|object, int given in %s%eCapabilitiesTest.php on line %d
1919

2020
Warning: foreach() argument must be of type array|object, int given in %s%eCapabilitiesTest.php on line %d
2121

test/functional/errors & exceptions/E_WARNING.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ Runtime: %s
1414
Configuration: %s
1515

1616
100% W ScriptFUSIONTest\Pip\CapabilitiesTest::testWarning (%d ms)
17-
[33;1m
18-
Warning: foreach() argument must be of type array|object, int given in %s%eCapabilitiesTest.php on line %d
17+
18+
[33;1mWarning: foreach() argument must be of type array|object, int given in %s%eCapabilitiesTest.php on line %d
1919

2020

2121

0 commit comments

Comments
 (0)