modifs.mineures sans commentaires

This commit is contained in:
Jephté Clain 2025-09-15 08:34:38 +04:00
parent 1d9f9492a5
commit 2583ff70e5
2 changed files with 25 additions and 24 deletions

View File

@ -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);

View File

@ -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() {