<?php
namespace nur\mapper\item;

use nur\mapper\base\Consumer;
use nur\t\TestCase;

class AttributeFilterMapperTest extends TestCase {
  const SOURCE = [
    ["nom", "prenom", "age"],
    ["clain", "jephté", "45"],
    ["clain", "françoise", "53"],
    ["payet", "eddy", "32"],
  ];

  function testFilter() {
    $consumer = new class extends Consumer {
      public $result = [];
      function cook($item) {
        $this->result[] = $item;
      }
    };
    $consumer->consume(self::SOURCE,
      Seq2AssocMapper::class,
      [SchemaMapper::class, [
        "nom" => "string",
        "prenom" => "string",
        "age" => "int",
      ]],
      [ItemFilterMapper::class, "skip_items" => 1, "max_count" => 1],
      [AttributeFilterMapper::class, [
        "nom",
        "middle" => 5,
        "age",
      ]]);
    self::assertSame([
      ["nom" => "clain", "middle" => 5, "age" => 53],
    ], $consumer->result);
  }
}
