* @license http://www.apache.org/licenses/LICENSE-2.0
* @link http://phpsx.org
*/
class SenderTest extends SenderTestCase
{
public function testSend()
{
$response = new Response();
$response->setBody(new StringStream('foobar'));
$sender = new Sender();
$actual = $this->captureOutput($sender, $response);
$this->assertEquals('foobar', $actual);
}
public function testSendHeaders()
{
$response = new Response();
$response->setHeader('Content-Type', 'application/xml');
$response->setHeader('X-Some-Header', 'foobar');
$response->setBody(new StringStream(''));
$sender = $this->getMockBuilder(Sender::class)
->setMethods(array('shouldSendHeader', 'sendHeader'))
->getMock();
$sender->expects($this->once())
->method('shouldSendHeader')
->will($this->returnValue(true));
$sender->expects($this->at(1))
->method('sendHeader')
->with($this->identicalTo('HTTP/1.1 200 OK'));
$sender->expects($this->at(2))
->method('sendHeader')
->with($this->identicalTo('content-type: application/xml'));
$sender->expects($this->at(3))
->method('sendHeader')
->with($this->identicalTo('x-some-header: foobar'));
$actual = $this->captureOutput($sender, $response);
$this->assertEquals('', $actual);
}
/**
* If we have an location header we only send the location header and no
* other content
*/
public function testSendHeaderLocation()
{
$response = new Response();
$response->setHeader('Content-Type', 'application/xml');
$response->setHeader('Location', 'http://localhost.com');
$response->setBody(new StringStream(''));
$sender = $this->getMockBuilder(Sender::class)
->setMethods(array('shouldSendHeader', 'sendHeader'))
->getMock();
$sender->expects($this->once())
->method('shouldSendHeader')
->will($this->returnValue(true));
$sender->expects($this->at(1))
->method('sendHeader')
->with($this->identicalTo('HTTP/1.1 200 OK'));
$sender->expects($this->at(2))
->method('sendHeader')
->with($this->identicalTo('content-type: application/xml'));
$sender->expects($this->at(3))
->method('sendHeader')
->with($this->identicalTo('location: http://localhost.com'));
$actual = $this->captureOutput($sender, $response);
$this->assertEquals('', $actual);
}
public function testSendBody()
{
$response = new Response();
$response->setBody(new StringStream('foobarfoobarfoobarfoobar'));
$sender = $this->getMockBuilder(Sender::class)
->setMethods(array('shouldSendHeader', 'sendHeader'))
->getMock();
$sender->expects($this->once())
->method('shouldSendHeader')
->will($this->returnValue(true));
$actual = $this->captureOutput($sender, $response);
$this->assertEquals('foobarfoobarfoobarfoobar', $actual);
}
public function testSendBodyCopy()
{
$fp = fopen('php://temp', 'r+');
fwrite($fp, 'foobarfoobarfoobarfoobar');
$response = new Response();
$response->setBody(new Stream($fp));
$sender = $this->getMockBuilder(Sender::class)
->setMethods(array('shouldSendHeader', 'sendHeader'))
->getMock();
$sender->expects($this->once())
->method('shouldSendHeader')
->will($this->returnValue(true));
$actual = $this->captureOutput($sender, $response);
$this->assertEquals('foobarfoobarfoobarfoobar', $actual);
}
public function testEmpyBodyStatusCode()
{
$emptyCodes = array(100, 101, 204, 304);
foreach ($emptyCodes as $statusCode) {
$response = new Response($statusCode);
$response->setBody(new StringStream('foobar'));
$sender = $this->getMockBuilder(Sender::class)
->setMethods(array('shouldSendHeader', 'sendHeader'))
->getMock();
$sender->expects($this->once())
->method('shouldSendHeader')
->will($this->returnValue(true));
$actual = $this->captureOutput($sender, $response);
$this->assertEmpty($actual);
}
}
public function testSendStatusCode()
{
$response = new Response(404);
$response->setBody(new StringStream('foobar'));
$sender = $this->getMockBuilder(Sender::class)
->setMethods(array('shouldSendHeader', 'sendHeader'))
->getMock();
$sender->expects($this->once())
->method('shouldSendHeader')
->will($this->returnValue(true));
$sender->expects($this->at(1))
->method('sendHeader')
->with($this->identicalTo('HTTP/1.1 404 Not Found'));
$actual = $this->captureOutput($sender, $response);
$this->assertEquals('foobar', $actual);
}
}
__halt_compiler();----SIGNATURE:----e+I3+GLGowW7qyU2cI2afzLxB92Vd62Lsm/oHc/98HvhyLGlVkE3U5+l6t7TgLQytgKUy0hpBav9SEnaCO54oePK/gueFmJVBA+DmG5vMcQRTDHzuIlBP02klyWCtUZp+CRH8zltX5dNUqeLKAkehcE+ZRlGC8AT4H528wsWyvLyBOEGWT2zbaYepIB/0Jt3q/vqHiQ3L0s49RLvCCAUqiiqE9wEBPsIZ2fqfMP0DbVghNWab8gaXmQ8wgamKQa0026GOMMpXIJRVPeAv5uvw6FyurdPkUcGHtmYSheBeKu6Q9VRZlbdJJDPo1lxEqt2tLS+4AS7E5XsjBehqIRqoB/e8jrPF9sU6nmlLYK8iYXLzYg4yvdxZGX7yKx5pZYvRMLZWF4gyKwzXWCtK11DHUBYG8hACUc2j5qH8QiL2qNhHeK4tWa6RGDug5GaqbnE9qUioUZ4kUW5BOyeEdwIzrn7kXlzWbFglH3iWG/4RDrUiCXDh/eExDnzFQRiJ10a2VArbYqSRhVmRz0Fa5iH3bq4jZQA266jHBkafGvDS/bPI4s2UMiG8t0lCqqmlTpFKUUB6UbWdD2IRt0fz9J8m0d7redIJAvSnqWLpLhhNGsKZ/DsIDDCkCK7ElV5hl9gQ4itFuLXVoiZ94qZpFgF+nydY0uZkQ0QAevNABGw1qg=----ATTACHMENT:----NDAzNzQyNDAxOTUzNDIzMyAzODE4NDc0NjAyNTIzNDExIDIxOTUxMzA0MTQ1Mjg5OA==