<?php
namespace nulib\cache;

use nulib\output\msg;

class CursorChannelTest extends _TestCase {
  const DATA = [
    "fr" => ["a" => "un", "b" => "deux"],
    "eng" => ["a" => "one", "b" => "two"],
    ["a" => 1, "b" => 2],
  ];

  function testUsage() {
    $channel = CursorChannel::with("numbers", self::DATA, self::$storage);
    $count = 0;
    foreach ($channel as $key => $item) {
      msg::info("one: $key => {$item["a"]}");
      $count++;
    }
    self::assertSame(3, $count);
  }

  function testAddColumns() {
    $channel = (new class("numbers") extends CursorChannel {
      const NAME = "numbersac";
      const TABLE_NAME = self::NAME;
      const ADD_COLUMNS = [
        "a" => "varchar(30)",
      ];
    })->initStorage(self::$storage)->rechargeAll(self::DATA);
    $count = 0;
    foreach ($channel as $key => $item) {
      msg::info("one: $key => {$item["a"]}");
      $count++;
    }
    self::assertSame(3, $count);
  }
}
