Passed
Push — master ( 1849ae...73997f )
by Felipe
01:57
created

EchoBodyMiddlewareTest::testProcessReturnResponse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
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