[HttpFoundation] Add create method to Json & Redirect responses
This commit is contained in:
parent
1c86ad78ee
commit
ff13528ad0
@ -38,4 +38,12 @@ class JsonResponse extends Response
|
||||
array_merge(array('Content-Type' => 'application/json'), $headers)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public static function create($data = array(), $status = 200, $headers = array())
|
||||
{
|
||||
return new static($data, $status, $headers);
|
||||
}
|
||||
}
|
||||
|
@ -63,6 +63,14 @@ class RedirectResponse extends Response
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public static function create($url = '', $status = 302, $headers = array())
|
||||
{
|
||||
return new static($url, $status, $headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the target URL.
|
||||
*
|
||||
|
@ -79,4 +79,13 @@ class JsonResponseTest extends \PHPUnit_Framework_TestCase
|
||||
$response = new JsonResponse(array(), 200, $headers);
|
||||
$this->assertSame('application/vnd.acme.blog-v1+json', $response->headers->get('Content-Type'));
|
||||
}
|
||||
|
||||
public function testCreate()
|
||||
{
|
||||
$response = JsonResponse::create(array('foo' => 'bar'), 204);
|
||||
|
||||
$this->assertInstanceOf('Symfony\Component\HttpFoundation\JsonResponse', $response);
|
||||
$this->assertEquals('{"foo":"bar"}', $response->getContent());
|
||||
$this->assertEquals(204, $response->getStatusCode());
|
||||
}
|
||||
}
|
||||
|
@ -40,4 +40,11 @@ class RedirectResponseTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals('foo.bar', $response->getTargetUrl());
|
||||
}
|
||||
|
||||
public function testCreate()
|
||||
{
|
||||
$response = RedirectResponse::create('foo', 301);
|
||||
|
||||
$this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $response);
|
||||
$this->assertEquals(301, $response->getStatusCode());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user