浏览代码

Enable (and fix) lambdas spec test.

This requires the not-yet-committed PHP version of the lambdas spec to actually do anything besides skip some more tests. But trust me, once you see these hot new lambda spec tests, it'll be a *lot* more interesting.
Justin Hileman 15 年之前
父节点
当前提交
65d6b5a638
共有 1 个文件被更改,包括 36 次插入20 次删除
  1. 36 20
      test/MustacheSpecTest.php

+ 36 - 20
test/MustacheSpecTest.php

@@ -57,20 +57,25 @@ class MustacheSpecTest extends PHPUnit_Framework_TestCase {
 		$this->assertEquals($expected, $m->render(), $desc);
 	}
 
-	// /**
-	//  * @group lambdas
-	//  * @dataProvider loadLambdasSpec
-	//  */
-	// public function testLambdasSpec($template, $data, $partials, $expected, $desc) {
-	// 	$this->markTestSkipped("Lambdas for PHP haven't made it into the spec yet, so we'll skip them to avoid a bajillion failed tests.");
-	//
-	// 	if (!version_compare(PHP_VERSION, '5.3.0', '>=')) {
-	// 		$this->markTestSkipped('Unable to test Lambdas spec with PHP < 5.3.');
-	// 	}
-	//
-	// 	$m = new Mustache($template, $data, $partials);
-	// 	$this->assertEquals($expected, $m->render(), $desc);
-	// }
+	/**
+	 * @group lambdas
+	 * @dataProvider loadLambdasSpec
+	 */
+	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', '>=')) {
+			$this->markTestSkipped('Unable to test Lambdas spec with PHP < 5.3.');
+		}
+
+		$func = $data['lambda']['php'];
+		$data['lambda'] = function($text = null) use ($func) { return eval($func); };
+
+		$m = new Mustache($template, $data, $partials);
+		$this->assertEquals($expected, $m->render(), $desc);
+	}
 
 	/**
 	 * @group partials
@@ -106,9 +111,9 @@ class MustacheSpecTest extends PHPUnit_Framework_TestCase {
 		return $this->loadSpec('inverted');
 	}
 
-	// public function loadLambdasSpec() {
-	// 	return $this->loadSpec('lambdas');
-	// }
+	public function loadLambdasSpec() {
+	 return $this->loadSpec('lambdas');
+	}
 
 	public function loadPartialsSpec() {
 		return $this->loadSpec('partials');
@@ -133,12 +138,23 @@ class MustacheSpecTest extends PHPUnit_Framework_TestCase {
 		}
 
 		$data = array();
-
 		$yaml = new sfYamlParser();
+		$file = file_get_contents($filename);
+
+		// @hack: pre-process the 'lambdas' spec so the Symfony YAML parser doesn't complain.
+		if ($name === 'lambdas') {
+			$file = str_replace(" !code\n", "\n", $file);
+		}
 
-		$spec = $yaml->parse(file_get_contents($filename));
+		$spec = $yaml->parse($file);
 		foreach ($spec['tests'] as $test) {
-			$data[] = array($test['template'], $test['data'], isset($test['partials']) ? $test['partials'] : array(), $test['expected'], $test['desc']);
+			$data[] = array(
+				$test['template'],
+				$test['data'],
+				isset($test['partials']) ? $test['partials'] : array(),
+				$test['expected'],
+				$test['desc']
+			);
 		}
 		return $data;
 	}