Skip to content

Commit

Permalink
Merge pull request #93 from johnkary/improve-output-v5
Browse files Browse the repository at this point in the history
Improve readability of results (rework)
  • Loading branch information
johnkary authored Oct 20, 2022
2 parents 14f1d29 + 01c5e98 commit a05623c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Many factors affect test execution time. A test not properly isolated from varia

SpeedTrap helps **identify slow tests** but cannot explain **why** those tests are slow. Consider using [Blackfire.io](https://blackfire.io) to profile the test suite to specifically identify slow code.

![Screenshot of terminal using SpeedTrap](https://i.imgur.com/xSpWL4Z.png)
![Screenshot of terminal using SpeedTrap](https://user-images.githubusercontent.com/135607/196077193-ba9e5f95-91ef-4655-88a5-93bb49007a67.png)

## Installation

Expand Down
8 changes: 8 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ must extend the new `JohnKary\PHPUnit\Extension\SpeedTrap`. There are various
method name changes that may affect your custom subclass. See [PR #83](https://github.com/johnkary/phpunit-speedtrap/pull/83)
for many of the new class has changed.

If you programmatically parse the slowness report text visible when running
`vendor/bin/phpunit`, there have been some text formatting changes in the output:

* The header text has changed
* The footer text has changed
* The slow test output has changed
* Slowness execution time now displays in seconds instead of milliseconds

UPGRADE FROM 3.x to 4.0
=======================

Expand Down
7 changes: 4 additions & 3 deletions src/SpeedTrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ protected function getHiddenCount(): int
*/
protected function renderHeader(): void
{
echo sprintf("\n\nYou should really speed up these slow tests (>%sms)...\n", $this->slowThreshold);
echo sprintf("\n\nThe following tests were detected as slow (>%sms)\n", $this->slowThreshold);
}

/**
Expand All @@ -209,8 +209,9 @@ protected function renderBody(): void
for ($i = 1; $i <= $length; ++$i) {
$label = key($slowTests);
$time = array_shift($slowTests);
$seconds = $time / 1000;

echo sprintf(" %s. %sms to run %s\n", $i, $time, $label);
echo sprintf(" %s) %.3fs to run %s\n", $i, $seconds, $label);
}
}

Expand All @@ -220,7 +221,7 @@ protected function renderBody(): void
protected function renderFooter(): void
{
if ($hidden = $this->getHiddenCount()) {
printf("...and there %s %s more above your threshold hidden from view\n", $hidden == 1 ? 'is' : 'are', $hidden);
printf("and %s more slow tests hidden from view\n", $hidden);
}
}

Expand Down
7 changes: 7 additions & 0 deletions tests/SomeSlowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ public function testLongEndToEndTest()
$this->assertTrue(true);
}

public function testSlowTestsOverOneSecond()
{
$this->extendTime(1300);

$this->assertTrue(true);
}

/**
* @dataProvider provideTime
*/
Expand Down

0 comments on commit a05623c

Please sign in to comment.