Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 45f121d

Browse files
committed
Fix forward compatibility with upcoming EventLoop releases
1 parent bf3c6ee commit 45f121d

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

tests/UnixServerTest.php

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
namespace React\Tests\Socket;
44

5-
use React\EventLoop\StreamSelectLoop;
5+
use Clue\React\Block;
6+
use React\EventLoop\Factory;
67
use React\Socket\UnixServer;
78
use React\Stream\DuplexResourceStream;
89

@@ -12,17 +13,12 @@ class UnixServerTest extends TestCase
1213
private $server;
1314
private $uds;
1415

15-
private function createLoop()
16-
{
17-
return new StreamSelectLoop();
18-
}
19-
2016
/**
2117
* @covers React\Socket\UnixServer::__construct
2218
*/
2319
public function setUp()
2420
{
25-
$this->loop = $this->createLoop();
21+
$this->loop = Factory::create();
2622
$this->uds = $this->getRandomSocketUri();
2723
$this->server = new UnixServer($this->uds, $this->loop);
2824
}
@@ -43,7 +39,7 @@ public function testConnection()
4339
$client = stream_socket_client($this->uds);
4440

4541
$this->server->on('connection', $this->expectCallableOnce());
46-
$this->loop->tick();
42+
$this->tick();
4743
}
4844

4945
/**
@@ -56,9 +52,9 @@ public function testConnectionWithManyClients()
5652
$client3 = stream_socket_client($this->uds);
5753

5854
$this->server->on('connection', $this->expectCallableExactly(3));
59-
$this->loop->tick();
60-
$this->loop->tick();
61-
$this->loop->tick();
55+
$this->tick();
56+
$this->tick();
57+
$this->tick();
6258
}
6359

6460
public function testDataEventWillNotBeEmittedWhenClientSendsNoData()
@@ -70,8 +66,8 @@ public function testDataEventWillNotBeEmittedWhenClientSendsNoData()
7066
$this->server->on('connection', function ($conn) use ($mock) {
7167
$conn->on('data', $mock);
7268
});
73-
$this->loop->tick();
74-
$this->loop->tick();
69+
$this->tick();
70+
$this->tick();
7571
}
7672

7773
public function testDataWillBeEmittedWithDataClientSends()
@@ -85,8 +81,8 @@ public function testDataWillBeEmittedWithDataClientSends()
8581
$this->server->on('connection', function ($conn) use ($mock) {
8682
$conn->on('data', $mock);
8783
});
88-
$this->loop->tick();
89-
$this->loop->tick();
84+
$this->tick();
85+
$this->tick();
9086
}
9187

9288
public function testDataWillBeEmittedEvenWhenClientShutsDownAfterSending()
@@ -100,8 +96,8 @@ public function testDataWillBeEmittedEvenWhenClientShutsDownAfterSending()
10096
$this->server->on('connection', function ($conn) use ($mock) {
10197
$conn->on('data', $mock);
10298
});
103-
$this->loop->tick();
104-
$this->loop->tick();
99+
$this->tick();
100+
$this->tick();
105101
}
106102

107103
public function testLoopWillEndWhenServerIsClosed()
@@ -184,8 +180,8 @@ public function testConnectionDoesNotEndWhenClientDoesNotClose()
184180
$this->server->on('connection', function ($conn) use ($mock) {
185181
$conn->on('end', $mock);
186182
});
187-
$this->loop->tick();
188-
$this->loop->tick();
183+
$this->tick();
184+
$this->tick();
189185
}
190186

191187
/**
@@ -202,8 +198,8 @@ public function testConnectionDoesEndWhenClientCloses()
202198
$this->server->on('connection', function ($conn) use ($mock) {
203199
$conn->on('end', $mock);
204200
});
205-
$this->loop->tick();
206-
$this->loop->tick();
201+
$this->tick();
202+
$this->tick();
207203
}
208204

209205
public function testCtorAddsResourceToLoop()
@@ -304,4 +300,9 @@ private function getRandomSocketUri()
304300
{
305301
return "unix://" . sys_get_temp_dir() . DIRECTORY_SEPARATOR . uniqid(rand(), true) . '.sock';
306302
}
303+
304+
private function tick()
305+
{
306+
Block\sleep(0, $this->loop);
307+
}
307308
}

0 commit comments

Comments
 (0)