Passed
Push — master ( dbf0a8...b29633 )
by
unknown
02:35
created

ObjectParserTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 45
rs 10
c 0
b 0
f 0
wmc 1

6 Methods

Rating   Name   Duplication   Size   Complexity  
testSkipStaticProperties() 0 5 ?
A hp$1 ➔ testSkipStaticProperties() 0 5 1
A hp$1 ➔ dataSkipStaticProperties() 0 19 1
dataSkipStaticProperties() 0 19 ?
testSkipStaticPropertiesDefault() 0 10 ?
A hp$2 ➔ testSkipStaticPropertiesDefault() 0 10 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Validator\Tests\Helper;
6
7
use PHPUnit\Framework\TestCase;
8
use Yiisoft\Validator\Helper\ObjectParser;
9
10
final class ObjectParserTest extends TestCase
11
{
12
    public function dataSkipStaticProperties(): array
13
    {
14
        return [
15
            [
16
                ['a' => 4, 'b' => 2],
17
                new class () {
18
                    public int $a = 4;
19
                    public static int $b = 2;
20
                },
21
                false,
22
            ],
23
            [
24
                ['a' => 4, 'c' => 'hello'],
25
                new class () {
26
                    public int $a = 4;
27
                    public static int $b = 2;
28
                    public string $c = 'hello';
29
                },
30
                true,
31
            ],
32
        ];
33
    }
34
35
    /**
36
     * @dataProvider dataSkipStaticProperties
37
     */
38
    public function testSkipStaticProperties(array $expectedData, object $object, bool $skipStaticProperties): void
39
    {
40
        $parser = new ObjectParser($object, skipStaticProperties: $skipStaticProperties);
41
42
        $this->assertSame($expectedData, $parser->getData());
43
    }
44
45
    public function testSkipStaticPropertiesDefault(): void
46
    {
47
        $object = new class () {
48
            public int $a = 4;
49
            public static int $b = 2;
50
        };
51
52
        $parser = new ObjectParser($object);
53
54
        $this->assertSame(['a' => 4, 'b' => 2], $parser->getData());
55
    }
56
}
57