/
Arrs.php
66 lines (61 loc) · 2.35 KB
/
Arrs.php
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
<?php
declare(strict_types=1);
/*
* This file is part of the QuidPHP package <https://quidphp.com>
* Author: Pierre-Philippe Emond <emondpph@gmail.com>
* License: https://github.com/quidphp/main/blob/master/LICENSE
*/
namespace Quid\Test\Main;
use Quid\Base;
use Quid\Main;
// arrs
// class for testing Quid\Main\Arrs
class Arrs extends Base\Test
{
// trigger
final public static function trigger(array $data):bool
{
// construct
$arrs = new Main\Arrs();
// map
$arrs['james/ok'] = 2;
assert($arrs->toArray() === ['james'=>['ok'=>2]]);
unset($arrs['james/ok']);
assert($arrs->toArray() === ['james'=>[]]);
$arrs['james/ok3'] = 3;
$arrs['james/ok'] = 2;
$arrs['james/ok4/what'] = 2;
assert($arrs->values()[0] === [3,2,[2]]);
assert($arrs->exists(['james','ok']));
assert(!$arrs->exists(['james','ok2']));
assert($arrs->in(2));
assert($arrs->search(2) === ['james','ok']);
assert($arrs->keys(2) === [['james','ok'],['james','ok4','what']]);
assert($arrs->get('james/ok3') === 3);
assert($arrs->gets('james/ok3') === ['james/ok3'=>3]);
assert($arrs->gets(['james','ok3']) === ['james/ok3'=>3]);
assert($arrs->index([0,-1,0]) === 2);
assert($arrs->indexes([0,-1,0]) === ['0/-1/0'=>2]);
assert(key($arrs->sort()['james']) === 'ok');
assert($arrs->sequential()[0][0] === 2);
$arrs->empty();
$arrs['james/ok3'] = 3;
$arrs['james/ok'] = 2;
$arrs['james/ok4/what'] = 2;
assert($arrs->set('ok/well',3) instanceof Main\Arrs);
assert($arrs->set(['ok',null],'z') instanceof Main\Arrs);
assert($arrs['ok/0'] === 'z');
assert($arrs->sets(['ok/well2'=>true])['ok']['well2'] === true);
assert($arrs->unset(['ok','well2'])['ok'] === ['well'=>3,'z']);
$arrs2 = new Main\Arrs(['james'=>['okz'=>2]]);
assert(count($arrs2->replace($arrs->toArray())['james']) === 4);
assert($arrs->remove(2,3,'z')['ok'] === []);
$arrs3 = new Main\Arrs($arrs2);
assert($arrs2->toArray() === $arrs2->toArray());
$arrs4 = new Main\Arrs(['test/ok'=>2,'james/lol'=>'bla']);
assert($arrs4['test']['ok'] === 2);
assert($arrs4->replace($arrs,['meh/lol'=>'ok'])['meh']['lol'] === 'ok');
return true;
}
}
?>