forked from slimphp/Slim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ContentLengthMiddlewareTest.php
45 lines (39 loc) · 1.36 KB
/
ContentLengthMiddlewareTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
/**
* Slim Framework (https://slimframework.com)
*
* @link https://github.com/slimphp/Slim
* @copyright Copyright (c) 2011-2018 Josh Lockhart
* @license https://github.com/slimphp/Slim/blob/4.x/LICENSE.md (MIT License)
*/
namespace Slim\Tests\Middleware;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Slim\Http\Body;
use Slim\Http\Headers;
use Slim\Http\Request;
use Slim\Http\Response;
use Slim\Http\Uri;
use Slim\Middleware\ContentLengthMiddleware;
class ContentLengthMiddlewareTest extends TestCase
{
public function testAddsContentLenght()
{
$mw = new ContentLengthMiddleware();
$uri = Uri::createFromString('https://example.com:443/foo/bar?abc=123');
$headers = new Headers();
$cookies = [];
$serverParams = [];
$body = new Body(fopen('php://temp', 'r+'));
$request = new Request('GET', $uri, $headers, $cookies, $serverParams, $body);
$response = new Response();
$next = function (ServerRequestInterface $req, ResponseInterface $res) {
$body = $res->getBody();
$body->write('Body');
return $res->withBody($body);
};
$newResponse = $mw($request, $response, $next);
$this->assertEquals(4, $newResponse->getHeaderLine('Content-Length'));
}
}