Completed
Push — master ( 56e25c...088dd2 )
by Oleg
19:18
created

iddlewareTest.php$1   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 12
Duplicated Lines 0 %

Coupling/Cohesion

Dependencies 2

Importance

Changes 0
Metric Value
wmc 1
cbo 2
dl 0
loc 12
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace DataFlow\Tests\Unit\Stdlib\Middleware;
5
6
use PHPUnit\Framework\TestCase;
7
use Psr\Http\Message\ResponseInterface;
8
use Psr\Http\Message\ServerRequestInterface;
9
use Psr\Http\Server\MiddlewareInterface;
10
use Psr\Http\Server\RequestHandlerInterface;
11
use SlayerBirden\DataFlowServer\Stdlib\Middleware\ResetIdMiddleware;
12
use Zend\Diactoros\Response\JsonResponse;
13
14
final class ResetIdMiddlewareTest extends TestCase
15
{
16
    public function testResetData()
17
    {
18
        $middleware = new ResetIdMiddleware();
19
20
        $request = new \Zend\Diactoros\ServerRequest();
21
22
        $pipeline = new \Zend\Stratigility\MiddlewarePipe();
23
        $last = new class implements MiddlewareInterface
0 ignored issues
show
Coding Style introduced by
This class is not in CamelCase format.

Classes in PHP are usually named in CamelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. The whole name starts with a capital letter as well.

Thus the name database provider becomes DatabaseProvider.

Loading history...
24
        {
25
            /**
26
             * @inheritdoc
27
             */
28
            public function process(
29
                ServerRequestInterface $request,
30
                RequestHandlerInterface $handler
31
            ): ResponseInterface {
32
                return new JsonResponse($request->getParsedBody(), 200);
33
            }
34
        };
35
        $pipeline->pipe($middleware);
36
        $pipeline->pipe($last);
37
38
        $response = $pipeline->handle($request->withParsedBody([
39
            'name' => 'bar',
40
            'id' => 'baz',
41
        ]));
42
43
        $this->assertJsonStringEqualsJsonString(json_encode(['name' => 'bar']), $response->getBody()->__toString());
44
    }
45
46
    public function testResetDataNonDefault()
47
    {
48
        $middleware = new ResetIdMiddleware('name');
49
50
        $request = new \Zend\Diactoros\ServerRequest();
51
52
        $pipeline = new \Zend\Stratigility\MiddlewarePipe();
53
        $last = new class implements MiddlewareInterface
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
Coding Style introduced by
This class is not in CamelCase format.

Classes in PHP are usually named in CamelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. The whole name starts with a capital letter as well.

Thus the name database provider becomes DatabaseProvider.

Loading history...
54
        {
55
            /**
56
             * @inheritdoc
57
             */
58
            public function process(
59
                ServerRequestInterface $request,
60
                RequestHandlerInterface $handler
61
            ): ResponseInterface {
62
                return new JsonResponse($request->getParsedBody(), 200);
63
            }
64
        };
65
        $pipeline->pipe($middleware);
66
        $pipeline->pipe($last);
67
68
        $response = $pipeline->handle($request->withParsedBody([
69
            'name' => 'bar',
70
            'id' => 'baz',
71
        ]));
72
73
        $this->assertJsonStringEqualsJsonString(json_encode(['id' => 'baz']), $response->getBody()->__toString());
74
    }
75
}
76