Example #1
0
             }
             return fopen($filename, $mode);
         });
         $req = new ServerRequest(['CONTENT_TYPE' => 'text/plain', 'CONTENT_LENGTH' => 11]);
         expect($req->getBody())->toBeA('resource');
         expect(fread($req->getBody(), 11))->toBe('Hello World');
     });
     it('assigns the body to the given and is not overriden even if it has Content-Length', function () {
         Monkey::patch('fopen', function ($filename, $mode) {
             if ($filename === 'php://input') {
                 throw RuntimeExpection('This should never be called');
             }
             return fopen($filename, $mode);
         });
         $req = new ServerRequest(['CONTENT_TYPE' => 'text/plain', 'CONTENT_LENGTH' => 11], NULL, NULL, NULL, 'Hello World');
         expect($req->getBody())->toBeA('resource');
         expect(fread($req->getBody(), 11))->toBe('Hello World');
     });
 });
 describe('->getParsedBody', function () {
     it('returns parsed body when is application/x-www-form-urlencoded', function () {
         Monkey::patch('fopen', function ($filename, $mode) {
             if ($filename === 'php://input') {
                 $input = fopen('php://temp', 'r+');
                 fwrite($input, 'hello=world&foo=bar');
                 fseek($input, 0);
                 return $input;
             }
             return fopen($filename, $mode);
         });
         $req = new ServerRequest(['REQUEST_METHOD' => 'POST', 'CONTENT_TYPE' => 'application/x-www-form-urlencoded', 'CONTENT_LENGTH' => 17]);