Skip to content

Commit 9fd1507

Browse files
committed
Allow integers, round to 2 decimals
1 parent f4e2694 commit 9fd1507

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/Codeception/Module/Symfony/TimeAssertionsTrait.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,37 @@
55
namespace Codeception\Module\Symfony;
66

77
use Symfony\Component\HttpKernel\DataCollector\TimeDataCollector;
8-
use function number_format;
8+
use function round;
99
use function sprintf;
1010

1111
trait TimeAssertionsTrait
1212
{
1313
/**
14-
* Asserts that the time a request lasted is less than expected (`$expectedTime`).
14+
* Asserts that the time a request lasted is less than expected.
1515
*
1616
* If the page performed a HTTP redirect, only the time of the last request will be taken into account.
1717
* You can modify this behavior using [stopFollowingRedirects()](https://codeception.com/docs/modules/Symfony#stopFollowingRedirects) first.
1818
*
1919
* Also, note that using code coverage can significantly increase the time it takes to resolve a request,
2020
* which could lead to unreliable results when used together.
2121
*
22-
* @param float $expectedMilliseconds The expected time in milliseconds
22+
* @param int|float $expectedMilliseconds The expected time in milliseconds
2323
*/
24-
public function seeRequestTimeIsLessThan(float $expectedMilliseconds): void
24+
public function seeRequestTimeIsLessThan($expectedMilliseconds): void
2525
{
26+
$expectedMilliseconds = round($expectedMilliseconds, 2);
27+
2628
$timeCollector = $this->grabTimeCollector(__FUNCTION__);
2729

28-
$actualMilliseconds = $timeCollector->getDuration();
30+
$actualMilliseconds = round($timeCollector->getDuration(), 2);
2931

3032
$this->assertLessThan(
3133
$expectedMilliseconds,
3234
$actualMilliseconds,
3335
sprintf(
34-
'The request was expected to last less than %s ms, but it actually lasted %s ms.',
35-
number_format($expectedMilliseconds, 2),
36-
number_format($actualMilliseconds, 2)
36+
'The request was expected to last less than %d ms, but it actually lasted %d ms.',
37+
$expectedMilliseconds,
38+
$actualMilliseconds
3739
)
3840
);
3941
}

0 commit comments

Comments
 (0)