1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
/* |
3
|
|
|
* This file is part of coisa/http. |
4
|
|
|
* |
5
|
|
|
* (c) Felipe Sayão Lobato Abreu <[email protected]> |
6
|
|
|
* |
7
|
|
|
* This source file is subject to the license that is bundled |
8
|
|
|
* with this source code in the file LICENSE. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace CoiSA\Http\Test\Middleware; |
12
|
|
|
|
13
|
|
|
use CoiSA\Http\Middleware\EchoBodyMiddleware; |
14
|
|
|
use CoiSA\Http\Test\Handler\AbstractMiddlewareTest; |
15
|
|
|
use Prophecy\Prophecy\ObjectProphecy; |
16
|
|
|
use Psr\Http\Message\StreamInterface; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Class EchoBodyMiddlewareTest |
20
|
|
|
* |
21
|
|
|
* @package CoiSA\Http\Test |
22
|
|
|
*/ |
23
|
|
|
final class EchoBodyMiddlewareTest extends AbstractMiddlewareTest |
24
|
|
|
{ |
25
|
|
|
/** @var string */ |
26
|
|
|
private $content; |
27
|
|
|
|
28
|
|
|
/** @var ObjectProphecy|StreamInterface */ |
29
|
|
|
private $body; |
30
|
|
|
|
31
|
|
|
public function setUp(): void |
32
|
|
|
{ |
33
|
|
|
parent::setUp(); |
34
|
|
|
|
35
|
|
|
$this->middleware = new EchoBodyMiddleware(); |
36
|
|
|
|
37
|
|
|
$this->body = $this->prophesize(StreamInterface::class); |
38
|
|
|
|
39
|
|
|
$this->content = \uniqid('content', true); |
40
|
|
|
$this->response->getBody()->will([$this->body, 'reveal']); |
41
|
|
|
$this->body->getContents()->willReturn($this->content); |
42
|
|
|
|
43
|
|
|
\ob_start(); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function tearDown(): void |
47
|
|
|
{ |
48
|
|
|
while (\ob_get_level() > 1) { |
49
|
|
|
\ob_end_clean(); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function testProcessEchoResponseBodyContent(): void |
54
|
|
|
{ |
55
|
|
|
$this->middleware->process($this->serverRequest->reveal(), $this->handler->reveal()); |
56
|
|
|
$content = \ob_get_clean(); |
57
|
|
|
$this->assertEquals($this->content, $content); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|