diff --git a/php/src/db/Capacitor.php b/php/src/db/Capacitor.php index 949ffee..32a278b 100644 --- a/php/src/db/Capacitor.php +++ b/php/src/db/Capacitor.php @@ -335,7 +335,7 @@ abstract class Capacitor { * @return int 1 si l'objet a été chargé ou mis à jour, 0 s'il existait * déjà à l'identique dans le canal */ - function charge(CapacitorChannel $channel, $item, $func, ?array $args, ?array &$row=null): int { + function charge(CapacitorChannel $channel, $item, $func=null, ?array $args=null, ?array &$row=null): int { $this->create($channel); $tableName = $channel->getTableName(); $db = $this->db(); @@ -588,7 +588,7 @@ abstract class Capacitor { * @param int $nbUpdated reçoit le nombre de lignes mises à jour * @return int le nombre de lignes parcourues */ - function each(CapacitorChannel $channel, $filter, $func, ?array $args, ?array $mergeQuery=null, ?int &$nbUpdated=null): int { + function each(CapacitorChannel $channel, $filter, $func=null, ?array $args=null, ?array $mergeQuery=null, ?int &$nbUpdated=null): int { $this->create($channel); if ($func === null) $func = CapacitorChannel::onEach; $onEach = func::with($func)->bind($channel); @@ -654,7 +654,7 @@ abstract class Capacitor { * * @return int le nombre de lignes parcourues */ - function delete(CapacitorChannel $channel, $filter, $func, ?array $args): int { + function delete(CapacitorChannel $channel, $filter, $func=null, ?array $args=null): int { $this->create($channel); if ($func === null) $func = CapacitorChannel::onDelete; $onDelete = func::with($func)->bind($channel); diff --git a/php/tests/db/sqlite/SqliteStorageTest.php b/php/tests/db/sqlite/SqliteCapacitorTest.php similarity index 90% rename from php/tests/db/sqlite/SqliteStorageTest.php rename to php/tests/db/sqlite/SqliteCapacitorTest.php index 7e6b071..9e6404b 100644 --- a/php/tests/db/sqlite/SqliteStorageTest.php +++ b/php/tests/db/sqlite/SqliteCapacitorTest.php @@ -6,49 +6,50 @@ use nulib\cl; use nulib\db\Capacitor; use nulib\db\CapacitorChannel; -class SqliteStorageTest extends TestCase { +class SqliteCapacitorTest extends TestCase { static function Txx(...$values): void { foreach ($values as $value) { var_export($value); } } - function _testChargeStrings(SqliteCapacitor $storage, ?string $channel) { - $storage->reset($channel); - $storage->charge($channel, "first"); - $storage->charge($channel, "second"); - $storage->charge($channel, "third"); - $items = cl::all($storage->discharge($channel, false)); + function _testChargeStrings(SqliteCapacitor $capacitor, CapacitorChannel $channel) { + $capacitor->reset($channel); + $capacitor->charge($channel, "first"); + $capacitor->charge($channel, "second"); + $capacitor->charge($channel, "third"); + $items = cl::all($capacitor->discharge($channel, false)); self::assertSame(["first", "second", "third"], $items); } - function _testChargeArrays(SqliteCapacitor $storage, ?string $channel) { - $storage->reset($channel); - $storage->charge($channel, ["id" => 10, "name" => "first"]); - $storage->charge($channel, ["name" => "second", "id" => 20]); - $storage->charge($channel, ["name" => "third", "id" => "30"]); + function _testChargeArrays(SqliteCapacitor $capacitor, CapacitorChannel $channel) { + $capacitor->reset($channel); + $capacitor->charge($channel, ["id" => 10, "name" => "first"]); + $capacitor->charge($channel, ["name" => "second", "id" => 20]); + $capacitor->charge($channel, ["name" => "third", "id" => "30"]); } function testChargeStrings() { - $storage = new SqliteCapacitor(__DIR__.'/capacitor.db'); - $this->_testChargeStrings($storage, null); - $storage->close(); + $capacitor = new SqliteCapacitor(__DIR__.'/capacitor.db'); + $channel = new CapacitorChannel(); + $this->_testChargeStrings($capacitor, $channel); + $capacitor->close(); } function testChargeArrays() { - $storage = new SqliteCapacitor(__DIR__.'/capacitor.db'); - $storage->addChannel(new class extends CapacitorChannel { + $capacitor = new SqliteCapacitor(__DIR__.'/capacitor.db'); + $channel = new class extends CapacitorChannel { const NAME = "arrays"; const COLUMN_DEFINITIONS = ["id" => "integer"]; function getItemValues($item): ?array { return ["id" => $item["id"] ?? null]; } - }); + }; - $this->_testChargeStrings($storage, "strings"); - $this->_testChargeArrays($storage, "arrays"); - $storage->close(); + $this->_testChargeStrings($capacitor, "strings"); + $this->_testChargeArrays($capacitor, "arrays"); + $capacitor->close(); } function testEach() {