forked from reactphp/async
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtilSeriesTest.php
More file actions
75 lines (59 loc) · 1.83 KB
/
Copy pathUtilSeriesTest.php
File metadata and controls
75 lines (59 loc) · 1.83 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
71
72
73
74
75
<?php
namespace React\Tests\Async;
use React\Async\Util;
use React\EventLoop\Loop;
class UtilSeriesTest extends TestCase
{
public function testSeriesWithoutTasks()
{
$tasks = array();
$callback = $this->expectCallableOnceWith(array());
$errback = $this->expectCallableNever();
Util::series($tasks, $callback, $errback);
}
public function testSeriesWithTasks()
{
$tasks = array(
function ($callback, $errback) {
Loop::addTimer(0.05, function () use ($callback) {
$callback('foo');
});
},
function ($callback, $errback) {
Loop::addTimer(0.05, function () use ($callback) {
$callback('bar');
});
},
);
$callback = $this->expectCallableOnceWith(array('foo', 'bar'));
$errback = $this->expectCallableNever();
Util::series($tasks, $callback, $errback);
$timer = new Timer($this);
$timer->start();
Loop::run();
$timer->stop();
$timer->assertInRange(0.10, 0.20);
}
public function testSeriesWithError()
{
$called = 0;
$tasks = array(
function ($callback, $errback) use (&$called) {
$callback('foo');
$called++;
},
function ($callback, $errback) {
$e = new \RuntimeException('whoops');
$errback($e);
},
function ($callback, $errback) use (&$called) {
$callback('bar');
$called++;
},
);
$callback = $this->expectCallableNever();
$errback = $this->expectCallableOnce();
Util::series($tasks, $callback, $errback);
$this->assertSame(1, $called);
}
}