The string representation of the Response is the same as the
one that will be sent to the client only if the prepare() method
has been called before.
public __toString ( ) : string | ||
Résultat | string | The Response as an HTTP string |
public function __toString() { $this->headers->set('Content-Length', strlen($this->getContent())); return parent::__toString(); }
public function testDefaultContentType() { $headerMock = $this->getMock('Symfony\\Component\\HttpFoundation\\ResponseHeaderBag', array('set')); $headerMock->expects($this->at(0))->method('set')->with('Content-Type', 'text/html; charset=UTF-8'); $headerMock->expects($this->at(1))->method('set')->with('Content-Type', 'text/html; charset=Foo'); $response = new Response(); $response->headers = $headerMock; // verify first set() $response->__toString(); $response->headers->remove('Content-Type'); $response->setCharset('Foo'); // verify second set() $response->__toString(); }
public function testContentTypeCharset() { $response = new Response(); $response->headers->set('Content-Type', 'text/css'); // force fixContentType() to be called $response->__toString(); $this->assertEquals('text/css; charset=UTF-8', $response->headers->get('Content-Type')); }