-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
Copy patharraylist.phpt
58 lines (48 loc) · 1.04 KB
/
arraylist.phpt
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
--TEST--
swoole_thread: arraylist
--SKIPIF--
<?php
require __DIR__ . '/../include/skipif.inc';
skip_if_nts();
?>
--FILE--
<?php
require __DIR__ . '/../include/bootstrap.php';
use Swoole\Thread\ArrayList;
$uuid = uniqid();
$array = [
random_int(1, 999999999999999999),
random_bytes(128),
$uuid,
time(),
];
$l = new ArrayList($array);
Assert::eq(count($l), count($array));
Assert::eq($l->toArray(), $array);
Assert::eq($l->find($uuid), 2);
for ($i = 0; $i < count($array); $i++) {
Assert::eq($l[$i], $array[$i]);
}
$array2 = [
'key' => 'value',
'hello' => 'world',
];
$l[] = $array2;
Assert::eq(count($l), 5);
Assert::eq($l[4]->toArray(), $array2);
try {
$l2 = new ArrayList($array2);
echo "never here\n";
} catch (Throwable $e) {
Assert::contains($e->getMessage(), 'must be an array of type list');
}
$uuid2 = uniqid();
$l[] = $uuid2;
$count = count($l);
unset($l[1]);
Assert::eq(count($l), $count - 1);
Assert::eq($l[1], $uuid);
Assert::eq($l->find($uuid), 1);
Assert::eq($l->find($uuid2), $count - 2);
?>
--EXPECTF--