forked from reactphp/promise
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeferredTest.php
More file actions
65 lines (52 loc) · 1.97 KB
/
DeferredTest.php
File metadata and controls
65 lines (52 loc) · 1.97 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
<?php
namespace React\Promise;
use React\Promise\PromiseAdapter\CallbackPromiseAdapter;
class DeferredTest extends TestCase
{
use PromiseTest\FullTestTrait;
public function getPromiseTestAdapter(callable $canceller = null): CallbackPromiseAdapter
{
$d = new Deferred($canceller);
return new CallbackPromiseAdapter([
'promise' => [$d, 'promise'],
'resolve' => [$d, 'resolve'],
'reject' => [$d, 'reject'],
'settle' => [$d, 'resolve'],
]);
}
/** @test */
public function shouldRejectWithoutCreatingGarbageCyclesIfCancellerRejectsWithException(): void
{
gc_collect_cycles();
$deferred = new Deferred(function ($resolve, $reject) {
$reject(new \Exception('foo'));
});
$deferred->promise()->cancel();
unset($deferred);
$this->assertSame(0, gc_collect_cycles());
}
/** @test */
public function shouldRejectWithoutCreatingGarbageCyclesIfParentCancellerRejectsWithException(): void
{
gc_collect_cycles();
gc_collect_cycles(); // clear twice to avoid leftovers in PHP 7.4 with ext-xdebug and code coverage turned on
$deferred = new Deferred(function ($resolve, $reject) {
$reject(new \Exception('foo'));
});
$deferred->promise()->then()->cancel();
unset($deferred);
$this->assertSame(0, gc_collect_cycles());
}
/** @test */
public function shouldRejectWithoutCreatingGarbageCyclesIfCancellerHoldsReferenceAndExplicitlyRejectWithException(): void
{
gc_collect_cycles();
gc_collect_cycles(); // clear twice to avoid leftovers in PHP 7.4 with ext-xdebug and code coverage turned on
$deferred = new Deferred(function () use (&$deferred) {
assert($deferred instanceof Deferred);
});
$deferred->reject(new \Exception('foo'));
unset($deferred);
$this->assertSame(0, gc_collect_cycles());
}
}