ParserTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 4
dl 0
loc 44
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetRequestBody() 0 4 1
A getRequests() 0 30 1
1
<?php
2
declare(strict_types=1);
3
4
namespace DataFlow\Tests\Unit\Stdlib\Request;
5
6
use Psr\Http\Message\ServerRequestInterface;
7
use SlayerBirden\DataFlowServer\Stdlib\Request\Parser;
8
use Zend\Diactoros\ServerRequest;
9
10
class A
11
{
12
    public $a;
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $a. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
13
    public $b;
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $b. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
14
}
15
16
final class ParserTest extends \Codeception\Test\Unit
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...
17
{
18
    /**
19
     * @param ServerRequestInterface $request
20
     * @param array $expected
21
     *
22
     * @dataProvider getRequests
23
     */
24
    public function testGetRequestBody(ServerRequestInterface $request, array $expected): void
25
    {
26
        $this->assertSame($expected, Parser::getRequestBody($request));
27
    }
28
29
    public function getRequests(): array
30
    {
31
        $body = new A();
32
        $body->a = 'baz';
33
        $body->b = 'bar';
34
35
        $collection = new \ArrayObject([1, 2, 3]);
36
        return [
37
            [
38
                (new ServerRequest())->withParsedBody(null),
39
                [],
40
            ],
41
            [
42
                (new ServerRequest())->withParsedBody([]),
43
                [],
44
            ],
45
            [
46
                (new ServerRequest())->withParsedBody($body),
47
                ['a' => 'baz', 'b' => 'bar'],
48
            ],
49
            [
50
                (new ServerRequest())->withParsedBody($collection),
51
                [1, 2, 3],
52
            ],
53
            [
54
                (new ServerRequest())->withParsedBody(['zzz' => 'aaa']),
55
                ['zzz' => 'aaa'],
56
            ],
57
        ];
58
    }
59
}
60