Skip to content

Commit 2e23860

Browse files
committed
Initial skeleton
1 parent c49163a commit 2e23860

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

tests/FactoryTest.php

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
3+
use React\Promise\When;
4+
5+
use React\Promise\PromiseInterface;
6+
7+
require __DIR__.'/../vendor/autoload.php';
8+
9+
class FactoryTest extends PHPUnit_Framework_TestCase
10+
{
11+
private $factory;
12+
13+
public function testClientSuccess()
14+
{
15+
$loop = React\EventLoop\Factory::create();
16+
$factory = new Datagram\Factory($loop, $this->createResolverMock());
17+
18+
$promise = $factory->createClient('127.0.0.1', 12345);
19+
$this->assertInstanceOf('React\Promise\PromiseInterface', $promise);
20+
21+
$capturedClient = null;
22+
$promise->then(function ($client) use (&$capturedClient, $loop) {
23+
$capturedClient = $client;
24+
$loop->stop();
25+
}, $this->expectCallableNever());
26+
27+
// future-turn resolutions are not enforced, so the client MAY be known here already
28+
if ($capturedClient === null) {
29+
$loop->run();
30+
}
31+
32+
$this->assertInstanceOf('Datagram\Client', $capturedClient);
33+
34+
$capturedClient->close();
35+
}
36+
37+
protected function expectCallableOnce()
38+
{
39+
$mock = $this->createCallableMock();
40+
$mock
41+
->expects($this->once())
42+
->method('__invoke');
43+
44+
return $mock;
45+
}
46+
47+
protected function expectCallableNever()
48+
{
49+
$mock = $this->createCallableMock();
50+
$mock
51+
->expects($this->never())
52+
->method('__invoke');
53+
54+
return $mock;
55+
}
56+
57+
protected function createCallableMock()
58+
{
59+
return $this->getMock('React\Tests\Socket\Stub\CallableStub');
60+
}
61+
62+
private function createResolverMock()
63+
{
64+
return $this->getMockBuilder('React\Dns\Resolver\Resolver')
65+
->disableOriginalConstructor()
66+
->getMock();
67+
}
68+
}

0 commit comments

Comments
 (0)