-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathCustomSleepMixinTest.php
More file actions
70 lines (58 loc) · 2.05 KB
/
Copy pathCustomSleepMixinTest.php
File metadata and controls
70 lines (58 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
use PHPUnit\Framework\TestCase;
/**
* Custom delay tests.
* Note: Timers are purposefully kept loose due to frequent CI issues.
*/
class CustomSleepMixinTest extends TestCase
{
use Mindee\CustomSleepMixin;
public function testCustomSleep1Second(): void {
$lowerBound = 1;
$upperBound = 1.1;
$start = microtime(true);
$this->customSleep(1);
$elapsed = microtime(true) - $start;
$this->assertGreaterThanOrEqual($lowerBound, $elapsed);
$this->assertLessThanOrEqual($upperBound, $elapsed);
}
public function testCustomSleep0dot33Seconds(): void {
$lowerBound = 0.33;
$upperBound = 0.43;
$start = microtime(true);
$this->customSleep(0.33);
$elapsed = microtime(true) - $start;
$this->assertGreaterThanOrEqual($lowerBound, $elapsed);
$this->assertLessThanOrEqual($upperBound, $elapsed);
}
public function testCustomSleep2Seconds(): void {
$lowerBound = 2;
$upperBound = 2.1;
$start = microtime(true);
$this->customSleep(2);
$elapsed = microtime(true) - $start;
$this->assertGreaterThanOrEqual($lowerBound, $elapsed);
$this->assertLessThanOrEqual($upperBound, $elapsed);
}
public function testCustomSleep1dot5Seconds(): void {
$lowerBound = 1.5;
$upperBound = 1.6;
$start = microtime(true);
$this->customSleep(1.5);
$elapsed = microtime(true) - $start;
$this->assertGreaterThanOrEqual($lowerBound, $elapsed);
$this->assertLessThanOrEqual($upperBound, $elapsed);
}
public function testCustomSleep0Seconds(): void {
$start = microtime(true);
$this->customSleep(0);
$elapsed = microtime(true) - $start;
$this->assertLessThanOrEqual(0.0001, $elapsed);
}
public function testCustomSleepMinus1Seconds(): void {
$start = microtime(true);
$this->customSleep(-1);
$elapsed = microtime(true) - $start;
$this->assertLessThanOrEqual(0.0001, $elapsed);
}
}