|
5 | 5 | namespace Codeception\Module\Symfony;
|
6 | 6 |
|
7 | 7 | use Symfony\Component\HttpKernel\DataCollector\TimeDataCollector;
|
8 |
| -use function number_format; |
| 8 | +use function round; |
9 | 9 | use function sprintf;
|
10 | 10 |
|
11 | 11 | trait TimeAssertionsTrait
|
12 | 12 | {
|
13 | 13 | /**
|
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. |
15 | 15 | *
|
16 | 16 | * If the page performed a HTTP redirect, only the time of the last request will be taken into account.
|
17 | 17 | * You can modify this behavior using [stopFollowingRedirects()](https://codeception.com/docs/modules/Symfony#stopFollowingRedirects) first.
|
18 | 18 | *
|
19 | 19 | * Also, note that using code coverage can significantly increase the time it takes to resolve a request,
|
20 | 20 | * which could lead to unreliable results when used together.
|
21 | 21 | *
|
22 |
| - * @param float $expectedMilliseconds The expected time in milliseconds |
| 22 | + * @param int|float $expectedMilliseconds The expected time in milliseconds |
23 | 23 | */
|
24 |
| - public function seeRequestTimeIsLessThan(float $expectedMilliseconds): void |
| 24 | + public function seeRequestTimeIsLessThan($expectedMilliseconds): void |
25 | 25 | {
|
| 26 | + $expectedMilliseconds = round($expectedMilliseconds, 2); |
| 27 | + |
26 | 28 | $timeCollector = $this->grabTimeCollector(__FUNCTION__);
|
27 | 29 |
|
28 |
| - $actualMilliseconds = $timeCollector->getDuration(); |
| 30 | + $actualMilliseconds = round($timeCollector->getDuration(), 2); |
29 | 31 |
|
30 | 32 | $this->assertLessThan(
|
31 | 33 | $expectedMilliseconds,
|
32 | 34 | $actualMilliseconds,
|
33 | 35 | 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 |
37 | 39 | )
|
38 | 40 | );
|
39 | 41 | }
|
|
0 commit comments