Skip to content

Commit

Permalink
Add tests for filling parsedBody
Browse files Browse the repository at this point in the history
  • Loading branch information
Zegnat committed Jun 6, 2020
1 parent cd3b5e0 commit 6ee9d73
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions tests/ServerRequestCreatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -594,4 +594,57 @@ public function testFailingStreamFromFile()
);
$this->assertEquals($expected, $created);
}

public function testNoParsedBodyWithoutPOSTMethod()
{
$_POST = ['a' => 'b', 'c' => 'd'];
$instance = $this->creator->fromGlobals();
$this->assertNull($instance->getParsedBody());
}

public function testNoParsedBodyWithPOSTMethodWithoutContentType()
{
$_SERVER['REQUEST_METHOD'] = 'POST';
$_POST = ['a' => 'b', 'c' => 'd'];
$instance = $this->creator->fromGlobals();
$this->assertNull($instance->getParsedBody());
}

/**
* @dataProvider dataContentTypesThatTriggerParsedBody
*/
public function testParsedBodyWithPOSTMethodDifferentContentType($parsedBody, $contentType)
{
$_SERVER['REQUEST_METHOD'] = 'POST';
$_SERVER['HTTP_CONTENT_TYPE'] = $contentType;
$_POST = ['a' => 'b', 'c' => 'd'];
$instance = $this->creator->fromGlobals();
$this->assertSame($parsedBody ? $_POST : null, $instance->getParsedBody());
}

public function dataContentTypesThatTriggerParsedBody()
{
return [
// Acceptable values
'Standard HTML Form' => [
true, 'application/x-www-form-urlencoded',
],
'HTML Form with MIME body' => [
true, 'multipart/form-data',
],
'Standard HTML Form, mixed case MIME' => [
true, 'appLication/x-WWW-form-URLEncoded',
],
'Standard HTML Form, surrounding whitespace' => [
true, ' application/x-www-form-urlencoded ',
],
'Standard HTML Form, with flags' => [
true, 'application/x-www-form-urlencoded;charset=utf-8',
],
// Nonacceptable values
'JSON is not parsed by PHP' => [
false, 'application/json',
],
];
}
}

0 comments on commit 6ee9d73

Please sign in to comment.