@@ -10,36 +10,47 @@ class FactoryTest extends PHPUnit_Framework_TestCase
10
10
{
11
11
private $ factory ;
12
12
13
- public function testClientSuccess ()
13
+ public function setUp ()
14
14
{
15
- $ loop = React \EventLoop \Factory::create ();
16
- $ factory = new Datagram \Factory ($ loop , $ this ->createResolverMock ());
15
+ $ this ->loop = React \EventLoop \Factory::create ();
16
+ $ this ->factory = new Datagram \Factory ($ this ->loop , $ this ->createResolverMock ());
17
+ }
18
+
19
+ public function testCreateClient ()
20
+ {
21
+ $ promise = $ this ->factory ->createClient ('127.0.0.1 ' , 12345 );
22
+
23
+ $ capturedClient = $ this ->getValueFromResolvedPromise ($ promise );
24
+ $ this ->assertInstanceOf ('Datagram\Socket ' , $ capturedClient );
25
+
26
+ $ capturedClient ->close ();
27
+ }
17
28
18
- $ promise = $ factory ->createClient ('127.0.0.1 ' , 12345 );
29
+ protected function getValueFromResolvedPromise ($ promise )
30
+ {
19
31
$ this ->assertInstanceOf ('React\Promise\PromiseInterface ' , $ promise );
20
32
21
- $ capturedClient = null ;
22
- $ promise ->then (function ($ client ) use (&$ capturedClient , $ loop ) {
23
- $ capturedClient = $ client ;
33
+ $ loop = $ this ->loop ;
34
+ $ capturedValue = null ;
35
+ $ promise ->then (function ($ value ) use (&$ capturedValue , $ loop ) {
36
+ $ capturedValue = $ value ;
24
37
$ loop ->stop ();
25
38
}, $ this ->expectCallableNever ());
26
39
27
- // future-turn resolutions are not enforced, so the client MAY be known here already
28
- if ($ capturedClient === null ) {
40
+ // future-turn resolutions are not enforced, so the value MAY be known here already
41
+ if ($ capturedValue === null ) {
29
42
$ loop ->run ();
30
43
}
31
44
32
- $ this ->assertInstanceOf ('Datagram\Socket ' , $ capturedClient );
33
-
34
- $ capturedClient ->close ();
45
+ return $ capturedValue ;
35
46
}
36
47
37
48
protected function expectCallableOnce ()
38
49
{
39
50
$ mock = $ this ->createCallableMock ();
40
51
$ mock
41
- ->expects ($ this ->once ())
42
- ->method ('__invoke ' );
52
+ ->expects ($ this ->once ())
53
+ ->method ('__invoke ' );
43
54
44
55
return $ mock ;
45
56
}
@@ -48,8 +59,8 @@ protected function expectCallableNever()
48
59
{
49
60
$ mock = $ this ->createCallableMock ();
50
61
$ mock
51
- ->expects ($ this ->never ())
52
- ->method ('__invoke ' );
62
+ ->expects ($ this ->never ())
63
+ ->method ('__invoke ' );
53
64
54
65
return $ mock ;
55
66
}
0 commit comments