Skip to content

Commit 22308d1

Browse files
committed
fix guzzle test suite
1 parent 78af0f8 commit 22308d1

6 files changed

+75
-7
lines changed

src/RequestIntegrationTest.php

+17
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,28 @@ public function testMethod()
6565
$this->assertNotSameObject($this->request, $request);
6666
$this->assertEquals($this->request, $original, 'Request object MUST not be mutated');
6767
$this->assertEquals('POST', $request->getMethod());
68+
}
69+
70+
public function testMethodIsCaseSensitive()
71+
{
72+
if (isset($this->skippedTests[__FUNCTION__])) {
73+
$this->markTestSkipped($this->skippedTests[__FUNCTION__]);
74+
}
6875

6976
$request = $this->request->withMethod('head');
7077
$this->assertEquals('head', $request->getMethod());
7178
}
7279

80+
public function testMethodIsExtendable()
81+
{
82+
if (isset($this->skippedTests[__FUNCTION__])) {
83+
$this->markTestSkipped($this->skippedTests[__FUNCTION__]);
84+
}
85+
86+
$request = $this->request->withMethod('CUSTOM');
87+
$this->assertEquals('CUSTOM', $request->getMethod());
88+
}
89+
7390
/**
7491
* @dataProvider getInvalidMethods
7592
*/

src/ServerRequestIntegrationTest.php

+6-5
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,16 @@ public function validParsedBodyParams()
117117
*/
118118
public function testGetParsedBodyInvalid($value)
119119
{
120-
$this->expectException('\InvalidArgumentException');
121-
122120
if (isset($this->skippedTests[__FUNCTION__])) {
123121
$this->markTestSkipped($this->skippedTests[__FUNCTION__]);
124122
}
125123

126-
$new = $this->serverRequest->withParsedBody($value);
127-
$this->assertNull($this->serverRequest->getParsedBody(), 'withParsedBody MUST be immutable');
128-
$this->assertEquals($value, $new->getParsedBody());
124+
try {
125+
$this->serverRequest->withParsedBody($value);
126+
$this->fail('Should not be accepted');
127+
} catch (\InvalidArgumentException $e) {
128+
$this->assertNull($this->serverRequest->getParsedBody(), 'withParsedBody MUST be immutable');
129+
}
129130
}
130131

131132
public function invalidParsedBodyParams()

src/StreamIntegrationTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,12 @@ public function testRewind()
241241
*/
242242
public function testRewindNotSeekable()
243243
{
244-
$this->expectException('\RuntimeException');
245-
246244
if (isset($this->skippedTests[__FUNCTION__])) {
247245
$this->markTestSkipped($this->skippedTests[__FUNCTION__]);
248246
}
249247

248+
$this->expectException(\RuntimeException::class);
249+
250250
$url = 'https://raw.githubusercontent.com/php-http/multipart-stream-builder/master/tests/Resources/httplug.png';
251251
$resource = fopen($url, 'r');
252252
$stream = $this->createStream($resource);

tests/Guzzle/RequestTest.php

+14
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,22 @@
77

88
class RequestTest extends RequestIntegrationTest
99
{
10+
protected $skippedTests = [
11+
'testMethodIsCaseSensitive' => 'methods are uppercased for BC',
12+
];
13+
1014
public function createSubject()
1115
{
1216
return new Request('GET', '/');
1317
}
18+
19+
public function getInvalidHeaderArguments()
20+
{
21+
$testCases = parent::getInvalidHeaderArguments();
22+
23+
// Guzzle accepts false as value for BC
24+
unset($testCases[3]);
25+
26+
return $testCases;
27+
}
1428
}

tests/Guzzle/ResponseTest.php

+10
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,14 @@ public function createSubject()
1111
{
1212
return new Response();
1313
}
14+
15+
public function getInvalidHeaderArguments()
16+
{
17+
$testCases = parent::getInvalidHeaderArguments();
18+
19+
// Guzzle accepts false as value for BC
20+
unset($testCases[3]);
21+
22+
return $testCases;
23+
}
1424
}

tests/Guzzle/ServerRequestTest.php

+26
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,32 @@
77

88
class ServerRequestTest extends ServerRequestIntegrationTest
99
{
10+
/**
11+
* Guzzle accepts more types for parsed body.
12+
*
13+
* ServerRequestInterface::withParsedBody says
14+
* > The data IS NOT REQUIRED to come from $_POST, but MUST be the results of
15+
* > deserializing the request body content. Deserialization/parsing returns
16+
* > structured data, and, as such, this method ONLY accepts arrays or objects,
17+
* > or a null value if nothing was available to parse.
18+
* > As an example, if content negotiation determines that the request data
19+
* > is a JSON payload, this method could be used to create a request
20+
* > instance with the deserialized parameters.
21+
*
22+
* A JSON body payload can also be a json string, a json int etc. So withParsedBody would also need to accept that as well. Those two sentences contradict each other.
23+
* According to a slack discussion, this was based on rfc4627
24+
* > A JSON text is a serialized object or array.
25+
*
26+
* But that is outdated since since rfc7158 in 2013 which does not limit it to array or object anymore. See current https://tools.ietf.org/html/rfc8259
27+
*
28+
* > A JSON text is a serialized value. Note that certain previous
29+
* > specifications of JSON constrained a JSON text to be an object or an
30+
* > array.
31+
*/
32+
protected $skippedTests = [
33+
'testGetParsedBodyInvalid' => 'more types are accepted per rfc7158',
34+
];
35+
1036
public function createSubject()
1137
{
1238
return new ServerRequest('GET', '/', [], null, '1.1', $_SERVER);

0 commit comments

Comments
 (0)