Add named constructor on JsonResponse
To make easier construction with raw json
This commit is contained in:
parent
64ace101fb
commit
6d5a65dd8b
@ -58,6 +58,14 @@ class JsonResponse extends Response
|
||||
return new static($data, $status, $headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make easier the creation of JsonResponse from raw json.
|
||||
*/
|
||||
public static function fromJsonString($data = null, $status = 200, $headers = array())
|
||||
{
|
||||
return new static($data, $status, $headers, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the JSONP callback.
|
||||
*
|
||||
|
@ -198,6 +198,12 @@ class JsonResponseTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals('{"0":{"0":1,"1":2,"2":3}}', $response->getContent());
|
||||
}
|
||||
|
||||
public function testItAcceptsJsonAsString()
|
||||
{
|
||||
$response = JsonResponse::fromJsonString('{"foo":"bar"}');
|
||||
$this->assertSame('{"foo":"bar"}', $response->getContent());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
|
Reference in New Issue
Block a user