forked from reactphp/promise-timer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFunctionRejectTest.php
91 lines (64 loc) · 2.21 KB
/
FunctionRejectTest.php
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
namespace React\Tests\Promise\Timer;
use React\EventLoop\Loop;
use React\Promise\Timer;
class FunctionRejectTest extends TestCase
{
public function testPromiseIsPendingWithoutRunningLoop()
{
$promise = Timer\reject(0.01);
$this->expectPromisePending($promise);
}
public function testPromiseExpiredIsPendingWithoutRunningLoop()
{
$promise = Timer\reject(-1);
$this->expectPromisePending($promise);
}
public function testPromiseWillBeRejectedOnTimeout()
{
$promise = Timer\reject(0.01);
Loop::run();
$this->expectPromiseRejected($promise);
}
public function testPromiseExpiredWillBeRejectedOnTimeout()
{
$promise = Timer\reject(-1);
Loop::run();
$this->expectPromiseRejected($promise);
}
public function testCancellingPromiseWillRejectTimer()
{
$promise = Timer\reject(0.01);
$promise->cancel();
$this->expectPromiseRejected($promise);
}
public function testRejectWithInvalidLoopThrows()
{
$this->setExpectedException('InvalidArgumentException', 'Argument #2 ($loop) expected null|React\EventLoop\LoopInterface');
Timer\reject(1.0, 42);
}
public function testWaitingForPromiseToRejectDoesNotLeaveGarbageCycles()
{
if (class_exists('React\Promise\When')) {
$this->markTestSkipped('Not supported on legacy Promise v1 API');
}
gc_collect_cycles();
gc_collect_cycles(); // clear twice to avoid leftovers in PHP 7.4 with ext-xdebug and code coverage turned on
$promise = Timer\reject(0.01);
$promise->then(null, $this->expectCallableOnce()); // avoid reporting unhandled rejection
Loop::run();
unset($promise);
$this->assertEquals(0, gc_collect_cycles());
}
public function testCancellingPromiseDoesNotLeaveGarbageCycles()
{
if (class_exists('React\Promise\When')) {
$this->markTestSkipped('Not supported on legacy Promise v1 API');
}
gc_collect_cycles();
$promise = Timer\reject(0.01);
$promise->cancel();
unset($promise);
$this->assertEquals(0, gc_collect_cycles());
}
}