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
|
<?php
namespace OpenCloud\Test\Common;
use OpenCloud\Common\JsonPath;
class JsonPathTest extends \PHPUnit_Framework_TestCase
{
private $jsonPath;
public function setUp()
{
$this->jsonPath = new JsonPath([]);
}
public function test_it_sets_values_according_to_paths()
{
$this->jsonPath->set('foo.bar.baz', 'VALUE');
$expected = [
'foo' => [
'bar' => [
'baz' => 'VALUE',
]
]
];
$this->assertEquals($expected, $this->jsonPath->getStructure());
}
public function test_it_sets_arrays_according_to_paths()
{
$jsonPath = new JsonPath([
'foo' => [
'bar' => [
'value' => 'VALUE',
]
]
]);
$jsonPath->set('foo.bar.items', ['item_1', 'item_2']);
$expected = [
'foo' => [
'bar' => [
'value' => 'VALUE',
'items' => ['item_1', 'item_2'],
]
]
];
$this->assertEquals($expected, $jsonPath->getStructure());
}
public function test_it_gets_values_according_to_paths()
{
$jsonPath = new JsonPath([
'foo' => [
'bar' => [
'baz' => 'VALUE_1',
'lol' => 'VALUE_2',
]
]
]);
$this->assertEquals('VALUE_1', $jsonPath->get('foo.bar.baz'));
$this->assertEquals('VALUE_2', $jsonPath->get('foo.bar.lol'));
$this->assertNull($jsonPath->get('foo.bar.boo'));
}
}
|