25 $this->objectManagerHelper =
new ObjectManagerHelper($this);
26 $this->arrayManager = $this->objectManagerHelper->getObject(ArrayManager::class);
47 'path' =>
'some/path',
48 'data' => [
'some' => [
'path' =>
null]],
53 'data' => [[[
'test' =>
false]]],
57 'path' =>
'invalid/path',
58 'data' => [
'valid' => [
'path' => 0]],
66 $data = [
'custom' => [
'delimiter' =>
null]];
68 $this->assertFalse($this->arrayManager->exists(
'custom/delimiter',
$data,
'~'));
69 $this->assertTrue($this->arrayManager->exists(
'custom~delimiter',
$data,
'~'));
90 'path' =>
'nested/path/0',
91 'data' => [
'nested' => [
'path' => [
'value1']]],
100 'path' =>
'invalid/path/0',
127 'data' => [[
false,
false]],
129 'result' => [[
false,
true]]
133 'data' => [
'test' => [
'lost data']],
134 'value' =>
'found data',
135 'result' => [
'test' =>
'found data']
138 'path' =>
'new/path/2',
139 'data' => [
'existing' => [
'path' => 1]],
140 'value' =>
'valuable data',
141 'result' => [
'existing' => [
'path' => 1],
'new' => [
'path' => [2 =>
'valuable data']]]
144 'path' => [
'new',
'path/2'],
145 'data' => [
'existing' => [
'path' => 1]],
146 'value' =>
'valuable data',
147 'result' => [
'existing' => [
'path' => 1],
'new' => [
'path' => [2 =>
'valuable data']]]
172 'data' => [[
false,
false]],
174 'result' => [[
false,
true]]
178 'data' => [
'test' => [
'lost data']],
179 'value' =>
'found data',
180 'result' => [
'test' =>
'found data']
183 'path' =>
'new/path/2',
184 'data' => [
'existing' => [
'path' => 1]],
185 'value' =>
'valuable data',
186 'result' => [
'existing' => [
'path' => 1]]
189 'path' => [
'new',
'path',
'2'],
190 'data' => [
'existing' => [
'path' => 1]],
191 'value' =>
'valuable data',
192 'result' => [
'existing' => [
'path' => 1]]
207 $this->assertSame(
$result, $this->arrayManager->move(
$path, $targetPath,
$data, $overwrite));
217 'path' =>
'not/valid/path',
218 'targetPath' =>
'target/path',
219 'data' => [
'valid' => [
'path' =>
'value']],
220 'overwrite' =>
false,
221 'result' => [
'valid' => [
'path' =>
'value']]
224 'path' =>
'valid/path',
225 'targetPath' =>
'target/path',
226 'data' => [
'valid' => [
'path' =>
'value']],
227 'overwrite' =>
false,
228 'result' => [
'valid' => [],
'target' => [
'path' =>
'value']]
231 'path' =>
'valid/path',
232 'targetPath' =>
'target/path',
233 'data' => [
'valid' => [
'path' =>
'value'],
'target' => [
'path' =>
'exists']],
234 'overwrite' =>
false,
235 'result' => [
'valid' => [
'path' =>
'value'],
'target' => [
'path' =>
'exists']]
238 'path' =>
'valid/path',
239 'targetPath' =>
'target/path',
240 'data' => [
'valid' => [
'path' =>
'value'],
'target' => [
'path' =>
'exists']],
242 'result' => [
'valid' => [],
'target' => [
'path' =>
'value']]
245 'path' => [
'valid',
'path'],
246 'targetPath' =>
'target/path',
247 'data' => [
'valid' => [
'path' =>
'value'],
'target' => [
'path' =>
'exists']],
249 'result' => [
'valid' => [],
'target' => [
'path' =>
'value']]
273 'path' =>
'0/path/1',
274 'data' => [[
'path' => [
false, [
'value' =>
false]]]],
275 'value' => [
'value' =>
true,
'new_value' =>
false],
276 'result' => [[
'path' => [
false, [
'value' =>
true,
'new_value' =>
false]]]]
280 'data' => [[
'nested' => [
'test' => 2,
'test2' => 1]]],
281 'value' => [
'nested' => [
'test' => 3],
'more' => 4],
282 'result' => [[
'nested' => [
'test' => 3,
'test2' => 1],
'more' => 4]]
285 'path' =>
'invalid/path',
291 'path' => [
'0',
'path/1'],
292 'data' => [[
'path' => [
false, [
'value' =>
false]]]],
293 'value' => [
'value' =>
true,
'new_value' =>
false],
294 'result' => [[
'path' => [
false, [
'value' =>
true,
'new_value' =>
false]]]]
317 'path' =>
'some/is/not/array',
318 'data' => [
'some' =>
true],
319 'result' => [
'some' =>
true]
327 'path' =>
'nested/1/array',
328 'data' => [
'nested' => [
true]],
329 'result' => [
'nested' => [
true, [
'array' => []]]]
353 'data' => [[[[
null]]]],
358 'data' => [
'simple' =>
true,
'complex' =>
false],
359 'result' => [
'complex' =>
false]
367 'path' => [
'simple'],
368 'data' => [
'simple' =>
true,
'complex' =>
false],
369 'result' => [
'complex' =>
false]
384 $this->assertSame(
$result, $this->arrayManager->findPaths($indexes,
$data, $startPath, $internalPath));
396 'children' => [
true,
true]
408 'children' => [
true,
true,
true]
419 'startPath' =>
'element2',
420 'internalPath' =>
null,
421 'result' => [
'element2/children/0',
'element2/children/2']
426 'startPath' => [
'',
'0'],
427 'internalPath' =>
'0',
428 'result' => [
'/0/0',
'/0/0/0/0']
434 'internalPath' => [
'0',
'0'],
435 'result' => [
'/0',
'/0/0/0/0']
440 'startPath' =>
'element1/children',
441 'internalPath' =>
'config/argument',
442 'result' => [
'element1/children/element12/config/argument/data']
448 'internalPath' =>
'elements',
464 $this->assertSame(
$result, $this->arrayManager->findPath($indexes,
$data, $startPath, $internalPath));
476 'children' => [
true,
true]
488 'children' => [
true,
true,
true]
499 'startPath' =>
'element2',
500 'internalPath' =>
null,
501 'result' =>
'element2/children/0' 506 'startPath' => [
'',
'0'],
507 'internalPath' =>
'0',
514 'internalPath' => [
'0',
'0'],
520 'startPath' =>
'element1/children',
521 'internalPath' =>
'config/argument',
522 'result' =>
'element1/children/element12/config/argument/data' 528 'internalPath' =>
'elements',
543 $this->assertSame(
$result, $this->arrayManager->slicePath(
$path, $offset, $length));
551 $path =
'some/very/very/long/path/0/goes/1/3/here';
558 'result' =>
'long/path/0/goes/1/3/here' 564 'result' =>
'1/3/here' 576 'result' =>
'very/long' 582 'result' =>
'path/0/goes' 589 $path =
'my~custom~path';
591 $this->assertSame(
'custom', $this->arrayManager->slicePath(
$path, 1, 1,
'~'));
592 $this->assertSame(
'', $this->arrayManager->slicePath(
$path, 1, 1));
testFindPath($indexes, array $data, $startPath, $internalPath, $result)
testExists($path, $data, $result)
testSet($path, $data, $value, $result)
testMerge($path, $data, $value, $result)
testGet($path, $data, $result)
testReplace($path, $data, $value, $result)
testSlicePath($path, $offset, $length, $result)
testFindPaths($indexes, array $data, $startPath, $internalPath, $result)
testMove($path, $targetPath, array $data, $overwrite, array $result)
testRemove($path, $data, $result)
testExistsCustomDelimiter()
testPopulate($path, $data, $result)
testSlicePathCustomDelimiter()