Add support for PHP 5.2.x

This commit is contained in:
Justin Hileman
2012-03-17 23:05:52 -07:00
parent 99ff7316b3
commit bec9ce8448
34 changed files with 330 additions and 473 deletions
+4 -8
View File
@@ -9,21 +9,17 @@
* file that was distributed with this source code.
*/
namespace Mustache\Test\Functional;
use Mustache\Mustache;
/**
* @group magic_methods
* @group functional
*/
class CallTest extends \PHPUnit_Framework_TestCase {
class Mustache_Test_Functional_CallTest extends PHPUnit_Framework_TestCase {
public function testCallEatsContext() {
$m = new Mustache;
$m = new Mustache_Mustache;
$tpl = $m->loadTemplate('{{# foo }}{{ label }}: {{ name }}{{/ foo }}');
$foo = new ClassWithCall();
$foo = new Mustache_Test_Functional_ClassWithCall();
$foo->name = 'Bob';
$data = array('label' => 'name', 'foo' => $foo);
@@ -32,7 +28,7 @@ class CallTest extends \PHPUnit_Framework_TestCase {
}
}
class ClassWithCall {
class Mustache_Test_Functional_ClassWithCall {
public $name;
public function __call($method, $args) {
return 'unknown value';
@@ -9,15 +9,11 @@
* file that was distributed with this source code.
*/
namespace Mustache\Test\Functional;
use Mustache\Mustache;
/**
* @group examples
* @group functional
*/
class ExamplesTest extends \PHPUnit_Framework_TestCase {
class Mustache_Test_Functional_ExamplesTest extends PHPUnit_Framework_TestCase {
/**
* Test everything in the `examples` directory.
@@ -30,7 +26,7 @@ class ExamplesTest extends \PHPUnit_Framework_TestCase {
* @param string $expected
*/
public function testExamples($context, $source, $partials, $expected) {
$mustache = new Mustache(array(
$mustache = new Mustache_Mustache(array(
'partials' => $partials
));
$this->assertEquals($expected, $mustache->loadTemplate($source)->render($context));
@@ -9,26 +9,22 @@
* file that was distributed with this source code.
*/
namespace Mustache\Test\Functional;
use Mustache\Mustache;
/**
* @group lambdas
* @group functional
*/
class HigherOrderSectionsTest extends \PHPUnit_Framework_TestCase {
class Mustache_Test_Functional_HigherOrderSectionsTest extends PHPUnit_Framework_TestCase {
private $mustache;
public function setUp() {
$this->mustache = new Mustache;
$this->mustache = new Mustache_Mustache;
}
public function testAnonymousFunctionSectionCallback() {
$tpl = $this->mustache->loadTemplate('{{#wrapper}}{{name}}{{/wrapper}}');
$foo = new Foo;
$foo = new Mustache_Test_Functional_Foo;
$foo->name = 'Mario';
$foo->wrapper = function($text) {
return sprintf('<div class="anonymous">%s</div>', $text);
@@ -41,7 +37,7 @@ class HigherOrderSectionsTest extends \PHPUnit_Framework_TestCase {
$one = $this->mustache->loadTemplate('{{name}}');
$two = $this->mustache->loadTemplate('{{#wrap}}{{name}}{{/wrap}}');
$foo = new Foo;
$foo = new Mustache_Test_Functional_Foo;
$foo->name = 'Luigi';
$this->assertEquals($foo->name, $one->render($foo));
@@ -51,7 +47,7 @@ class HigherOrderSectionsTest extends \PHPUnit_Framework_TestCase {
public function testRuntimeSectionCallback() {
$tpl = $this->mustache->loadTemplate('{{#doublewrap}}{{name}}{{/doublewrap}}');
$foo = new Foo;
$foo = new Mustache_Test_Functional_Foo;
$foo->doublewrap = array($foo, 'wrapWithBoth');
$this->assertEquals(sprintf('<strong><em>%s</em></strong>', $foo->name), $tpl->render($foo));
@@ -60,7 +56,7 @@ class HigherOrderSectionsTest extends \PHPUnit_Framework_TestCase {
public function testStaticSectionCallback() {
$tpl = $this->mustache->loadTemplate('{{#trimmer}} {{name}} {{/trimmer}}');
$foo = new Foo;
$foo = new Mustache_Test_Functional_Foo;
$foo->trimmer = array(get_class($foo), 'staticTrim');
$this->assertEquals($foo->name, $tpl->render($foo));
@@ -69,7 +65,7 @@ class HigherOrderSectionsTest extends \PHPUnit_Framework_TestCase {
public function testViewArraySectionCallback() {
$tpl = $this->mustache->loadTemplate('{{#trim}} {{name}} {{/trim}}');
$foo = new Foo;
$foo = new Mustache_Test_Functional_Foo;
$data = array(
'name' => 'Bob',
@@ -95,19 +91,19 @@ class HigherOrderSectionsTest extends \PHPUnit_Framework_TestCase {
public function testMonsters() {
$tpl = $this->mustache->loadTemplate('{{#title}}{{title}} {{/title}}{{name}}');
$frank = new Monster();
$frank = new Mustache_Test_Functional_Monster();
$frank->title = 'Dr.';
$frank->name = 'Frankenstein';
$this->assertEquals('Dr. Frankenstein', $tpl->render($frank));
$dracula = new Monster();
$dracula = new Mustache_Test_Functional_Monster();
$dracula->title = 'Count';
$dracula->name = 'Dracula';
$this->assertEquals('Count Dracula', $tpl->render($dracula));
}
}
class Foo {
class Mustache_Test_Functional_Foo {
public $name = 'Justin';
public $lorem = 'Lorem ipsum dolor sit amet,';
public $wrap;
@@ -135,7 +131,7 @@ class Foo {
}
}
class Monster {
class Mustache_Test_Functional_Monster {
public $title;
public $name;
}
@@ -9,20 +9,16 @@
* file that was distributed with this source code.
*/
namespace Mustache\Test\Functional;
use Mustache\Mustache;
/**
* @group mustache_injection
* @group functional
*/
class MustacheInjectionTest extends \PHPUnit_Framework_TestCase {
class Mustache_Test_Functional_MustacheInjectionTest extends PHPUnit_Framework_TestCase {
private $mustache;
public function setUp() {
$this->mustache = new Mustache;
$this->mustache = new Mustache_Mustache;
}
// interpolation
@@ -9,23 +9,18 @@
* file that was distributed with this source code.
*/
namespace Mustache\Test\Functional;
use Mustache\Mustache;
use Mustache\Loader\StringLoader;
/**
* A PHPUnit test case wrapping the Mustache Spec
*
* @group mustache-spec
* @group functional
*/
class MustacheSpecTest extends \PHPUnit_Framework_TestCase {
class Mustache_Test_Functional_MustacheSpecTest extends PHPUnit_Framework_TestCase {
private static $mustache;
public static function setUpBeforeClass() {
self::$mustache = new Mustache;
self::$mustache = new Mustache_Mustache;
}
/**
@@ -167,7 +162,7 @@ class MustacheSpecTest extends \PHPUnit_Framework_TestCase {
}
$data = array();
$yaml = new \sfYamlParser;
$yaml = new sfYamlParser;
$file = file_get_contents($filename);
// @hack: pre-process the 'lambdas' spec so the Symfony YAML parser doesn't complain.
@@ -9,24 +9,20 @@
* file that was distributed with this source code.
*/
namespace Mustache\Test\Functional;
use Mustache\Mustache;
/**
* @group sections
* @group functional
*/
class ObjectSectionTest extends \PHPUnit_Framework_TestCase {
class Mustache_Test_Functional_ObjectSectionTest extends PHPUnit_Framework_TestCase {
private $mustache;
public function setUp() {
$this->mustache = new Mustache;
$this->mustache = new Mustache_Mustache;
}
public function testBasicObject() {
$tpl = $this->mustache->loadTemplate('{{#foo}}{{name}}{{/foo}}');
$this->assertEquals('Foo', $tpl->render(new Alpha));
$this->assertEquals('Foo', $tpl->render(new Mustache_Test_Functional_Alpha));
}
/**
@@ -34,7 +30,7 @@ class ObjectSectionTest extends \PHPUnit_Framework_TestCase {
*/
public function testObjectWithGet() {
$tpl = $this->mustache->loadTemplate('{{#foo}}{{name}}{{/foo}}');
$this->assertEquals('Foo', $tpl->render(new Beta));
$this->assertEquals('Foo', $tpl->render(new Mustache_Test_Functional_Beta));
}
/**
@@ -42,32 +38,32 @@ class ObjectSectionTest extends \PHPUnit_Framework_TestCase {
*/
public function testSectionObjectWithGet() {
$tpl = $this->mustache->loadTemplate('{{#bar}}{{#foo}}{{name}}{{/foo}}{{/bar}}');
$this->assertEquals('Foo', $tpl->render(new Gamma));
$this->assertEquals('Foo', $tpl->render(new Mustache_Test_Functional_Gamma));
}
public function testSectionObjectWithFunction() {
$tpl = $this->mustache->loadTemplate('{{#foo}}{{name}}{{/foo}}');
$alpha = new Alpha;
$alpha->foo = new Delta;
$alpha = new Mustache_Test_Functional_Alpha;
$alpha->foo = new Mustache_Test_Functional_Delta;
$this->assertEquals('Foo', $tpl->render($alpha));
}
}
class Alpha {
class Mustache_Test_Functional_Alpha {
public $foo;
public function __construct() {
$this->foo = new \StdClass();
$this->foo = new StdClass();
$this->foo->name = 'Foo';
$this->foo->number = 1;
}
}
class Beta {
class Mustache_Test_Functional_Beta {
protected $_data = array();
public function __construct() {
$this->_data['foo'] = new \StdClass();
$this->_data['foo'] = new StdClass();
$this->_data['foo']->name = 'Foo';
$this->_data['foo']->number = 1;
}
@@ -81,15 +77,15 @@ class Beta {
}
}
class Gamma {
class Mustache_Test_Functional_Gamma {
public $bar;
public function __construct() {
$this->bar = new Beta();
$this->bar = new Mustache_Test_Functional_Beta;
}
}
class Delta {
class Mustache_Test_Functional_Delta {
protected $_name = 'Foo';
public function name() {