Adding test support for the mustache spec.
To run the spec tests, you must initialize the spec submodule:
git submodule update --init
You can then run just spec tests, if that's the sort of thing you're into:
cd test
phpunit --filter Spec
This test currently skips Lambdas -- the Mustache.php implementation is still in a feature branch. It also skips recursive partials to keep [issue #11](http://hile.mn/bYIIYt) from breaking PHPUnit with infinite recursion.
This commit is contained in:
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
|
||||
require_once '../Mustache.php';
|
||||
require_once './lib/spyc.php';
|
||||
|
||||
/**
|
||||
* A PHPUnit test case wrapping the Mustache Spec
|
||||
*/
|
||||
class MustacheSpecTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
/**
|
||||
* For some reason data providers can't mark tests skipped, so this test exists
|
||||
* simply to provide a 'skipped' test if the `spec` submodule isn't initialized.
|
||||
*/
|
||||
public function testSpecInitialized() {
|
||||
$spec_dir = dirname(__FILE__) . '/spec/specs/';
|
||||
if (!file_exists($spec_dir)) {
|
||||
$this->markTestSkipped('Mustache spec submodule not initialized: run "git submodule update --init"');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider loadCommentSpec
|
||||
*/
|
||||
public function testCommentSpec($template, $data, $partials, $expected, $desc) {
|
||||
$m = new Mustache($template, $data, $partials);
|
||||
$this->assertEquals($expected, $m->render(), $desc);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider loadDelimitersSpec
|
||||
*/
|
||||
public function testDelimitersSpec($template, $data, $partials, $expected, $desc) {
|
||||
$m = new Mustache($template, $data, $partials);
|
||||
$this->assertEquals($expected, $m->render(), $desc);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider loadInterpolationSpec
|
||||
*/
|
||||
public function testInterpolationSpec($template, $data, $partials, $expected, $desc) {
|
||||
$m = new Mustache($template, $data, $partials);
|
||||
$this->assertEquals($expected, $m->render(), $desc);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider loadInvertedSpec
|
||||
*/
|
||||
public function testInvertedSpec($template, $data, $partials, $expected, $desc) {
|
||||
$m = new Mustache($template, $data, $partials);
|
||||
$this->assertEquals($expected, $m->render(), $desc);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider loadPartialsSpec
|
||||
*/
|
||||
public function testPartialsSpec($template, $data, $partials, $expected, $desc) {
|
||||
// skip partial recursion tests, see: http://hile.mn/bYIIYt
|
||||
if (strpos($desc, 'recurse') !== false) {
|
||||
$this->markTestSkipped('Mustache.php has an issue with recursive partials. See http://hile.mn/bYIIYt');
|
||||
}
|
||||
$m = new Mustache($template, $data, $partials);
|
||||
$this->assertEquals($expected, $m->render(), $desc);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider loadSectionsSpec
|
||||
*/
|
||||
public function testSectionsSpec($template, $data, $partials, $expected, $desc) {
|
||||
$m = new Mustache($template, $data, $partials);
|
||||
$this->assertEquals($expected, $m->render(), $desc);
|
||||
}
|
||||
|
||||
public function loadCommentSpec() {
|
||||
return $this->loadSpec('comments');
|
||||
}
|
||||
|
||||
public function loadDelimitersSpec() {
|
||||
return $this->loadSpec('delimiters');
|
||||
}
|
||||
|
||||
public function loadInterpolationSpec() {
|
||||
return $this->loadSpec('interpolation');
|
||||
}
|
||||
|
||||
public function loadInvertedSpec() {
|
||||
return $this->loadSpec('inverted');
|
||||
}
|
||||
|
||||
public function loadLambdasSpec() {
|
||||
return $this->loadSpec('lambdas');
|
||||
}
|
||||
|
||||
public function loadPartialsSpec() {
|
||||
return $this->loadSpec('partials');
|
||||
}
|
||||
|
||||
public function loadSectionsSpec() {
|
||||
return $this->loadSpec('sections');
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for the mustache spec test.
|
||||
*
|
||||
* Loads YAML files from the spec and converts them to PHPisms.
|
||||
*
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
protected function loadSpec($name) {
|
||||
$filename = dirname(__FILE__) . '/spec/specs/' . $name . '.yml';
|
||||
if (!file_exists($filename)) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$data = array();
|
||||
|
||||
$spec = spyc_load_file($filename);
|
||||
foreach ($spec['tests'] as $test) {
|
||||
$data[] = array($test['template'], $test['data'], isset($test['partials']) ? $test['partials'] : array(), $test['expected'], $test['desc']);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
+1024
File diff suppressed because it is too large
Load Diff
Submodule
+1
Submodule test/spec added at 2d9859f72c
Reference in New Issue
Block a user