modifs.mineures sans commentaires
This commit is contained in:
parent
1d9f9492a5
commit
2583ff70e5
@ -335,7 +335,7 @@ abstract class Capacitor {
|
|||||||
* @return int 1 si l'objet a été chargé ou mis à jour, 0 s'il existait
|
* @return int 1 si l'objet a été chargé ou mis à jour, 0 s'il existait
|
||||||
* déjà à l'identique dans le canal
|
* 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);
|
$this->create($channel);
|
||||||
$tableName = $channel->getTableName();
|
$tableName = $channel->getTableName();
|
||||||
$db = $this->db();
|
$db = $this->db();
|
||||||
@ -588,7 +588,7 @@ abstract class Capacitor {
|
|||||||
* @param int $nbUpdated reçoit le nombre de lignes mises à jour
|
* @param int $nbUpdated reçoit le nombre de lignes mises à jour
|
||||||
* @return int le nombre de lignes parcourues
|
* @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);
|
$this->create($channel);
|
||||||
if ($func === null) $func = CapacitorChannel::onEach;
|
if ($func === null) $func = CapacitorChannel::onEach;
|
||||||
$onEach = func::with($func)->bind($channel);
|
$onEach = func::with($func)->bind($channel);
|
||||||
@ -654,7 +654,7 @@ abstract class Capacitor {
|
|||||||
*
|
*
|
||||||
* @return int le nombre de lignes parcourues
|
* @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);
|
$this->create($channel);
|
||||||
if ($func === null) $func = CapacitorChannel::onDelete;
|
if ($func === null) $func = CapacitorChannel::onDelete;
|
||||||
$onDelete = func::with($func)->bind($channel);
|
$onDelete = func::with($func)->bind($channel);
|
||||||
|
@ -6,49 +6,50 @@ use nulib\cl;
|
|||||||
use nulib\db\Capacitor;
|
use nulib\db\Capacitor;
|
||||||
use nulib\db\CapacitorChannel;
|
use nulib\db\CapacitorChannel;
|
||||||
|
|
||||||
class SqliteStorageTest extends TestCase {
|
class SqliteCapacitorTest extends TestCase {
|
||||||
static function Txx(...$values): void {
|
static function Txx(...$values): void {
|
||||||
foreach ($values as $value) {
|
foreach ($values as $value) {
|
||||||
var_export($value);
|
var_export($value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function _testChargeStrings(SqliteCapacitor $storage, ?string $channel) {
|
function _testChargeStrings(SqliteCapacitor $capacitor, CapacitorChannel $channel) {
|
||||||
$storage->reset($channel);
|
$capacitor->reset($channel);
|
||||||
$storage->charge($channel, "first");
|
$capacitor->charge($channel, "first");
|
||||||
$storage->charge($channel, "second");
|
$capacitor->charge($channel, "second");
|
||||||
$storage->charge($channel, "third");
|
$capacitor->charge($channel, "third");
|
||||||
$items = cl::all($storage->discharge($channel, false));
|
$items = cl::all($capacitor->discharge($channel, false));
|
||||||
self::assertSame(["first", "second", "third"], $items);
|
self::assertSame(["first", "second", "third"], $items);
|
||||||
}
|
}
|
||||||
|
|
||||||
function _testChargeArrays(SqliteCapacitor $storage, ?string $channel) {
|
function _testChargeArrays(SqliteCapacitor $capacitor, CapacitorChannel $channel) {
|
||||||
$storage->reset($channel);
|
$capacitor->reset($channel);
|
||||||
$storage->charge($channel, ["id" => 10, "name" => "first"]);
|
$capacitor->charge($channel, ["id" => 10, "name" => "first"]);
|
||||||
$storage->charge($channel, ["name" => "second", "id" => 20]);
|
$capacitor->charge($channel, ["name" => "second", "id" => 20]);
|
||||||
$storage->charge($channel, ["name" => "third", "id" => "30"]);
|
$capacitor->charge($channel, ["name" => "third", "id" => "30"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testChargeStrings() {
|
function testChargeStrings() {
|
||||||
$storage = new SqliteCapacitor(__DIR__.'/capacitor.db');
|
$capacitor = new SqliteCapacitor(__DIR__.'/capacitor.db');
|
||||||
$this->_testChargeStrings($storage, null);
|
$channel = new CapacitorChannel();
|
||||||
$storage->close();
|
$this->_testChargeStrings($capacitor, $channel);
|
||||||
|
$capacitor->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
function testChargeArrays() {
|
function testChargeArrays() {
|
||||||
$storage = new SqliteCapacitor(__DIR__.'/capacitor.db');
|
$capacitor = new SqliteCapacitor(__DIR__.'/capacitor.db');
|
||||||
$storage->addChannel(new class extends CapacitorChannel {
|
$channel = new class extends CapacitorChannel {
|
||||||
const NAME = "arrays";
|
const NAME = "arrays";
|
||||||
const COLUMN_DEFINITIONS = ["id" => "integer"];
|
const COLUMN_DEFINITIONS = ["id" => "integer"];
|
||||||
|
|
||||||
function getItemValues($item): ?array {
|
function getItemValues($item): ?array {
|
||||||
return ["id" => $item["id"] ?? null];
|
return ["id" => $item["id"] ?? null];
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
|
||||||
$this->_testChargeStrings($storage, "strings");
|
$this->_testChargeStrings($capacitor, "strings");
|
||||||
$this->_testChargeArrays($storage, "arrays");
|
$this->_testChargeArrays($capacitor, "arrays");
|
||||||
$storage->close();
|
$capacitor->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
function testEach() {
|
function testEach() {
|
Loading…
x
Reference in New Issue
Block a user