Update spec test to work with v1.0.0rc2 lambdas spec.
This commit is contained in:
@@ -62,21 +62,34 @@ class MustacheSpecTest extends PHPUnit_Framework_TestCase {
|
|||||||
* @dataProvider loadLambdasSpec
|
* @dataProvider loadLambdasSpec
|
||||||
*/
|
*/
|
||||||
public function testLambdasSpec($template, $data, $partials, $expected, $desc) {
|
public function testLambdasSpec($template, $data, $partials, $expected, $desc) {
|
||||||
if (!isset($data['lambda']['php'])) {
|
|
||||||
$this->markTestSkipped(sprintf('PHP lambda test not implemented for "%s".', $desc));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!version_compare(PHP_VERSION, '5.3.0', '>=')) {
|
if (!version_compare(PHP_VERSION, '5.3.0', '>=')) {
|
||||||
$this->markTestSkipped('Unable to test Lambdas spec with PHP < 5.3.');
|
$this->markTestSkipped('Unable to test Lambdas spec with PHP < 5.3.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$func = $data['lambda']['php'];
|
$data = $this->prepareLambdasSpec($data);
|
||||||
$data['lambda'] = function($text = null) use ($func) { return eval($func); };
|
|
||||||
|
|
||||||
$m = new Mustache($template, $data, $partials);
|
$m = new Mustache($template, $data, $partials);
|
||||||
$this->assertEquals($expected, $m->render(), $desc);
|
$this->assertEquals($expected, $m->render(), $desc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extract and lambdafy any 'lambda' values found in the $data array.
|
||||||
|
*/
|
||||||
|
protected function prepareLambdasSpec($data) {
|
||||||
|
foreach ($data as $key => $val) {
|
||||||
|
if ($key === 'lambda') {
|
||||||
|
if (!isset($val['php'])) {
|
||||||
|
$this->markTestSkipped(sprintf('PHP lambda test not implemented for this test.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
$func = $val['php'];
|
||||||
|
$data[$key] = function($text = null) use ($func) { return eval($func); };
|
||||||
|
} else if (is_array($val)) {
|
||||||
|
$data[$key] = $this->prepareLambdasSpec($val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @group partials
|
* @group partials
|
||||||
* @dataProvider loadPartialsSpec
|
* @dataProvider loadPartialsSpec
|
||||||
@@ -112,7 +125,7 @@ class MustacheSpecTest extends PHPUnit_Framework_TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function loadLambdasSpec() {
|
public function loadLambdasSpec() {
|
||||||
return $this->loadSpec('lambdas');
|
return $this->loadSpec('~lambdas');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function loadPartialsSpec() {
|
public function loadPartialsSpec() {
|
||||||
@@ -142,7 +155,7 @@ class MustacheSpecTest extends PHPUnit_Framework_TestCase {
|
|||||||
$file = file_get_contents($filename);
|
$file = file_get_contents($filename);
|
||||||
|
|
||||||
// @hack: pre-process the 'lambdas' spec so the Symfony YAML parser doesn't complain.
|
// @hack: pre-process the 'lambdas' spec so the Symfony YAML parser doesn't complain.
|
||||||
if ($name === 'lambdas') {
|
if ($name === '~lambdas') {
|
||||||
$file = str_replace(" !code\n", "\n", $file);
|
$file = str_replace(" !code\n", "\n", $file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user