* @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:----s5xz0FYaxNMWg/k6GiXj4YP/iJWOERgOIhQmXC4TnK+X3M6QgBbAGPfnjMdYOQPWJ2Ses/RWTFZWY6mxmb1hGLYAhFJVpIn+FDuBPpzSVu9jnea/EnryurUExNiNwKkaENUSOHNe1cMbutpleOMzmupb5rYaKX1O71Gld0jT3ZHbYiS+DGQVNk6CmKIoWYtRv3afHx6Q/lQqSl1uaVT7EwhetEtNG7CZbpknFCLHsUQ/ia5Dx+VkkzZWjFCX4090RU3IFOVdAbWudG8tQmY1AX32deCw1FLJp6Mi0BoTp9OyTYBnjM1SPjz2vvLrD81GMIA5ueesFtFji25LMCQTth8L/TLCyhML9S65aAxji31a4tKHbh2KlycPIXCK6oX0UkZdKyay4ea6EkCEFdL4cAf8/xeKmEr0QMu7M8F3bHc1kRoKFC+VaOqc4UuCmlgOgIojSFRLtZGrPyOaObST1dUsFsOGG4hXy4La8J77v8eucBkMYsdBn23xuM9fajCGw9DOJnObtAmqVN0M1i4BoNC2Yq8qgVsw8VD1ucLNpcFKplzN1RuJoEPTOGHuwCOrSBbpZi/R82Bx9khW2uGIsrWRQ9hbLrpTuSIkpVa3f0FHfo//qh/GokBaNBU/HOl3lP5+yq14lyqKRqZcRfPihS4O3GbiJ1DMl8QY2K7/HfI=----ATTACHMENT:----NDQ0MDA0MDMxMzg3NzkwMCA1ODI1NDQ4MDc2MjY1MjggMzA3NTUzNjk5MDAyMjE3MQ==