From ed8823c16852bac0aa46e004f4fc695f845e0617 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Thu, 19 Jul 2012 17:48:12 +0200 Subject: [PATCH 1/2] [HttpFoundation] Allow setting an unknown status code without specifying a text --- .../Component/HttpFoundation/Response.php | 21 ++++++++++++--- .../Component/HttpFoundation/ResponseTest.php | 27 +++++++++++++++++++ 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/HttpFoundation/Response.php b/src/Symfony/Component/HttpFoundation/Response.php index a82d40484e..bb729f7cbf 100644 --- a/src/Symfony/Component/HttpFoundation/Response.php +++ b/src/Symfony/Component/HttpFoundation/Response.php @@ -254,7 +254,10 @@ class Response * Sets the response status code. * * @param integer $code HTTP status code - * @param string $text HTTP status text + * @param mixed $text HTTP status text + * + * If the status text is null it will be automatically populated for the known + * status codes and left empty otherwise. * * @throws \InvalidArgumentException When the HTTP status code is not valid * @@ -262,12 +265,24 @@ class Response */ public function setStatusCode($code, $text = null) { - $this->statusCode = (int) $code; + $this->statusCode = $code = (int) $code; if ($this->isInvalid()) { throw new \InvalidArgumentException(sprintf('The HTTP status code "%s" is not valid.', $code)); } - $this->statusText = false === $text ? '' : (null === $text ? self::$statusTexts[$this->statusCode] : $text); + if (null === $text) { + $this->statusText = isset(self::$statusTexts[$code]) ? self::$statusTexts[$code] : ''; + + return; + } + + if (false === $text) { + $this->statusText = ''; + + return; + } + + $this->statusText = $text; } /** diff --git a/tests/Symfony/Tests/Component/HttpFoundation/ResponseTest.php b/tests/Symfony/Tests/Component/HttpFoundation/ResponseTest.php index 512d20f48f..a9acc7080c 100644 --- a/tests/Symfony/Tests/Component/HttpFoundation/ResponseTest.php +++ b/tests/Symfony/Tests/Component/HttpFoundation/ResponseTest.php @@ -323,6 +323,33 @@ class ResponseTest extends \PHPUnit_Framework_TestCase $this->assertFalse($response->isInvalid()); } + /** + * @dataProvider getStatusCodeFixtures + */ + public function testSetStatusCode($code, $text, $expectedText) + { + $response = new Response(); + + $response->setStatusCode($code, $text); + + $statusText = new \ReflectionProperty($response, 'statusText'); + $statusText->setAccessible(true); + + $this->assertEquals($expectedText, $statusText->getValue($response)); + } + + public function getStatusCodeFixtures() + { + return array( + array('200', null, 'OK'), + array('200', false, ''), + array('200', 'foo', 'foo'), + array('199', null, ''), + array('199', false, ''), + array('199', 'foo', 'foo') + ); + } + public function testIsInformational() { $response = new Response('', 100); From 16a980b937f02d3aefdcc48c2772fd1bf5abdabc Mon Sep 17 00:00:00 2001 From: Vincent Composieux Date: Thu, 19 Jul 2012 20:43:09 +0200 Subject: [PATCH 2/2] [Validator] Fix bug order for constraint, property, getter and group-sequence-provider in validation.xml --- .../dic/constraint-mapping/constraint-mapping-1.0.xsd | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Validator/Mapping/Loader/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd b/src/Symfony/Component/Validator/Mapping/Loader/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd index 61232da570..c9acb28425 100644 --- a/src/Symfony/Component/Validator/Mapping/Loader/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd +++ b/src/Symfony/Component/Validator/Mapping/Loader/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd @@ -51,11 +51,11 @@ definitions. ]]> - + - + @@ -135,4 +135,4 @@ - \ No newline at end of file +