-
Notifications
You must be signed in to change notification settings - Fork 143
Expand file tree
/
Copy pathDeepSetAccessorsTest.php
More file actions
101 lines (81 loc) · 2.19 KB
/
Copy pathDeepSetAccessorsTest.php
File metadata and controls
101 lines (81 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
namespace Intercom\Tests\Core\Pagination;
use PHPUnit\Framework\TestCase;
use Intercom\Core\Pagination\PaginationHelper;
class RootObjectAccessors
{
private ?Level1ObjectAccessors $level1;
public function getLevel1(): ?Level1ObjectAccessors
{
return $this->level1;
}
/**
* @param ?array{
* level1?: ?Level1ObjectAccessors,
* } $data
*/
public function __construct(?array $data = [])
{
$this->level1 = $data['level1'] ?? null;
}
}
class Level1ObjectAccessors
{
private ?Level2ObjectAccessors $level2;
public function getLevel2(): ?Level2ObjectAccessors
{
return $this->level2;
}
/**
* @param ?array{
* level2?: ?Level2ObjectAccessors,
* } $data
*/
public function __construct(?array $data = [])
{
$this->level2 = $data['level2'] ?? null;
}
}
class Level2ObjectAccessors
{
private ?string $level3;
/**
* @return string|null
*/
public function getLevel3(): ?string
{
return $this->level3;
}
/**
* @param ?array{
* level3?: ?string,
* } $data
*/
public function __construct(?array $data = [])
{
$this->level3 = $data['level3'] ?? null;
}
}
class DeepSetAccessorsTest extends TestCase
{
public function testSetNestedPropertyWithNull(): void
{
$object = new RootObjectAccessors();
$this->assertNull($object->getLevel1());
PaginationHelper::setDeep($object, ['level1', 'level2', 'level3'], 'testValue');
$this->assertEquals('testValue', $object->getLevel1()?->getLevel2()?->getLevel3());
}
public function testSetNestedProperty(): void
{
$object = new RootObjectAccessors([
"level1" => new Level1ObjectAccessors([
"level2" => new Level2ObjectAccessors([
"level3" => null
])
])
]);
$this->assertNull($object->getLevel1()?->getLevel2()?->getLevel3());
PaginationHelper::setDeep($object, ['level1', 'level2', 'level3'], 'testValue');
$this->assertEquals('testValue', $object->getLevel1()?->getLevel2()?->getLevel3());
}
}