ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Sabre\Event\Loop\FunctionsTest Class Reference
+ Inheritance diagram for Sabre\Event\Loop\FunctionsTest:
+ Collaboration diagram for Sabre\Event\Loop\FunctionsTest:

Public Member Functions

 setUp ()
 
 tearDown ()
 
 testNextTick ()
 
 testTimeout ()
 
 testTimeoutOrder ()
 
 testSetInterval ()
 
 testAddWriteStream ()
 
 testAddReadStream ()
 
 testStop ()
 
 testTick ()
 

Detailed Description

Definition at line 5 of file FunctionsTest.php.

Member Function Documentation

◆ setUp()

Sabre\Event\Loop\FunctionsTest::setUp ( )

Definition at line 7 of file FunctionsTest.php.

7 {
8
9 // Always creating a fresh loop object.
10 instance(new Loop());
11
12 }
instance(Loop $newLoop=null)
Retrieves or sets the global Loop object.
Definition: functions.php:173

References Sabre\Event\Loop\instance().

+ Here is the call graph for this function:

◆ tearDown()

Sabre\Event\Loop\FunctionsTest::tearDown ( )

Definition at line 14 of file FunctionsTest.php.

14 {
15
16 // Removing the global loop object.
17 instance(null);
18
19 }

References Sabre\Event\Loop\instance().

+ Here is the call graph for this function:

◆ testAddReadStream()

Sabre\Event\Loop\FunctionsTest::testAddReadStream ( )

Definition at line 109 of file FunctionsTest.php.

109 {
110
111 $h = fopen('php://temp', 'r+');
112 fwrite($h, 'hello world');
113 rewind($h);
114
115 $result = null;
116
117 addReadStream($h, function() use ($h, &$result) {
118
119 $result = fgets($h);
121
122 });
123 run();
124 $this->assertEquals('hello world', $result);
125
126 }
$result
$h
run()
Runs the loop.
Definition: functions.php:130
removeReadStream($stream)
Stop watching a stream for reads.
Definition: functions.php:103
addReadStream($stream, callable $cb)
Adds a read stream.
Definition: functions.php:72

References $h, $result, Sabre\Event\Loop\addReadStream(), Sabre\Event\Loop\removeReadStream(), and Sabre\Event\Loop\run().

+ Here is the call graph for this function:

◆ testAddWriteStream()

Sabre\Event\Loop\FunctionsTest::testAddWriteStream ( )

Definition at line 94 of file FunctionsTest.php.

94 {
95
96 $h = fopen('php://temp', 'r+');
97 addWriteStream($h, function() use ($h) {
98
99 fwrite($h, 'hello world');
101
102 });
103 run();
104 rewind($h);
105 $this->assertEquals('hello world', stream_get_contents($h));
106
107 }
addWriteStream($stream, callable $cb)
Adds a write stream.
Definition: functions.php:91
removeWriteStream($stream)
Stop watching a stream for writes.
Definition: functions.php:115

References $h, Sabre\Event\Loop\addWriteStream(), Sabre\Event\Loop\removeWriteStream(), and Sabre\Event\Loop\run().

+ Here is the call graph for this function:

◆ testNextTick()

Sabre\Event\Loop\FunctionsTest::testNextTick ( )

Definition at line 21 of file FunctionsTest.php.

21 {
22
23 $check = 0;
24 nextTick(function() use (&$check) {
25
26 $check++;
27
28 });
29
30 run();
31
32 $this->assertEquals(1, $check);
33
34 }
nextTick(callable $cb)
Runs a function immediately at the next iteration of the loop.
Definition: functions.php:52

References Sabre\Event\Loop\nextTick(), and Sabre\Event\Loop\run().

+ Here is the call graph for this function:

◆ testSetInterval()

Sabre\Event\Loop\FunctionsTest::testSetInterval ( )

Definition at line 76 of file FunctionsTest.php.

76 {
77
78 $check = 0;
79 $intervalId = null;
80 $intervalId = setInterval(function() use (&$check, &$intervalId) {
81
82 $check++;
83 if ($check > 5) {
84 clearInterval($intervalId);
85 }
86
87 }, 0.02);
88
89 run();
90 $this->assertEquals(6, $check);
91
92 }
setInterval(callable $cb, $timeout)
Executes a function every x seconds.
Definition: functions.php:28
clearInterval($intervalId)
Stops a running internval.
Definition: functions.php:40

References Sabre\Event\Loop\clearInterval(), Sabre\Event\Loop\run(), and Sabre\Event\Loop\setInterval().

+ Here is the call graph for this function:

◆ testStop()

Sabre\Event\Loop\FunctionsTest::testStop ( )

Definition at line 128 of file FunctionsTest.php.

128 {
129
130 $check = 0;
131 setTimeout(function() use (&$check) {
132 $check++;
133 }, 200);
134
135 nextTick(function() {
136 stop();
137 });
138 run();
139
140 $this->assertEquals(0, $check);
141
142 }
stop()
Stops a running eventloop.
Definition: functions.php:162
setTimeout(callable $cb, $timeout)
Executes a function after x seconds.
Definition: functions.php:12

References Sabre\Event\Loop\nextTick(), Sabre\Event\Loop\run(), Sabre\Event\Loop\setTimeout(), and Sabre\Event\Loop\stop().

+ Here is the call graph for this function:

◆ testTick()

Sabre\Event\Loop\FunctionsTest::testTick ( )

Definition at line 144 of file FunctionsTest.php.

144 {
145
146 $check = 0;
147 setTimeout(function() use (&$check) {
148 $check++;
149 }, 1);
150
151 nextTick(function() use (&$check) {
152 $check++;
153 });
154 tick();
155
156 $this->assertEquals(1, $check);
157
158 }
tick($block=false)
Executes all pending events.
Definition: functions.php:151

References Sabre\Event\Loop\nextTick(), Sabre\Event\Loop\setTimeout(), and Sabre\Event\Loop\tick().

+ Here is the call graph for this function:

◆ testTimeout()

Sabre\Event\Loop\FunctionsTest::testTimeout ( )

Definition at line 36 of file FunctionsTest.php.

36 {
37
38 $check = 0;
39 setTimeout(function() use (&$check) {
40
41 $check++;
42
43 }, 0.02);
44
45 run();
46
47 $this->assertEquals(1, $check);
48
49 }

References Sabre\Event\Loop\run(), and Sabre\Event\Loop\setTimeout().

+ Here is the call graph for this function:

◆ testTimeoutOrder()

Sabre\Event\Loop\FunctionsTest::testTimeoutOrder ( )

Definition at line 51 of file FunctionsTest.php.

51 {
52
53 $check = [];
54 setTimeout(function() use (&$check) {
55
56 $check[] = 'a';
57
58 }, 0.2);
59 setTimeout(function() use (&$check) {
60
61 $check[] = 'b';
62
63 }, 0.1);
64 setTimeout(function() use (&$check) {
65
66 $check[] = 'c';
67
68 }, 0.3);
69
70 run();
71
72 $this->assertEquals(['b', 'a', 'c'], $check);
73
74 }

References Sabre\Event\Loop\run(), and Sabre\Event\Loop\setTimeout().

+ Here is the call graph for this function:

The documentation for this class was generated from the following file: