Example #1
0
<?php

declare (strict_types=1);
use Kahlan\Plugin\Monkey;
use ochenta\ServerRequest;
describe('ServerRequest', function () {
    describe('->__construct', function () {
        it('assigns method from REQUEST_METHOD', function () {
            expect((new ServerRequest(['REQUEST_METHOD' => 'HEAD']))->getMethod())->toBe('HEAD');
        });
        it('assigns uri from REQUEST_URI', function () {
            $req = new ServerRequest(['REQUEST_URI' => 'http://*****:*****@example.com/path']);
            expect($req->getTarget())->toBe('/path');
            expect($req->getHeaders()['HOST'])->toBe(['example.com']);
        });
        it('assigns query as query parameters', function () {
            $req = new ServerRequest(NULL, ['foo' => 'bar']);
            expect($req->getQuery())->toBeA('array')->toContainKey('foo');
            expect($req->getQuery()['foo'])->toBe('bar');
        });
        it('assigns query from query string', function () {
            $req = new ServerRequest(['REQUEST_URI' => '/path?foo=bar'], []);
            expect($req->getQuery())->toBeA('array')->toContainKey('foo');
            expect($req->getQuery()['foo'])->toBe('bar');
        });
        it('assigns xargs as form parameters', function () {
            $req = new ServerRequest(NULL, NULL, ['foo' => 'bar']);
            expect($req->getParsedBody())->toBeA('array')->toContainKey('foo');
            expect($req->getParsedBody()['foo'])->toBe('bar');
        });
        it('assigns content headers from server', function () {