nur-sery/nur_tests/mapper/item/AssocMapperTest.php

53 lines
1.2 KiB
PHP

<?php
namespace nur\mapper\item;
use nur\t\TestCase;
class AssocMapperTest extends TestCase {
const SOURCE = [
["nom", "prenom", "age"],
["clain", "jephté", "45"],
];
function testAssoc() {
$assoc = new Seq2AssocMapper(self::SOURCE);
self::assertSame(
[
["nom" => "clain", "prenom" => "jephté", "age" => "45"],
],
iterator_to_array($assoc)
);
$assoc = new Seq2AssocMapper(self::SOURCE);
$assoc->setParseKeys(false);
self::assertSame(
[
["nom", "prenom", "age"],
["clain", "jephté", "45"],
],
iterator_to_array($assoc)
);
$assoc = new Seq2AssocMapper(self::SOURCE);
$assoc->setParseKeys(false);
$assoc->setKeys(["nom", "prenom", "age"]);
self::assertSame(
[
["nom" => "nom", "prenom" => "prenom", "age" => "age"],
["nom" => "clain", "prenom" => "jephté", "age" => "45"],
],
iterator_to_array($assoc)
);
$assoc = new Seq2AssocMapper(self::SOURCE);
$assoc->setParseKeys(true);
$assoc->setKeys(["nom", "prenom", "age"]);
self::assertSame(
[
["nom" => "clain", "prenom" => "jephté", "age" => "45"],
],
iterator_to_array($assoc)
);
}
}