Skip to content

Commit

Permalink
Slowness execution time output in seconds instead of milliseconds
Browse files Browse the repository at this point in the history
Slow tests often run for over 1 second. The output of 1000 milliseconds or more
can be harder to read the longer the test runs. Using seconds inserts a decimal
to make output easier to read for humans.

For example, a slow test running for 12432 milliseconds displays as 12.432 seconds
  • Loading branch information
johnkary committed Oct 17, 2022
1 parent 14f1d29 commit 386f65b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/SpeedTrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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. %ss to run %s\n", $i, $seconds, $label);
}
}

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 386f65b

Please sign in to comment.