reset($channel); $capacitor->charge("first", $channel); $capacitor->charge("second", $channel); $capacitor->charge("third", $channel); $items = iterator_to_array($capacitor->discharge(null, $channel, false)); self::assertSame(["first", "second", "third"], $items); } function _testChargeArrays(SqliteCapacitor $capacitor, ?string $channel) { $capacitor->reset($channel); $capacitor->charge(["id" => 10, "name" => "first"], $channel); $capacitor->charge(["name" => "second", "id" => 20], $channel); $capacitor->charge(["name" => "third", "id" => "30"], $channel); } function testChargeStrings() { $capacitor = new SqliteCapacitor(__DIR__.'/capacitor.db'); $this->_testChargeStrings($capacitor, null); $capacitor->close(); } function testChargeArrays() { $capacitor = new SqliteCapacitor(__DIR__.'/capacitor.db'); $capacitor->addChannel(new class extends CapacitorChannel { const NAME = "arrays"; function getKeyDefinitions(): ?array { return ["id" => "integer"]; } function getKeyValues($item): ?array { return ["id" => $item["id"] ?? null]; } }); $this->_testChargeStrings($capacitor, "strings"); $this->_testChargeArrays($capacitor, "arrays"); $capacitor->close(); } function testEach() { $capacitor = new SqliteCapacitor(__DIR__.'/capacitor.db'); $capacitor->addChannel(new class extends CapacitorChannel { const NAME = "each"; function getKeyDefinitions(): ?array { return [ "age" => "integer", "done" => "integer default 0", ]; } function getKeyValues($item): ?array { return [ "age" => $item["age"], ]; } }); $channel = "each"; $capacitor->reset($channel); $capacitor->charge(["name" => "first", "age" => 5], $channel); $capacitor->charge(["name" => "second", "age" => 10], $channel); $capacitor->charge(["name" => "third", "age" => 15], $channel); $capacitor->charge(["name" => "fourth", "age" => 20], $channel); $setDone = function ($item, $row, $suffix=null) { $updates = ["done" => 1]; if ($suffix !== null) { $item["name"] .= $suffix; $updates["_item"] = $item; } return $updates; }; $capacitor->each(["age" => [">", 10]], $setDone, ["++"], $channel); $capacitor->each(["done" => 0], $setDone, null, $channel); Txx(iterator_to_array($capacitor->discharge(null, $channel, false))); $capacitor->close(); self::assertTrue(true); } }