Completed
Push — master ( 0456c5...25ee32 )
by Oleg
04:45
created

NullDecoratorTest::testExtract()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
declare(strict_types=1);
3
4
namespace DataFlow\Tests\Unit\Doctrine\Hydrator\Strategy\Decoration;
5
6
use SlayerBirden\DataFlowServer\Doctrine\Hydrator\Strategy\DecoratedStrategy;
7
use SlayerBirden\DataFlowServer\Doctrine\Hydrator\Strategy\Decoration\NullDecorator;
8
use SlayerBirden\DataFlowServer\Doctrine\Hydrator\Strategy\NestedEntityStrategy;
9
use Zend\Hydrator\HydratorInterface;
10
use Zend\Hydrator\ObjectProperty;
11
12
class A
13
{
14
    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...
15
    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...
16
}
17
18
class B
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...
19
{
20
    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...
21
    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...
22
}
23
24
final class NullDecoratorTest 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...
25
{
26
    /**
27
     * @var HydratorInterface
28
     */
29
    private $hydrator;
30
31
    protected function setUp()
32
    {
33
        $this->hydrator = new ObjectProperty();
34
        $this->hydrator->addStrategy('b', new DecoratedStrategy(
35
            new NestedEntityStrategy(new ObjectProperty()),
36
            new NullDecorator()
37
        ));
38
    }
39
40
    /**
41
     * @param A $a
42
     * @param array $expected
43
     *
44
     * @dataProvider hydratorsDataProvider
45
     */
46
    public function testExtract(A $a, array $expected): void
47
    {
48
        $this->assertSame($expected, $this->hydrator->extract($a));
49
    }
50
51
    public function hydratorsDataProvider(): array
52
    {
53
        $a1 = new A();
54
        $a1->a = 10;
55
        $b1 = new B();
56
        $b1->a = 15;
57
        $b1->b = 'bar';
58
        $a1->b = $b1;
59
60
        $a2 = new A();
61
        $a2->a = 14;
62
        $a2->b = null;
63
64
        return [
65
            [
66
                $a1,
67
                [
68
                    'a' => 10,
69
                    'b' => [
70
                        'a' => 15,
71
                        'b' => 'bar'
72
                    ],
73
                ],
74
            ],
75
            [
76
                $a2,
77
                [
78
                    'a' => 14,
79
                    'b' => null,
80
                ],
81
            ],
82
        ];
83
    }
84
}
85