Skip to content
Snippets Groups Projects
Verified Commit 58211d35 authored by Thomas Flori's avatar Thomas Flori
Browse files

use a wrapper class to be able to test send functionality

parent a40b9681
No related branches found
No related tags found
No related merge requests found
<?php
namespace Tal;
/**
* Class Server
*
* This class is a stupid wrapper for php functions for testing.
*
* @package Tal
* @author Thomas Flori <thflori@gmail.com>
* @codeCoverageIgnore trivial
*/
class Server
{
/**
* Send a raw HTTP header
*
* @link http://php.net/manual/en/function.header.php
* @param string $string The header string
* @param bool $replace
* @param int $responseCode
* @return void
*/
public function header($string, $replace = true, $responseCode = null)
{
header($string, $replace, $responseCode);
}
/**
* Echos the given $string
*
* @param $string
* @return void
*/
public function echo($string)
{
echo($string);
}
}
......@@ -17,16 +17,19 @@ class ServerResponse extends Response implements ServerResponseInterface
/**
* Sends this response to the client.
*
* @param int $bufferSize
* @param Server|null $server
* @return static
*/
public function send(int $bufferSize = 8192)
public function send(int $bufferSize = 8192, Server $server = null)
{
$server = $server ?? new Server();
foreach ($this->getHeaders() as $name => $values) {
if (strtolower($name) !== 'set-cookie') {
header(sprintf('%s: %s', $name, implode(',', $values)), false);
$server->header(sprintf('%s: %s', $name, implode(',', $values)), false);
} else {
foreach ($values as $value) {
header(sprintf('%s: %s', $name, $value), false);
$server->header(sprintf('%s: %s', $name, $value), false);
}
}
}
......@@ -37,14 +40,14 @@ class ServerResponse extends Response implements ServerResponseInterface
$this->getStatusCode(),
$this->getReasonPhrase()
);
header($http_line, true, $this->getStatusCode());
$server->header($http_line, true, $this->getStatusCode());
$stream = $this->getBody();
if ($stream->isSeekable()) {
$stream->rewind();
}
while (!$stream->eof()) {
echo $stream->read($bufferSize);
$server->echo($stream->read($bufferSize));
}
return $this;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment