public function test_send_headers_while_headers_already_sent() { if (!function_exists('xdebug_get_headers')) { throw new Exception('Test skipped, missing required function xdebug_get_headers.'); } $builder = new HttpResponseBuilder(); $response = new HttpResponse(); $count = count(xdebug_get_headers()); // headers already sent $this->assertTrue(headers_sent()); $response->getHeaders()->set('bar', 'foo'); $builder->sendHeader('yolo'); $builder->sendHeaders($response); $this->assertTrue(count(xdebug_get_headers()) == $count); }
public function test_to_array() { $response = new HttpResponse(HttpStatusCode::GONE, 'foo', new HttpHeaders(['foo' => 'bar'])); $this->assertEquals(['protocol' => $response->getProtocol(), 'version' => $response->getProtocolVersion(), 'statusCode' => $response->getStatusCode(), 'statusCodeText' => $response->getStatusText(), 'headers' => $response->getHeaders()->toArray(), 'content' => $response->getContent()], $response->toArray()); }
<?php use Weew\Http\Cookie; use Weew\Http\HttpResponse; use Weew\Http\HttpStatusCode; use Weew\HttpBlueprint\BlueprintProxy; require __DIR__ . '/../../../vendor/autoload.php'; $proxy = new BlueprintProxy(); $proxy->getRouter()->get('/', new HttpResponse(HttpStatusCode::OK, 'bar'))->post('post', function () { $response = new HttpResponse(HttpStatusCode::BAD_REQUEST, array_get($_POST, 'value')); return $response; })->get('headers', function () { $response = new HttpResponse(); $response->getHeaders()->set('header', array_get($_SERVER, 'HTTP_HEADER')); $response->getHeaders()->set('yolo', 'swag'); $response->getHeaders()->add('foo', 'foo'); $response->getHeaders()->add('foo', 'bar'); return $response; })->get('cookies', function () { $response = new HttpResponse(); $response->getCookies()->add(new Cookie('foo', array_get($_COOKIE, 'foo'))); $response->getCookies()->add(new Cookie('bar', array_get($_COOKIE, 'bar'))); $response->getCookies()->add(new Cookie('yolo', 'swag')); return $response; }); $proxy->sendResponse();