Skip to content

Commit f25ac8d

Browse files
committed
Add orderByChild() realtime database integration test
1 parent 0814061 commit f25ac8d

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

tests/Integration/Database/QueryTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,29 @@ public function limitToLast(): void
4747

4848
$this->assertSame(['key' => 3], current($value));
4949
}
50+
51+
#[Test]
52+
public function orderByChild(): void
53+
{
54+
$ref = $this->ref->getChild(__FUNCTION__);
55+
56+
$rules = self::$db->getRuleSet()->getRules();
57+
58+
$rules['rules'][$this->ref->getPath()] = [
59+
__FUNCTION__ => [
60+
'.indexOn' => ['child/grandchild']
61+
],
62+
];
63+
self::$db->updateRules(RuleSet::fromArray($rules));
64+
65+
$ref->getChild('first')->set(['child' => ['grandchild' => 3]]);
66+
$ref->getChild('second')->set(['child' => ['grandchild' => 4]]);
67+
$ref->getChild('third')->set(['child' => ['grandchild' => 1]]);
68+
$ref->getChild('fourth')->set(['child' => ['grandchild' => 2]]);
69+
70+
$check = $ref->orderByChild('child/grandchild')->getValue();
71+
$keys = array_keys($check);
72+
73+
$this->assertSame(['third', 'fourth', 'first', 'second'], $keys);
74+
}
5075
}

0 commit comments

Comments
 (0)