merged 2.0

This commit is contained in:
Fabien Potencier 2012-07-20 07:34:13 +02:00
commit 4bde2aac41
3 changed files with 48 additions and 6 deletions

View File

@ -379,7 +379,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.
*
* @return Response
*
@ -389,12 +392,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 $this;
}
if (false === $text) {
$this->statusText = '';
return $this;
}
$this->statusText = $text;
return $this;
}

View File

@ -367,6 +367,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);

View File

@ -51,12 +51,12 @@
definitions.
]]></xsd:documentation>
</xsd:annotation>
<xsd:sequence>
<xsd:choice minOccurs="0" maxOccurs="unbounded">
<xsd:element name="group-sequence-provider" type="group-sequence-provider" minOccurs="0" maxOccurs="1" />
<xsd:element name="constraint" type="constraint" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="property" type="property" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="getter" type="getter" minOccurs="0" maxOccurs="unbounded" />
</xsd:sequence>
</xsd:choice>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
@ -144,4 +144,4 @@
</xsd:choice>
<xsd:attribute name="key" type="xsd:string" use="optional" />
</xsd:complexType>
</xsd:schema>
</xsd:schema>