Refactor to remove strict callables test duplication.
This commit is contained in:
@@ -18,9 +18,9 @@ class Mustache_Test_FiveThree_Functional_StrictCallablesTest extends PHPUnit_Fra
|
|||||||
/**
|
/**
|
||||||
* @dataProvider callables
|
* @dataProvider callables
|
||||||
*/
|
*/
|
||||||
public function testStrictCallablesDisabled($name, $section, $expected)
|
public function testStrictCallables($strict, $name, $section, $expected)
|
||||||
{
|
{
|
||||||
$mustache = new Mustache_Engine(array('strict_callables' => false));
|
$mustache = new Mustache_Engine(array('strict_callables' => $strict));
|
||||||
$tpl = $mustache->loadTemplate('{{# section }}{{ name }}{{/ section }}');
|
$tpl = $mustache->loadTemplate('{{# section }}{{ name }}{{/ section }}');
|
||||||
|
|
||||||
$data = new StdClass;
|
$data = new StdClass;
|
||||||
@@ -39,16 +39,19 @@ class Mustache_Test_FiveThree_Functional_StrictCallablesTest extends PHPUnit_Fra
|
|||||||
return array(
|
return array(
|
||||||
// Interpolation lambdas
|
// Interpolation lambdas
|
||||||
array(
|
array(
|
||||||
|
false,
|
||||||
array($this, 'instanceName'),
|
array($this, 'instanceName'),
|
||||||
$lambda,
|
$lambda,
|
||||||
'YOSHI',
|
'YOSHI',
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
|
false,
|
||||||
array(__CLASS__, 'staticName'),
|
array(__CLASS__, 'staticName'),
|
||||||
$lambda,
|
$lambda,
|
||||||
'YOSHI',
|
'YOSHI',
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
|
false,
|
||||||
function () { return 'Yoshi'; },
|
function () { return 'Yoshi'; },
|
||||||
$lambda,
|
$lambda,
|
||||||
'YOSHI',
|
'YOSHI',
|
||||||
@@ -56,64 +59,47 @@ class Mustache_Test_FiveThree_Functional_StrictCallablesTest extends PHPUnit_Fra
|
|||||||
|
|
||||||
// Section lambdas
|
// Section lambdas
|
||||||
array(
|
array(
|
||||||
|
false,
|
||||||
'Yoshi',
|
'Yoshi',
|
||||||
array($this, 'instanceCallable'),
|
array($this, 'instanceCallable'),
|
||||||
'YOSHI',
|
'YOSHI',
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
|
false,
|
||||||
'Yoshi',
|
'Yoshi',
|
||||||
array(__CLASS__, 'staticCallable'),
|
array(__CLASS__, 'staticCallable'),
|
||||||
'YOSHI',
|
'YOSHI',
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
|
false,
|
||||||
'Yoshi',
|
'Yoshi',
|
||||||
$lambda,
|
$lambda,
|
||||||
'YOSHI',
|
'YOSHI',
|
||||||
),
|
),
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
// Strict interpolation lambdas
|
||||||
* @dataProvider strictCallables
|
|
||||||
*/
|
|
||||||
public function testStrictCallablesEnabled($name, $section, $expected)
|
|
||||||
{
|
|
||||||
$mustache = new Mustache_Engine(array('strict_callables' => true));
|
|
||||||
$tpl = $mustache->loadTemplate('{{# section }}{{ name }}{{/ section }}');
|
|
||||||
|
|
||||||
$data = new StdClass;
|
|
||||||
$data->name = $name;
|
|
||||||
$data->section = $section;
|
|
||||||
|
|
||||||
$this->assertEquals($expected, $tpl->render($data));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function strictCallables()
|
|
||||||
{
|
|
||||||
$lambda = function ($tpl, $mustache) {
|
|
||||||
return strtoupper($mustache->render($tpl));
|
|
||||||
};
|
|
||||||
|
|
||||||
return array(
|
|
||||||
// Interpolation lambdas
|
|
||||||
array(
|
array(
|
||||||
|
true,
|
||||||
function () { return 'Yoshi'; },
|
function () { return 'Yoshi'; },
|
||||||
$lambda,
|
$lambda,
|
||||||
'YOSHI',
|
'YOSHI',
|
||||||
),
|
),
|
||||||
|
|
||||||
// Section lambdas
|
// Strict section lambdas
|
||||||
array(
|
array(
|
||||||
|
true,
|
||||||
'Yoshi',
|
'Yoshi',
|
||||||
array($this, 'instanceCallable'),
|
array($this, 'instanceCallable'),
|
||||||
'YoshiYoshi',
|
'YoshiYoshi',
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
|
true,
|
||||||
'Yoshi',
|
'Yoshi',
|
||||||
array(__CLASS__, 'staticCallable'),
|
array(__CLASS__, 'staticCallable'),
|
||||||
'YoshiYoshi',
|
'YoshiYoshi',
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
|
true,
|
||||||
'Yoshi',
|
'Yoshi',
|
||||||
function ($tpl, $mustache) {
|
function ($tpl, $mustache) {
|
||||||
return strtoupper($mustache->render($tpl));
|
return strtoupper($mustache->render($tpl));
|
||||||
|
|||||||
Reference in New Issue
Block a user