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

Public Member Functions

 testNextTick ()
 
 testTimeout ()
 
 testTimeoutOrder ()
 
 testSetInterval ()
 
 testAddWriteStream ()
 
 testAddReadStream ()
 
 testStop ()
 
 testTick ()
 
 testNextTickStacking ()
 Here we add a new nextTick function as we're in the middle of a current nextTick. More...
 

Detailed Description

Definition at line 5 of file LoopTest.php.

Member Function Documentation

◆ testAddReadStream()

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

Definition at line 100 of file LoopTest.php.

References $h, and $result.

100  {
101 
102  $h = fopen('php://temp', 'r+');
103  fwrite($h, 'hello world');
104  rewind($h);
105 
106  $loop = new Loop();
107 
108  $result = null;
109 
110  $loop->addReadStream($h, function() use ($h, $loop, &$result) {
111 
112  $result = fgets($h);
113  $loop->removeReadStream($h);
114 
115  });
116  $loop->run();
117  $this->assertEquals('hello world', $result);
118 
119  }
$result
$h

◆ testAddWriteStream()

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

Definition at line 84 of file LoopTest.php.

References $h.

84  {
85 
86  $h = fopen('php://temp', 'r+');
87  $loop = new Loop();
88  $loop->addWriteStream($h, function() use ($h, $loop) {
89 
90  fwrite($h, 'hello world');
91  $loop->removeWriteStream($h);
92 
93  });
94  $loop->run();
95  rewind($h);
96  $this->assertEquals('hello world', stream_get_contents($h));
97 
98  }
$h

◆ testNextTick()

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

Definition at line 7 of file LoopTest.php.

7  {
8 
9  $loop = new Loop();
10  $check = 0;
11  $loop->nextTick(function() use (&$check) {
12 
13  $check++;
14 
15  });
16 
17  $loop->run();
18 
19  $this->assertEquals(1, $check);
20 
21  }

◆ testNextTickStacking()

Sabre\Event\Loop\LoopTest::testNextTickStacking ( )

Here we add a new nextTick function as we're in the middle of a current nextTick.

Definition at line 159 of file LoopTest.php.

159  {
160 
161  $loop = new Loop();
162  $check = 0;
163  $loop->nextTick(function() use (&$check, $loop) {
164 
165  $loop->nextTick(function() use (&$check) {
166 
167  $check++;
168 
169  });
170  $check++;
171 
172  });
173 
174  $loop->run();
175 
176  $this->assertEquals(2, $check);
177 
178  }

◆ testSetInterval()

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

Definition at line 65 of file LoopTest.php.

65  {
66 
67  $loop = new Loop();
68  $check = 0;
69  $intervalId = null;
70  $intervalId = $loop->setInterval(function() use (&$check, &$intervalId, $loop) {
71 
72  $check++;
73  if ($check > 5) {
74  $loop->clearInterval($intervalId);
75  }
76 
77  }, 0.02);
78 
79  $loop->run();
80  $this->assertEquals(6, $check);
81 
82  }

◆ testStop()

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

Definition at line 121 of file LoopTest.php.

121  {
122 
123  $check = 0;
124  $loop = new Loop();
125  $loop->setTimeout(function() use (&$check) {
126  $check++;
127  }, 200);
128 
129  $loop->nextTick(function() use ($loop) {
130  $loop->stop();
131  });
132  $loop->run();
133 
134  $this->assertEquals(0, $check);
135 
136  }

◆ testTick()

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

Definition at line 138 of file LoopTest.php.

138  {
139 
140  $check = 0;
141  $loop = new Loop();
142  $loop->setTimeout(function() use (&$check) {
143  $check++;
144  }, 1);
145 
146  $loop->nextTick(function() use ($loop, &$check) {
147  $check++;
148  });
149  $loop->tick();
150 
151  $this->assertEquals(1, $check);
152 
153  }

◆ testTimeout()

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

Definition at line 23 of file LoopTest.php.

23  {
24 
25  $loop = new Loop();
26  $check = 0;
27  $loop->setTimeout(function() use (&$check) {
28 
29  $check++;
30 
31  }, 0.02);
32 
33  $loop->run();
34 
35  $this->assertEquals(1, $check);
36 
37  }

◆ testTimeoutOrder()

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

Definition at line 39 of file LoopTest.php.

39  {
40 
41  $loop = new Loop();
42  $check = [];
43  $loop->setTimeout(function() use (&$check) {
44 
45  $check[] = 'a';
46 
47  }, 0.2);
48  $loop->setTimeout(function() use (&$check) {
49 
50  $check[] = 'b';
51 
52  }, 0.1);
53  $loop->setTimeout(function() use (&$check) {
54 
55  $check[] = 'c';
56 
57  }, 0.3);
58 
59  $loop->run();
60 
61  $this->assertEquals(['b', 'a', 'c'], $check);
62 
63  }

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