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

ObjectParserTest::testSkipStaticProperties()

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
nc 1
nop 3
dl 0
loc 5
c 0
b 0
f 0
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