Skip to content

Commit b7ef800

Browse files
committed
Test cleanup
1 parent fc531a2 commit b7ef800

File tree

2 files changed

+29
-79
lines changed

2 files changed

+29
-79
lines changed

tests/Client/RequestTest.php

Lines changed: 23 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -86,28 +86,30 @@ public function requestShouldBindToStreamEventsAndUseconnector()
8686
$request->handleData("\r\nbody");
8787
}
8888

89+
/**
90+
* @test
91+
*/
92+
public function requestShouldConnectViaTlsIfUrlUsesHttpsScheme()
93+
{
94+
$requestData = new RequestData('GET', 'https://www.example.com');
95+
$request = new Request($this->connector, $requestData);
96+
97+
$this->connector->expects($this->once())->method('connect')->with('tls://www.example.com:443')->willReturn(new Promise(function () { }));
98+
99+
$request->end();
100+
}
101+
89102
/** @test */
90103
public function requestShouldEmitErrorIfConnectionFails()
91104
{
92105
$requestData = new RequestData('GET', 'http://www.example.com');
93106
$request = new Request($this->connector, $requestData);
94107

95-
$this->rejectedConnectionMock();
96-
97-
$handler = $this->createCallableMock();
98-
$handler->expects($this->once())
99-
->method('__invoke')
100-
->with(
101-
$this->isInstanceOf('RuntimeException')
102-
);
103-
104-
$request->on('error', $handler);
108+
$this->connector->expects($this->once())->method('connect')->willReturn(\React\Promise\reject(new \RuntimeException()));
105109

106-
$handler = $this->createCallableMock();
107-
$handler->expects($this->once())
108-
->method('__invoke');
110+
$request->on('error', $this->expectCallableOnceWith($this->isInstanceOf('RuntimeException')));
109111

110-
$request->on('close', $handler);
112+
$request->on('close', $this->expectCallableOnce());
111113
$request->on('end', $this->expectCallableNever());
112114

113115
$request->end();
@@ -121,20 +123,9 @@ public function requestShouldEmitErrorIfConnectionClosesBeforeResponseIsParsed()
121123

122124
$this->successfulConnectionMock();
123125

124-
$handler = $this->createCallableMock();
125-
$handler->expects($this->once())
126-
->method('__invoke')
127-
->with(
128-
$this->isInstanceOf('RuntimeException')
129-
);
130-
131-
$request->on('error', $handler);
132-
133-
$handler = $this->createCallableMock();
134-
$handler->expects($this->once())
135-
->method('__invoke');
126+
$request->on('error', $this->expectCallableOnceWith($this->isInstanceOf('RuntimeException')));
136127

137-
$request->on('close', $handler);
128+
$request->on('close', $this->expectCallableOnce());
138129
$request->on('end', $this->expectCallableNever());
139130

140131
$request->end();
@@ -149,20 +140,9 @@ public function requestShouldEmitErrorIfConnectionEmitsError()
149140

150141
$this->successfulConnectionMock();
151142

152-
$handler = $this->createCallableMock();
153-
$handler->expects($this->once())
154-
->method('__invoke')
155-
->with(
156-
$this->isInstanceOf('Exception')
157-
);
158-
159-
$request->on('error', $handler);
143+
$request->on('error', $this->expectCallableOnceWith($this->isInstanceOf('Exception')));
160144

161-
$handler = $this->createCallableMock();
162-
$handler->expects($this->once())
163-
->method('__invoke');
164-
165-
$request->on('close', $handler);
145+
$request->on('close', $this->expectCallableOnce());
166146
$request->on('end', $this->expectCallableNever());
167147

168148
$request->end();
@@ -177,14 +157,7 @@ public function requestShouldEmitErrorIfRequestParserThrowsException()
177157

178158
$this->successfulConnectionMock();
179159

180-
$handler = $this->createCallableMock();
181-
$handler->expects($this->once())
182-
->method('__invoke')
183-
->with(
184-
$this->isInstanceOf('\InvalidArgumentException')
185-
);
186-
187-
$request->on('error', $handler);
160+
$request->on('error', $this->expectCallableOnceWith($this->isInstanceOf('InvalidArgumentException')));
188161

189162
$request->end();
190163
$request->handleData("\r\n\r\n");
@@ -198,14 +171,7 @@ public function requestShouldEmitErrorIfUrlIsInvalid()
198171
$requestData = new RequestData('GET', 'ftp://www.example.com');
199172
$request = new Request($this->connector, $requestData);
200173

201-
$handler = $this->createCallableMock();
202-
$handler->expects($this->once())
203-
->method('__invoke')
204-
->with(
205-
$this->isInstanceOf('\InvalidArgumentException')
206-
);
207-
208-
$request->on('error', $handler);
174+
$request->on('error', $this->expectCallableOnceWith($this->isInstanceOf('InvalidArgumentException')));
209175

210176
$this->connector->expects($this->never())
211177
->method('connect');
@@ -221,14 +187,7 @@ public function requestShouldEmitErrorIfUrlHasNoScheme()
221187
$requestData = new RequestData('GET', 'www.example.com');
222188
$request = new Request($this->connector, $requestData);
223189

224-
$handler = $this->createCallableMock();
225-
$handler->expects($this->once())
226-
->method('__invoke')
227-
->with(
228-
$this->isInstanceOf('\InvalidArgumentException')
229-
);
230-
231-
$request->on('error', $handler);
190+
$request->on('error', $this->expectCallableOnceWith($this->isInstanceOf('InvalidArgumentException')));
232191

233192
$this->connector->expects($this->never())
234193
->method('connect');
@@ -533,15 +492,6 @@ private function successfulAsyncConnectionMock()
533492
};
534493
}
535494

536-
private function rejectedConnectionMock()
537-
{
538-
$this->connector
539-
->expects($this->once())
540-
->method('connect')
541-
->with('www.example.com:80')
542-
->will($this->returnValue(new RejectedPromise(new \RuntimeException())));
543-
}
544-
545495
/** @test */
546496
public function multivalueHeader()
547497
{

tests/FunctionalServerTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,8 @@ public function testPlainHttpOnStandardPortWithoutHostHeaderReturnsUriWithNoPort
300300

301301
public function testSecureHttpsOnStandardPortReturnsUriWithNoPort()
302302
{
303-
if (!function_exists('stream_socket_enable_crypto')) {
304-
$this->markTestSkipped('Not supported on your platform (outdated HHVM?)');
303+
if (defined('HHVM_VERSION')) {
304+
$this->markTestSkipped('Not supported on HHVM');
305305
}
306306

307307
$loop = Factory::create();
@@ -339,8 +339,8 @@ public function testSecureHttpsOnStandardPortReturnsUriWithNoPort()
339339

340340
public function testSecureHttpsOnStandardPortWithoutHostHeaderUsesSocketUri()
341341
{
342-
if (!function_exists('stream_socket_enable_crypto')) {
343-
$this->markTestSkipped('Not supported on your platform (outdated HHVM?)');
342+
if (defined('HHVM_VERSION')) {
343+
$this->markTestSkipped('Not supported on HHVM');
344344
}
345345

346346
$loop = Factory::create();
@@ -408,8 +408,8 @@ public function testPlainHttpOnHttpsStandardPortReturnsUriWithPort()
408408

409409
public function testSecureHttpsOnHttpStandardPortReturnsUriWithPort()
410410
{
411-
if (!function_exists('stream_socket_enable_crypto')) {
412-
$this->markTestSkipped('Not supported on your platform (outdated HHVM?)');
411+
if (defined('HHVM_VERSION')) {
412+
$this->markTestSkipped('Not supported on HHVM');
413413
}
414414

415415
$loop = Factory::create();

0 commit comments

Comments
 (0)