Skip to content
This repository was archived by the owner on Jan 30, 2020. It is now read-only.

Commit 2970425

Browse files
committed
Rebase, fix tests, rewrite 100 continue
1 parent 08ebc6f commit 2970425

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+173
-193
lines changed

src/Response.php

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,15 @@ public static function fromString($string)
190190
$firstLine = array_shift($lines);
191191

192192
$response = new static();
193+
$response->parseStatusLine($firstLine);
193194

194-
try {
195-
$response->parseStatusLine($firstLine);
196-
} catch (RuntimeException $e) {
197-
array_shift($lines); // skip next empty line
198-
$firstLine = array_shift($lines); // and try again
199-
$response->parseStatusLine($firstLine);
195+
/**
196+
* @link https://tools.ietf.org/html/rfc7231#section-6.2.1
197+
*/
198+
if ($response->statusCode === static::STATUS_CODE_100) {
199+
$next = array_shift($lines); // take next line
200+
$next = !empty($next) ? $next : array_shift($lines); // take next or skip if empty
201+
$response->parseStatusLine($next);
200202
}
201203

202204
if (count($lines) === 0) {
@@ -255,11 +257,6 @@ protected function parseStatusLine($line)
255257
);
256258
}
257259

258-
// check for `continue` status
259-
if (static::STATUS_CODE_100 === (int)$matches['status']) {
260-
throw new Exception\RuntimeException('Continue status found.');
261-
}
262-
263260
$this->version = $matches['version'];
264261
$this->setStatusCode($matches['status']);
265262
$this->setReasonPhrase((isset($matches['reason']) ? $matches['reason'] : ''));

test/Client/CurlTest.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,7 @@ public function testConfigSetAsZendConfig()
105105
*/
106106
public function testSetConfigInvalidConfig($config)
107107
{
108-
$this->expectException(InvalidArgumentException::class);
109-
$this->expectExceptionMessage('Array or Traversable object expected');
108+
$this->setExpectedException(InvalidArgumentException::class, 'Array or Traversable object expected');
110109

111110
$this->_adapter->setOptions($config);
112111
}
@@ -129,8 +128,7 @@ public function testSettingInvalidCurlOption()
129128
];
130129
$this->client = new Client($this->client->getUri(true), $config);
131130

132-
$this->expectException(RuntimeException::class);
133-
$this->expectExceptionMessage('Unknown or erroreous cURL option');
131+
$this->setExpectedException(RuntimeException::class, 'Unknown or erroreous cURL option');
134132
$this->client->send();
135133
}
136134

@@ -176,9 +174,8 @@ public function testRedirectPostToGetWithCurlFollowLocationOptionLeadsToTimeout(
176174
$this->client->setParameterGet(['swallow' => 'african']);
177175
$this->client->setParameterPost(['Camelot' => 'A silly place']);
178176
$this->client->setMethod('POST');
179-
$this->expectException(RuntimeException::class);
180-
$this->expectExceptionMessage(
181-
'Error in cURL request: Operation timed out after 1000 milliseconds with 0 bytes received'
177+
$this->setExpectedException(
178+
RuntimeException::class, 'Error in cURL request: Operation timed out after 1000 milliseconds with 0 bytes received'
182179
);
183180
$this->client->send();
184181
}
@@ -239,15 +236,14 @@ public function testPutFileHandleWithHttpClient()
239236
public function testWritingAndNotConnectedWithCurlHandleThrowsException()
240237
{
241238
$adapter = new Adapter\Curl();
242-
$this->expectException(RuntimeException::class);
243-
$this->expectExceptionMessage('Trying to write but we are not connected');
239+
$this->setExpectedException(RuntimeException::class, 'Trying to write but we are not connected');
244240
$adapter->write('GET', 'someUri');
245241
}
246242

247243
public function testSetConfigIsNotArray()
248244
{
249245
$adapter = new Adapter\Curl();
250-
$this->expectException(InvalidArgumentException::class);
246+
$this->setExpectedException(InvalidArgumentException::class);
251247
$adapter->setOptions('foo');
252248
}
253249

test/Client/SocketTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,7 @@ public function testConfigSetAsZendConfig()
165165
*/
166166
public function testSetConfigInvalidConfig($config)
167167
{
168-
$this->expectException(InvalidArgumentException::class);
169-
$this->expectExceptionMessage('Array or Zend\Config object expected');
168+
$this->setExpectedException(InvalidArgumentException::class, 'Array or Zend\Config object expected');
170169

171170
$this->_adapter->setOptions($config);
172171
}
@@ -225,8 +224,10 @@ public function testSetNewStreamContextOptions()
225224
*/
226225
public function testSetInvalidContextOptions($invalid)
227226
{
228-
$this->expectException(InvalidArgumentException::class);
229-
$this->expectExceptionMessage('Expecting either a stream context resource or array');
227+
$this->setExpectedException(
228+
InvalidArgumentException::class,
229+
'Expecting either a stream context resource or array'
230+
);
230231

231232
$adapterClass = $this->config['adapter'];
232233
$adapter = new $adapterClass();

test/Client/StaticTest.php

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,10 @@ public function testGetHeader()
153153
*/
154154
public function testExceptUnsupportedAuthDynamic()
155155
{
156-
$this->expectException(InvalidArgumentException::class);
157-
$this->expectExceptionMessage('Invalid or not supported authentication type: \'SuperStrongAlgo\'');
156+
$this->setExpectedException(
157+
InvalidArgumentException::class,
158+
'Invalid or not supported authentication type: \'SuperStrongAlgo\''
159+
);
158160

159161
$this->_client->setAuth('shahar', '1234', 'SuperStrongAlgo');
160162
}
@@ -200,8 +202,10 @@ public function testUnsetCookies()
200202
*/
201203
public function testSetInvalidCookies()
202204
{
203-
$this->expectException(InvalidArgumentException::class);
204-
$this->expectExceptionMessage('Invalid parameter type passed as Cookie');
205+
$this->setExpectedException(
206+
InvalidArgumentException::class,
207+
'Invalid parameter type passed as Cookie'
208+
);
205209

206210
$this->_client->addCookie('cookie');
207211
}
@@ -259,8 +263,7 @@ public function testConfigSetAsZendConfig()
259263
*/
260264
public function testConfigSetInvalid($config)
261265
{
262-
$this->expectException(ClientException\InvalidArgumentException::class);
263-
$this->expectExceptionMessage('Config parameter is not valid');
266+
$this->setExpectedException(ClientException\InvalidArgumentException::class, 'Config parameter is not valid');
264267

265268
$this->_client->setOptions($config);
266269
}
@@ -345,8 +348,7 @@ public function testInvalidPostContentType()
345348
HTTPClient::class
346349
));
347350
}
348-
$this->expectException(RuntimeException::class);
349-
$this->expectExceptionMessage('Cannot handle content type \'x-foo/something-fake\' automatically');
351+
$this->setExpectedException(RuntimeException::class, 'Cannot handle content type \'x-foo/something-fake\' automatically');
350352

351353
$this->_client->setEncType('x-foo/something-fake');
352354
$this->_client->setParameterPost(['parameter' => 'value']);
@@ -366,8 +368,10 @@ public function testSocketErrorException()
366368
HTTPClient::class
367369
));
368370
}
369-
$this->expectException(ClientAdapterException\RuntimeException::class);
370-
$this->expectExceptionMessage('Unable to connect to 255.255.255.255:80');
371+
$this->setExpectedException(
372+
ClientAdapterException\RuntimeException::class,
373+
'Unable to connect to 255.255.255.255:80'
374+
);
371375

372376
// Try to connect to an invalid host
373377
$this->_client->setUri('http://255.255.255.255');
@@ -389,8 +393,7 @@ public function testSocketErrorException()
389393
*/
390394
public function testSettingInvalidMethodThrowsException($method)
391395
{
392-
$this->expectException(InvalidArgumentException::class);
393-
$this->expectExceptionMessage('Invalid HTTP method passed');
396+
$this->setExpectedException(InvalidArgumentException::class, 'Invalid HTTP method passed');
394397

395398
$this->_client->setMethod($method);
396399
}
@@ -522,8 +525,7 @@ public function testOpenTempStreamWithBogusFileClosesTheConnection()
522525
$client = new HTTPClient($url, $config);
523526
$client->setMethod('GET');
524527

525-
$this->expectException(RuntimeException::class);
526-
$this->expectExceptionMessage('Could not open temp file /path/to/bogus/file.ext');
528+
$this->setExpectedException(RuntimeException::class, 'Could not open temp file /path/to/bogus/file.ext');
527529
$client->send();
528530
}
529531

test/Client/TestAdapterTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ public function tearDown()
5050
*/
5151
public function testSetConfigThrowsOnInvalidConfig()
5252
{
53-
$this->expectException(InvalidArgumentException::class);
54-
$this->expectExceptionMessage('Array or Traversable object expected');
53+
$this->setExpectedException(InvalidArgumentException::class, 'Array or Traversable object expected');
5554

5655
$this->adapter->setOptions('foo');
5756
}

test/ClientTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ public function testIfNullValueCookiesThrowsException()
122122
{
123123
$client = new Client();
124124

125-
$this->expectException(HttpException\InvalidArgumentException::class);
125+
$this->setExpectedException(HttpException\InvalidArgumentException::class);
126+
126127
$client->addCookie('test', null);
127128
}
128129

@@ -217,13 +218,13 @@ public function testEncodeAuthHeaderWorksAsExpected()
217218

218219
public function testEncodeAuthHeaderThrowsExceptionWhenUsernameContainsSemiColon()
219220
{
220-
$this->expectException(ClientException\InvalidArgumentException::class);
221+
$this->setExpectedException(ClientException\InvalidArgumentException::class);
221222
Client::encodeAuthHeader('test:', 'test');
222223
}
223224

224225
public function testEncodeAuthHeaderThrowsExceptionWhenInvalidAuthTypeIsUsed()
225226
{
226-
$this->expectException(ClientException\InvalidArgumentException::class);
227+
$this->setExpectedException(ClientException\InvalidArgumentException::class);
227228
Client::encodeAuthHeader('test', 'test', 'test');
228229
}
229230

@@ -453,7 +454,7 @@ public function testHttpQueryParametersCastToString()
453454
{
454455
$client = new Client();
455456

456-
$adapter = $this->createMock(AdapterInterface::class);
457+
$adapter = $this->getMock(AdapterInterface::class);
457458

458459
$client->setAdapter($adapter);
459460

test/Header/AcceptCharsetTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function testWildcharCharset()
9494
*/
9595
public function testPreventsCRLFAttackViaFromString()
9696
{
97-
$this->expectException(InvalidArgumentException::class);
97+
$this->setExpectedException(InvalidArgumentException::class);
9898
AcceptCharset::fromString("Accept-Charset: iso-8859-5\r\n\r\nevilContent");
9999
}
100100

@@ -105,8 +105,7 @@ public function testPreventsCRLFAttackViaFromString()
105105
public function testPreventsCRLFAttackViaSetters()
106106
{
107107
$header = new AcceptCharset();
108-
$this->expectException(InvalidArgumentException::class);
109-
$this->expectExceptionMessage('valid type');
108+
$this->setExpectedException(InvalidArgumentException::class, 'valid type');
110109
$header->addCharset("\niso\r-8859-\r\n5");
111110
}
112111
}

test/Header/AcceptEncodingTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public function testWildcharEncoder()
9595
*/
9696
public function testPreventsCRLFAttackViaFromString()
9797
{
98-
$this->expectException(InvalidArgumentException::class);
98+
$this->setExpectedException(InvalidArgumentException::class);
9999
$header = AcceptEncoding::fromString("Accept-Encoding: compress\r\n\r\nevilContent");
100100
}
101101

@@ -106,8 +106,7 @@ public function testPreventsCRLFAttackViaFromString()
106106
public function testPreventsCRLFAttackViaSetters()
107107
{
108108
$header = new AcceptEncoding();
109-
$this->expectException(InvalidArgumentException::class);
110-
$this->expectExceptionMessage('valid type');
109+
$this->setExpectedException(InvalidArgumentException::class, 'valid type');
111110

112111
$header->addEncoding("\nc\rom\r\npress");
113112
}

test/Header/AcceptLanguageTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public function testWildcards()
111111
*/
112112
public function testPreventsCRLFAttackViaFromString()
113113
{
114-
$this->expectException(InvalidArgumentException::class);
114+
$this->setExpectedException(InvalidArgumentException::class);
115115
$header = AcceptLanguage::fromString("Accept-Language: da\r\n\r\nevilContent");
116116
}
117117

@@ -122,8 +122,7 @@ public function testPreventsCRLFAttackViaFromString()
122122
public function testPreventsCRLFAttackViaSetters()
123123
{
124124
$header = new AcceptLanguage();
125-
$this->expectException(InvalidArgumentException::class);
126-
$this->expectExceptionMessage('valid type');
125+
$this->setExpectedException(InvalidArgumentException::class, 'valid type');
127126

128127
$header->addLanguage("\nen\r-\r\nus");
129128
}

test/Header/AcceptRangesTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function testAcceptRangesToStringReturnsHeaderFormattedString()
5151
*/
5252
public function testPreventsCRLFAttackViaFromString()
5353
{
54-
$this->expectException(InvalidArgumentException::class);
54+
$this->setExpectedException(InvalidArgumentException::class);
5555
$header = AcceptRanges::fromString("Accept-Ranges: bytes;\r\n\r\nevilContent");
5656
}
5757

@@ -61,7 +61,7 @@ public function testPreventsCRLFAttackViaFromString()
6161
*/
6262
public function testPreventsCRLFAttackViaConstructor()
6363
{
64-
$this->expectException(InvalidArgumentException::class);
64+
$this->setExpectedException(InvalidArgumentException::class);
6565
$header = new AcceptRanges("bytes;\r\n\r\nevilContent");
6666
}
6767
}

0 commit comments

Comments
 (0)