Skip to content

Commit f30223e

Browse files
committed
Additional tests for 100% coverage of Factory
1 parent 2f69231 commit f30223e

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

tests/FactoryTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use React\Datagram\Socket;
44
use React\Datagram\Factory;
55
use Clue\React\Block;
6+
use React\Promise;
67

78
class FactoryTest extends TestCase
89
{
@@ -69,6 +70,38 @@ public function testCreateServerRandomPort()
6970
$capturedServer->close();
7071
}
7172

73+
public function testCreateClientWithIpWillNotUseResolver()
74+
{
75+
$this->resolver->expects($this->never())->method('resolve');
76+
77+
$client = Block\await($this->factory->createClient('127.0.0.1:0'), $this->loop);
78+
$client->close();
79+
}
80+
81+
public function testCreateClientWithHostnameWillUseResolver()
82+
{
83+
$this->resolver->expects($this->once())->method('resolve')->with('example.com')->willReturn(Promise\resolve('127.0.0.1'));
84+
85+
$client = Block\await($this->factory->createClient('example.com:0'), $this->loop);
86+
$client->close();
87+
}
88+
89+
public function testCreateClientWithHostnameWillRejectIfResolverRejects()
90+
{
91+
$this->resolver->expects($this->once())->method('resolve')->with('example.com')->willReturn(Promise\reject(new \RuntimeException('test')));
92+
93+
$this->setExpectedException('RuntimeException');
94+
Block\await($this->factory->createClient('example.com:0'), $this->loop);
95+
}
96+
97+
public function testCreateClientWithHostnameWillRejectIfNoResolverIsGiven()
98+
{
99+
$this->factory = new Factory($this->loop);
100+
101+
$this->setExpectedException('Exception');
102+
Block\await($this->factory->createClient('example.com:0'), $this->loop);
103+
}
104+
72105
/**
73106
* @expectedException Exception
74107
* @expectedExceptionMessage Unable to create client socket

0 commit comments

Comments
 (0)