コード例 #1
0
    $t->fail('->__get() throws an InvalidArgumentException if the helper is not defined');
} catch (InvalidArgumentException $e) {
    $t->pass('->__get() throws an InvalidArgumentException if the helper is not defined');
}
// ->get() ->set() ->has()
$t->diag('->get() ->set() ->has()');
$engine = new ProjectTemplateEngine($loader);
$engine->set('foo', 'bar');
$t->is($engine->get('foo'), 'bar', '->set() sets a slot value');
$t->is($engine->get('bar', 'bar'), 'bar', '->get() takes a default value to return if the slot does not exist');
$t->ok($engine->has('foo'), '->has() returns true if the slot exists');
$t->ok(!$engine->has('bar'), '->has() returns false if the slot does not exist');
// ->output()
$t->diag('->output()');
ob_start();
$ret = $engine->output('foo');
$output = ob_get_clean();
$t->is($output, 'bar', '->output() outputs the content of a slot');
$t->is($ret, true, '->output() returns true if the slot exists');
ob_start();
$ret = $engine->output('bar', 'bar');
$output = ob_get_clean();
$t->is($output, 'bar', '->output() takes a default value to return if the slot does not exist');
$t->is($ret, true, '->output() returns true if the slot does not exist but a default value is provided');
ob_start();
$ret = $engine->output('bar');
$output = ob_get_clean();
$t->is($output, '', '->output() outputs nothing if the slot does not exist');
$t->is($ret, false, '->output() returns false if the slot does not exist');
// ->start() ->stop()
$t->diag('->start() ->stop()');