nur-sery/nur_tests/data/template/StreamTemplateTest.php

40 lines
914 B
PHP
Raw Permalink Normal View History

2023-12-03 22:11:29 +04:00
<?php
namespace nur\data\template;
use nur\b\io\StringWriter;
use PHPUnit\Framework\TestCase;
class StreamTemplateTest extends TestCase {
function testApply() {
$sw = new StringWriter();
$t = new MyTemplate($sw);
$t["texte"] = "truc";
$t->apply();
self::assertSame(
"Ceci est un TEST de truc\nqui bouge pas _et_ qui bouge\n",
$sw->getString()
);
$t["texte"] = "machin";
$t->apply();
self::assertSame(
"Ceci est un TEST de machin\nqui bouge pas _et_ qui bouge\n",
$sw->getString()
);
}
}
class MyTemplate extends StreamTemplate {
const INPUT = __DIR__ . "/StreamTemplateTest.txt";
const EXPRS = [
"TEXTE" => "texte",
"statique" => "::get_statique",
"dynamique" => "->getDynamique",
];
static function get_statique(): string {
return "qui bouge pas";
}
function getDynamique(): string {
return "qui bouge";
}
}