forked from reactphp/datagram
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFactoryTest.php
68 lines (49 loc) · 1.92 KB
/
FactoryTest.php
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
<?php
use React\Datagram\Socket;
use React\Promise\When;
use React\Promise\PromiseInterface;
class FactoryTest extends TestCase
{
private $factory;
public function setUp()
{
$this->loop = React\EventLoop\Factory::create();
$this->factory = new React\Datagram\Factory($this->loop, $this->createResolverMock());
}
public function testCreateClient()
{
$promise = $this->factory->createClient('127.0.0.1:12345');
$capturedClient = $this->getValueFromResolvedPromise($promise);
$this->assertInstanceOf('React\Datagram\Socket', $capturedClient);
$capturedClient->close();
}
public function testCreateClientLocalhost()
{
$promise = $this->factory->createClient('localhost:12345');
$capturedClient = $this->getValueFromResolvedPromise($promise);
$this->assertInstanceOf('React\Datagram\Socket', $capturedClient);
$capturedClient->close();
}
public function testCreateClientIpv6()
{
$promise = $this->factory->createClient('[::1]:12345');
$capturedClient = $this->getValueFromResolvedPromise($promise);
$this->assertInstanceOf('React\Datagram\Socket', $capturedClient);
$capturedClient->close();
}
public function testCreateServer()
{
$promise = $this->factory->createServer('127.0.0.1:12345');
$capturedServer = $this->getValueFromResolvedPromise($promise);
$this->assertInstanceOf('React\Datagram\Socket', $capturedServer);
$capturedServer->close();
}
public function testCreateServerRandomPort()
{
$promise = $this->factory->createServer('127.0.0.1:0');
$capturedServer = $this->getValueFromResolvedPromise($promise);
$this->assertInstanceOf('React\Datagram\Socket', $capturedServer);
$this->assertNotEquals('127.0.0.1:0', $capturedServer->getLocalAddress());
$capturedServer->close();
}
}