40 lines
914 B
PHP
40 lines
914 B
PHP
|
<?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";
|
||
|
}
|
||
|
}
|