Segregate 5.3+ tests, exclude them from phpunit config.
This commit is contained in:
+2
-1
@@ -1,7 +1,8 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<phpunit backupGlobals="false" colors="true" bootstrap="./test/bootstrap.php">
|
<phpunit backupGlobals="false" colors="true" bootstrap="./test/bootstrap.php">
|
||||||
<testsuite name="Mustache">
|
<testsuite name="Mustache">
|
||||||
<directory>./test</directory>
|
<directory suffix="Test.php" phpVersion="5.3.0" phpVersionOperator=">=">./test/Mustache/Test/FiveThree</directory>
|
||||||
|
<directory suffix="Test.php">./test</directory>
|
||||||
</testsuite>
|
</testsuite>
|
||||||
|
|
||||||
<filter>
|
<filter>
|
||||||
|
|||||||
@@ -0,0 +1,71 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Mustache.php.
|
||||||
|
*
|
||||||
|
* (c) 2012 Justin Hileman
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group lambdas
|
||||||
|
* @group functional
|
||||||
|
*/
|
||||||
|
class Mustache_Test_FiveThree_Functional_HigherOrderSectionsTest extends PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
|
private $mustache;
|
||||||
|
|
||||||
|
public function setUp() {
|
||||||
|
$this->mustache = new Mustache_Mustache;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAnonymousFunctionSectionCallback() {
|
||||||
|
$tpl = $this->mustache->loadTemplate('{{#wrapper}}{{name}}{{/wrapper}}');
|
||||||
|
|
||||||
|
$foo = new Mustache_Test_FiveThree_Functional_Foo;
|
||||||
|
$foo->name = 'Mario';
|
||||||
|
$foo->wrapper = function($text) {
|
||||||
|
return sprintf('<div class="anonymous">%s</div>', $text);
|
||||||
|
};
|
||||||
|
|
||||||
|
$this->assertEquals(sprintf('<div class="anonymous">%s</div>', $foo->name), $tpl->render($foo));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSectionCallback() {
|
||||||
|
$one = $this->mustache->loadTemplate('{{name}}');
|
||||||
|
$two = $this->mustache->loadTemplate('{{#wrap}}{{name}}{{/wrap}}');
|
||||||
|
|
||||||
|
$foo = new Mustache_Test_FiveThree_Functional_Foo;
|
||||||
|
$foo->name = 'Luigi';
|
||||||
|
|
||||||
|
$this->assertEquals($foo->name, $one->render($foo));
|
||||||
|
$this->assertEquals(sprintf('<em>%s</em>', $foo->name), $two->render($foo));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testViewArrayAnonymousSectionCallback() {
|
||||||
|
$tpl = $this->mustache->loadTemplate('{{#wrap}}{{name}}{{/wrap}}');
|
||||||
|
|
||||||
|
$data = array(
|
||||||
|
'name' => 'Bob',
|
||||||
|
'wrap' => function($text) {
|
||||||
|
return sprintf('[[%s]]', $text);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertEquals(sprintf('[[%s]]', $data['name']), $tpl->render($data));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Mustache_Test_FiveThree_Functional_Foo {
|
||||||
|
public $name = 'Justin';
|
||||||
|
public $lorem = 'Lorem ipsum dolor sit amet,';
|
||||||
|
public $wrap;
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
$this->wrap = function($text) {
|
||||||
|
return sprintf('<em>%s</em>', $text);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,114 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Mustache.php.
|
||||||
|
*
|
||||||
|
* (c) 2012 Justin Hileman
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A PHPUnit test case wrapping the Mustache Spec
|
||||||
|
*
|
||||||
|
* @group mustache-spec
|
||||||
|
* @group functional
|
||||||
|
*/
|
||||||
|
class Mustache_Test_FiveThree_Functional_MustacheSpecTest extends PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
|
private static $mustache;
|
||||||
|
|
||||||
|
public static function setUpBeforeClass() {
|
||||||
|
self::$mustache = new Mustache_Mustache;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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() {
|
||||||
|
if (!file_exists(dirname(__FILE__).'/../../../../../vendor/spec/specs/')) {
|
||||||
|
$this->markTestSkipped('Mustache spec submodule not initialized: run "git submodule update --init"');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group lambdas
|
||||||
|
* @dataProvider loadLambdasSpec
|
||||||
|
*/
|
||||||
|
public function testLambdasSpec($desc, $source, $partials, $data, $expected) {
|
||||||
|
$template = self::loadTemplate($source, $partials);
|
||||||
|
$this->assertEquals($expected, $template($this->prepareLambdasSpec($data)), $desc);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function loadLambdasSpec() {
|
||||||
|
return $this->loadSpec('~lambdas');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extract and lambdafy any 'lambda' values found in the $data array.
|
||||||
|
*/
|
||||||
|
private 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data provider for the mustache spec test.
|
||||||
|
*
|
||||||
|
* Loads YAML files from the spec and converts them to PHPisms.
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function loadSpec($name) {
|
||||||
|
$filename = dirname(__FILE__) . '/../../../../../vendor/spec/specs/' . $name . '.yml';
|
||||||
|
if (!file_exists($filename)) {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
$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);
|
||||||
|
|
||||||
|
foreach ($spec['tests'] as $test) {
|
||||||
|
$data[] = array(
|
||||||
|
$test['name'] . ': ' . $test['desc'],
|
||||||
|
$test['template'],
|
||||||
|
isset($test['partials']) ? $test['partials'] : array(),
|
||||||
|
$test['data'],
|
||||||
|
$test['expected'],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function loadTemplate($source, $partials) {
|
||||||
|
self::$mustache->setPartials($partials);
|
||||||
|
|
||||||
|
return self::$mustache->loadTemplate($source);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -21,34 +21,6 @@ class Mustache_Test_Functional_HigherOrderSectionsTest extends PHPUnit_Framework
|
|||||||
$this->mustache = new Mustache_Mustache;
|
$this->mustache = new Mustache_Mustache;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAnonymousFunctionSectionCallback() {
|
|
||||||
if (version_compare(PHP_VERSION, '5.3.0', '<')) {
|
|
||||||
$this->markTestSkipped('Unable to test anonymous function section callbacks in PHP < 5.3');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$tpl = $this->mustache->loadTemplate('{{#wrapper}}{{name}}{{/wrapper}}');
|
|
||||||
|
|
||||||
$foo = new Mustache_Test_Functional_Foo;
|
|
||||||
$foo->name = 'Mario';
|
|
||||||
$foo->wrapper = function($text) {
|
|
||||||
return sprintf('<div class="anonymous">%s</div>', $text);
|
|
||||||
};
|
|
||||||
|
|
||||||
$this->assertEquals(sprintf('<div class="anonymous">%s</div>', $foo->name), $tpl->render($foo));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testSectionCallback() {
|
|
||||||
$one = $this->mustache->loadTemplate('{{name}}');
|
|
||||||
$two = $this->mustache->loadTemplate('{{#wrap}}{{name}}{{/wrap}}');
|
|
||||||
|
|
||||||
$foo = new Mustache_Test_Functional_Foo;
|
|
||||||
$foo->name = 'Luigi';
|
|
||||||
|
|
||||||
$this->assertEquals($foo->name, $one->render($foo));
|
|
||||||
$this->assertEquals(sprintf('<em>%s</em>', $foo->name), $two->render($foo));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testRuntimeSectionCallback() {
|
public function testRuntimeSectionCallback() {
|
||||||
$tpl = $this->mustache->loadTemplate('{{#doublewrap}}{{name}}{{/doublewrap}}');
|
$tpl = $this->mustache->loadTemplate('{{#doublewrap}}{{name}}{{/doublewrap}}');
|
||||||
|
|
||||||
@@ -80,19 +52,6 @@ class Mustache_Test_Functional_HigherOrderSectionsTest extends PHPUnit_Framework
|
|||||||
$this->assertEquals($data['name'], $tpl->render($data));
|
$this->assertEquals($data['name'], $tpl->render($data));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testViewArrayAnonymousSectionCallback() {
|
|
||||||
$tpl = $this->mustache->loadTemplate('{{#wrap}}{{name}}{{/wrap}}');
|
|
||||||
|
|
||||||
$data = array(
|
|
||||||
'name' => 'Bob',
|
|
||||||
'wrap' => function($text) {
|
|
||||||
return sprintf('[[%s]]', $text);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->assertEquals(sprintf('[[%s]]', $data['name']), $tpl->render($data));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testMonsters() {
|
public function testMonsters() {
|
||||||
$tpl = $this->mustache->loadTemplate('{{#title}}{{title}} {{/title}}{{name}}');
|
$tpl = $this->mustache->loadTemplate('{{#title}}{{title}} {{/title}}{{name}}');
|
||||||
|
|
||||||
@@ -111,13 +70,6 @@ class Mustache_Test_Functional_HigherOrderSectionsTest extends PHPUnit_Framework
|
|||||||
class Mustache_Test_Functional_Foo {
|
class Mustache_Test_Functional_Foo {
|
||||||
public $name = 'Justin';
|
public $name = 'Justin';
|
||||||
public $lorem = 'Lorem ipsum dolor sit amet,';
|
public $lorem = 'Lorem ipsum dolor sit amet,';
|
||||||
public $wrap;
|
|
||||||
|
|
||||||
public function __construct() {
|
|
||||||
$this->wrap = function($text) {
|
|
||||||
return sprintf('<em>%s</em>', $text);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public function wrapWithEm($text) {
|
public function wrapWithEm($text) {
|
||||||
return sprintf('<em>%s</em>', $text);
|
return sprintf('<em>%s</em>', $text);
|
||||||
|
|||||||
@@ -110,9 +110,7 @@ class Mustache_Test_Functional_MustacheInjectionTest extends PHPUnit_Framework_T
|
|||||||
$tpl = $this->mustache->loadTemplate('{{ a }}');
|
$tpl = $this->mustache->loadTemplate('{{ a }}');
|
||||||
|
|
||||||
$data = array(
|
$data = array(
|
||||||
'a' => function() {
|
'a' => array($this, 'lambdaInterpolationCallback'),
|
||||||
return '{{ b }}';
|
|
||||||
},
|
|
||||||
'b' => '{{ c }}',
|
'b' => '{{ c }}',
|
||||||
'c' => 'FAIL'
|
'c' => 'FAIL'
|
||||||
);
|
);
|
||||||
@@ -120,17 +118,23 @@ class Mustache_Test_Functional_MustacheInjectionTest extends PHPUnit_Framework_T
|
|||||||
$this->assertEquals('{{ c }}', $tpl->render($data));
|
$this->assertEquals('{{ c }}', $tpl->render($data));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function lambdaInterpolationCallback() {
|
||||||
|
return '{{ b }}';
|
||||||
|
}
|
||||||
|
|
||||||
public function testLambdaSectionInjection() {
|
public function testLambdaSectionInjection() {
|
||||||
$tpl = $this->mustache->loadTemplate('{{# a }}b{{/ a }}');
|
$tpl = $this->mustache->loadTemplate('{{# a }}b{{/ a }}');
|
||||||
|
|
||||||
$data = array(
|
$data = array(
|
||||||
'a' => function ($text) {
|
'a' => array($this, 'lambdaSectionCallback'),
|
||||||
return '{{ ' . $text . ' }}';
|
|
||||||
},
|
|
||||||
'b' => '{{ c }}',
|
'b' => '{{ c }}',
|
||||||
'c' => 'FAIL'
|
'c' => 'FAIL'
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals('{{ c }}', $tpl->render($data));
|
$this->assertEquals('{{ c }}', $tpl->render($data));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function lambdaSectionCallback($text) {
|
||||||
|
return '{{ ' . $text . ' }}';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,41 +86,6 @@ class Mustache_Test_Functional_MustacheSpecTest extends PHPUnit_Framework_TestCa
|
|||||||
return $this->loadSpec('inverted');
|
return $this->loadSpec('inverted');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @group lambdas
|
|
||||||
* @dataProvider loadLambdasSpec
|
|
||||||
*/
|
|
||||||
public function testLambdasSpec($desc, $source, $partials, $data, $expected) {
|
|
||||||
$template = self::loadTemplate($source, $partials);
|
|
||||||
$this->assertEquals($expected, $template($this->prepareLambdasSpec($data)), $desc);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function loadLambdasSpec() {
|
|
||||||
return $this->loadSpec('~lambdas');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Extract and lambdafy any 'lambda' values found in the $data array.
|
|
||||||
*/
|
|
||||||
private 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
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
class Mustache_Test_HelperCollectionTest extends PHPUnit_Framework_TestCase {
|
class Mustache_Test_HelperCollectionTest extends PHPUnit_Framework_TestCase {
|
||||||
public function testConstructor() {
|
public function testConstructor() {
|
||||||
$foo = function() { echo 'foo'; };
|
$foo = array($this, 'getFoo');
|
||||||
$bar = 'BAR';
|
$bar = 'BAR';
|
||||||
|
|
||||||
$helpers = new Mustache_HelperCollection(array(
|
$helpers = new Mustache_HelperCollection(array(
|
||||||
@@ -23,8 +23,12 @@ class Mustache_Test_HelperCollectionTest extends PHPUnit_Framework_TestCase {
|
|||||||
$this->assertSame($bar, $helpers->get('bar'));
|
$this->assertSame($bar, $helpers->get('bar'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getFoo() {
|
||||||
|
echo 'foo';
|
||||||
|
}
|
||||||
|
|
||||||
public function testAccessorsAndMutators() {
|
public function testAccessorsAndMutators() {
|
||||||
$foo = function() { echo 'foo'; };
|
$foo = array($this, 'getFoo');
|
||||||
$bar = 'BAR';
|
$bar = 'BAR';
|
||||||
|
|
||||||
$helpers = new Mustache_HelperCollection;
|
$helpers = new Mustache_HelperCollection;
|
||||||
@@ -49,7 +53,7 @@ class Mustache_Test_HelperCollectionTest extends PHPUnit_Framework_TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testMagicMethods() {
|
public function testMagicMethods() {
|
||||||
$foo = function() { echo 'foo'; };
|
$foo = array($this, 'getFoo');
|
||||||
$bar = 'BAR';
|
$bar = 'BAR';
|
||||||
|
|
||||||
$helpers = new Mustache_HelperCollection;
|
$helpers = new Mustache_HelperCollection;
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ class Mustache_Test_MustacheTest extends PHPUnit_Framework_TestCase {
|
|||||||
'foo' => '{{ foo }}',
|
'foo' => '{{ foo }}',
|
||||||
),
|
),
|
||||||
'helpers' => array(
|
'helpers' => array(
|
||||||
'foo' => function() { return 'foo'; },
|
'foo' => array($this, 'getFoo'),
|
||||||
'bar' => 'BAR',
|
'bar' => 'BAR',
|
||||||
),
|
),
|
||||||
'escape' => 'strtoupper',
|
'escape' => 'strtoupper',
|
||||||
@@ -53,6 +53,10 @@ class Mustache_Test_MustacheTest extends PHPUnit_Framework_TestCase {
|
|||||||
$this->assertFalse($mustache->hasHelper('baz'));
|
$this->assertFalse($mustache->hasHelper('baz'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getFoo() {
|
||||||
|
return 'foo';
|
||||||
|
}
|
||||||
|
|
||||||
public function testRender() {
|
public function testRender() {
|
||||||
$source = '{{ foo }}';
|
$source = '{{ foo }}';
|
||||||
$data = array('bar' => 'baz');
|
$data = array('bar' => 'baz');
|
||||||
@@ -158,7 +162,7 @@ class Mustache_Test_MustacheTest extends PHPUnit_Framework_TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testHelpers() {
|
public function testHelpers() {
|
||||||
$foo = function() { return 'foo'; };
|
$foo = array($this, 'getFoo');
|
||||||
$bar = 'BAR';
|
$bar = 'BAR';
|
||||||
$mustache = new Mustache_Mustache(array('helpers' => array(
|
$mustache = new Mustache_Mustache(array('helpers' => array(
|
||||||
'foo' => $foo,
|
'foo' => $foo,
|
||||||
@@ -178,7 +182,7 @@ class Mustache_Test_MustacheTest extends PHPUnit_Framework_TestCase {
|
|||||||
$mustache->addHelper('bar', $bar);
|
$mustache->addHelper('bar', $bar);
|
||||||
$this->assertSame($bar, $mustache->getHelper('bar'));
|
$this->assertSame($bar, $mustache->getHelper('bar'));
|
||||||
|
|
||||||
$baz = function($text) { return '__'.$text.'__'; };
|
$baz = array($this, 'wrapWithUnderscores');
|
||||||
$this->assertFalse($mustache->hasHelper('baz'));
|
$this->assertFalse($mustache->hasHelper('baz'));
|
||||||
$this->assertFalse($helpers->has('baz'));
|
$this->assertFalse($helpers->has('baz'));
|
||||||
|
|
||||||
@@ -192,6 +196,10 @@ class Mustache_Test_MustacheTest extends PHPUnit_Framework_TestCase {
|
|||||||
$this->assertEquals('foo - BAR - __qux__', $tpl->render(array('qux' => "won't mess things up")));
|
$this->assertEquals('foo - BAR - __qux__', $tpl->render(array('qux' => "won't mess things up")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function wrapWithUnderscores($text) {
|
||||||
|
return '__'.$text.'__';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \InvalidArgumentException
|
* @expectedException \InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user