Skip to content

Commit

Permalink
Merge branch 'return-null-from-get-parsed-body' into 3.x
Browse files Browse the repository at this point in the history
Closes #1808
Fixes #1807
  • Loading branch information
akrabat committed Mar 10, 2016
2 parents 1d99b88 + 250bdbe commit 3e24602
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Slim/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -978,9 +978,10 @@ public function getParsedBody()
);
}
$this->bodyParsed = $parsed;
return $this->bodyParsed;
}

return $this->bodyParsed;
return null;
}

/**
Expand Down
22 changes: 20 additions & 2 deletions tests/Http/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@

class RequestTest extends \PHPUnit_Framework_TestCase
{
public function requestFactory()
public function requestFactory($envData = [])
{
$env = Environment::mock();
$env = Environment::mock($envData);

$uri = Uri::createFromString('https://example.com:443/foo/bar?abc=123');
$headers = Headers::createFromEnvironment($env);
Expand Down Expand Up @@ -836,6 +836,24 @@ public function testWithParsedBodyNull()
$this->assertNull($clone->getParsedBody());
}

public function testGetParsedBodyReturnsNullWhenThereIsNoBodyData()
{
$request = $this->requestFactory(['REQUEST_METHOD' => 'POST']);

$this->assertNull($request->getParsedBody());
}

public function testGetParsedBodyReturnsNullWhenThereIsNoMediaTypeParserRegistered()
{
$request = $this->requestFactory([
'REQUEST_METHOD' => 'POST',
'CONTENT_TYPE' => 'text/csv',
]);
$request->getBody()->write('foo,bar,baz');

$this->assertNull($request->getParsedBody());
}

/**
* @expectedException \InvalidArgumentException
*/
Expand Down

0 comments on commit 3e24602

Please sign in to comment.