Completed
Push — master ( af09d7...7599bb )
by Dorian
02:06
created

ArrayPopulatedObjectTest::testSetUnknownProperty()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Tests\Unit\Library\Helper;
6
7
use PHPUnit\Framework\TestCase;
8
use Tests\Unit\Library\Helper\Mock\ArrayPopulatedObjectMock;
9
10
final class ArrayPopulatedObjectTest extends TestCase
11
{
12
    /**
13
     * @dataProvider getObjectData
14
     */
15
    public function testObjectInstantiation(array $data, array $expected): void
16
    {
17
        $object = new ArrayPopulatedObjectMock($data);
18
19
        foreach (get_object_vars($object) as $property => $value) {
20
            $this->assertEquals($value, $expected[$property]);
21
        }
22
    }
23
24
    public function getObjectData(): array
25
    {
26
        return [
27
            [
28
                [],
29
                [
30
                    'property1' => null,
31
                    'property2' => null,
32
                    'untouchedProperty' => null,
33
                ],
34
            ],
35
            [
36
                [
37
                    'property1' => 'test1',
38
                    'property2' => 'test2',
39
                ],
40
                [
41
                    'property1' => 'test1',
42
                    'property2' => 'test2',
43
                    'untouchedProperty' => null,
44
                ],
45
            ],
46
            [
47
                [
48
                    'property1' => ['test 1.1', 'test 1.2'],
49
                    'property2' => new \StdClass(),
50
                ],
51
                [
52
                    'property1' => ['test 1.1', 'test 1.2'],
53
                    'property2' => new \StdClass(),
54
                    'untouchedProperty' => null,
55
                ],
56
            ],
57
        ];
58
    }
59
60
    public function testSetUnknownProperty(): void
61
    {
62
        $this->expectException(\InvalidArgumentException::class);
63
        $this->expectExceptionMessage('Expected the property "unknownProperty" to exist.');
64
65
        new ArrayPopulatedObjectMock(
66
            [
67
                'property1' => 'test',
68
                'unknownProperty' => true,
69
            ]
70
        );
71
    }
72
}
73