4
4
5
5
use Clue \React \Block ;
6
6
use Psr \Http \Message \ResponseInterface ;
7
- use React \EventLoop \Factory ;
7
+ use React \EventLoop \Loop ;
8
8
use React \Http \Client \Client ;
9
9
use React \Promise \Deferred ;
10
10
use React \Promise \Stream ;
@@ -37,36 +37,32 @@ class FunctionalIntegrationTest extends TestCase
37
37
38
38
public function testRequestToLocalhostEmitsSingleRemoteConnection ()
39
39
{
40
- $ loop = Factory::create ();
41
-
42
- $ socket = new SocketServer ('127.0.0.1:0 ' , array (), $ loop );
40
+ $ socket = new SocketServer ('127.0.0.1:0 ' );
43
41
$ socket ->on ('connection ' , $ this ->expectCallableOnce ());
44
42
$ socket ->on ('connection ' , function (ConnectionInterface $ conn ) use ($ socket ) {
45
43
$ conn ->end ("HTTP/1.1 200 OK \r\n\r\nOk " );
46
44
$ socket ->close ();
47
45
});
48
46
$ port = parse_url ($ socket ->getAddress (), PHP_URL_PORT );
49
47
50
- $ client = new Client ($ loop );
48
+ $ client = new Client (Loop:: get () );
51
49
$ request = $ client ->request ('GET ' , 'http://localhost: ' . $ port );
52
50
53
51
$ promise = Stream \first ($ request , 'close ' );
54
52
$ request ->end ();
55
53
56
- Block \await ($ promise , $ loop , self ::TIMEOUT_LOCAL );
54
+ Block \await ($ promise , null , self ::TIMEOUT_LOCAL );
57
55
}
58
56
59
57
public function testRequestLegacyHttpServerWithOnlyLineFeedReturnsSuccessfulResponse ()
60
58
{
61
- $ loop = Factory::create ();
62
-
63
- $ socket = new SocketServer ('127.0.0.1:0 ' , array (), $ loop );
59
+ $ socket = new SocketServer ('127.0.0.1:0 ' );
64
60
$ socket ->on ('connection ' , function (ConnectionInterface $ conn ) use ($ socket ) {
65
61
$ conn ->end ("HTTP/1.0 200 OK \n\nbody " );
66
62
$ socket ->close ();
67
63
});
68
64
69
- $ client = new Client ($ loop );
65
+ $ client = new Client (Loop:: get () );
70
66
$ request = $ client ->request ('GET ' , str_replace ('tcp: ' , 'http: ' , $ socket ->getAddress ()));
71
67
72
68
$ once = $ this ->expectCallableOnceWith ('body ' );
@@ -77,7 +73,7 @@ public function testRequestLegacyHttpServerWithOnlyLineFeedReturnsSuccessfulResp
77
73
$ promise = Stream \first ($ request , 'close ' );
78
74
$ request ->end ();
79
75
80
- Block \await ($ promise , $ loop , self ::TIMEOUT_LOCAL );
76
+ Block \await ($ promise , null , self ::TIMEOUT_LOCAL );
81
77
}
82
78
83
79
/** @group internet */
@@ -86,8 +82,7 @@ public function testSuccessfulResponseEmitsEnd()
86
82
// max_nesting_level was set to 100 for PHP Versions < 5.4 which resulted in failing test for legacy PHP
87
83
ini_set ('xdebug.max_nesting_level ' , 256 );
88
84
89
- $ loop = Factory::create ();
90
- $ client = new Client ($ loop );
85
+ $ client = new Client (Loop::get ());
91
86
92
87
$ request = $ client ->request ('GET ' , 'http://www.google.com/ ' );
93
88
@@ -99,7 +94,7 @@ public function testSuccessfulResponseEmitsEnd()
99
94
$ promise = Stream \first ($ request , 'close ' );
100
95
$ request ->end ();
101
96
102
- Block \await ($ promise , $ loop , self ::TIMEOUT_REMOTE );
97
+ Block \await ($ promise , null , self ::TIMEOUT_REMOTE );
103
98
}
104
99
105
100
/** @group internet */
@@ -112,8 +107,7 @@ public function testPostDataReturnsData()
112
107
// max_nesting_level was set to 100 for PHP Versions < 5.4 which resulted in failing test for legacy PHP
113
108
ini_set ('xdebug.max_nesting_level ' , 256 );
114
109
115
- $ loop = Factory::create ();
116
- $ client = new Client ($ loop );
110
+ $ client = new Client (Loop::get ());
117
111
118
112
$ data = str_repeat ('. ' , 33000 );
119
113
$ request = $ client ->request ('POST ' , 'https:// ' . (mt_rand (0 , 1 ) === 0 ? 'eu. ' : '' ) . 'httpbin.org/post ' , array ('Content-Length ' => strlen ($ data )));
@@ -128,7 +122,7 @@ public function testPostDataReturnsData()
128
122
129
123
$ request ->end ($ data );
130
124
131
- $ buffer = Block \await ($ deferred ->promise (), $ loop , self ::TIMEOUT_REMOTE );
125
+ $ buffer = Block \await ($ deferred ->promise (), null , self ::TIMEOUT_REMOTE );
132
126
133
127
$ this ->assertNotEquals ('' , $ buffer );
134
128
@@ -145,8 +139,7 @@ public function testPostJsonReturnsData()
145
139
$ this ->markTestSkipped ('Not supported on HHVM ' );
146
140
}
147
141
148
- $ loop = Factory::create ();
149
- $ client = new Client ($ loop );
142
+ $ client = new Client (Loop::get ());
150
143
151
144
$ data = json_encode (array ('numbers ' => range (1 , 50 )));
152
145
$ request = $ client ->request ('POST ' , 'https://httpbin.org/post ' , array ('Content-Length ' => strlen ($ data ), 'Content-Type ' => 'application/json ' ));
@@ -161,7 +154,7 @@ public function testPostJsonReturnsData()
161
154
162
155
$ request ->end ($ data );
163
156
164
- $ buffer = Block \await ($ deferred ->promise (), $ loop , self ::TIMEOUT_REMOTE );
157
+ $ buffer = Block \await ($ deferred ->promise (), null , self ::TIMEOUT_REMOTE );
165
158
166
159
$ this ->assertNotEquals ('' , $ buffer );
167
160
@@ -176,8 +169,7 @@ public function testCancelPendingConnectionEmitsClose()
176
169
// max_nesting_level was set to 100 for PHP Versions < 5.4 which resulted in failing test for legacy PHP
177
170
ini_set ('xdebug.max_nesting_level ' , 256 );
178
171
179
- $ loop = Factory::create ();
180
- $ client = new Client ($ loop );
172
+ $ client = new Client (Loop::get ());
181
173
182
174
$ request = $ client ->request ('GET ' , 'http://www.google.com/ ' );
183
175
$ request ->on ('error ' , $ this ->expectCallableNever ());
0 commit comments