Fix whitespace in a few test files (PSR-2)

This commit is contained in:
Justin Hileman
2012-07-27 17:58:55 -07:00
parent 9e436f8c07
commit 169e6e0a1f
3 changed files with 123 additions and 123 deletions
@@ -15,57 +15,57 @@
*/ */
class Mustache_Test_FiveThree_Functional_HigherOrderSectionsTest extends PHPUnit_Framework_TestCase { class Mustache_Test_FiveThree_Functional_HigherOrderSectionsTest extends PHPUnit_Framework_TestCase {
private $mustache; private $mustache;
public function setUp() { public function setUp() {
$this->mustache = new Mustache_Engine; $this->mustache = new Mustache_Engine;
} }
public function testAnonymousFunctionSectionCallback() { public function testAnonymousFunctionSectionCallback() {
$tpl = $this->mustache->loadTemplate('{{#wrapper}}{{name}}{{/wrapper}}'); $tpl = $this->mustache->loadTemplate('{{#wrapper}}{{name}}{{/wrapper}}');
$foo = new Mustache_Test_FiveThree_Functional_Foo; $foo = new Mustache_Test_FiveThree_Functional_Foo;
$foo->name = 'Mario'; $foo->name = 'Mario';
$foo->wrapper = function($text) { $foo->wrapper = function($text) {
return sprintf('<div class="anonymous">%s</div>', $text); return sprintf('<div class="anonymous">%s</div>', $text);
}; };
$this->assertEquals(sprintf('<div class="anonymous">%s</div>', $foo->name), $tpl->render($foo)); $this->assertEquals(sprintf('<div class="anonymous">%s</div>', $foo->name), $tpl->render($foo));
} }
public function testSectionCallback() { public function testSectionCallback() {
$one = $this->mustache->loadTemplate('{{name}}'); $one = $this->mustache->loadTemplate('{{name}}');
$two = $this->mustache->loadTemplate('{{#wrap}}{{name}}{{/wrap}}'); $two = $this->mustache->loadTemplate('{{#wrap}}{{name}}{{/wrap}}');
$foo = new Mustache_Test_FiveThree_Functional_Foo; $foo = new Mustache_Test_FiveThree_Functional_Foo;
$foo->name = 'Luigi'; $foo->name = 'Luigi';
$this->assertEquals($foo->name, $one->render($foo)); $this->assertEquals($foo->name, $one->render($foo));
$this->assertEquals(sprintf('<em>%s</em>', $foo->name), $two->render($foo)); $this->assertEquals(sprintf('<em>%s</em>', $foo->name), $two->render($foo));
} }
public function testViewArrayAnonymousSectionCallback() { public function testViewArrayAnonymousSectionCallback() {
$tpl = $this->mustache->loadTemplate('{{#wrap}}{{name}}{{/wrap}}'); $tpl = $this->mustache->loadTemplate('{{#wrap}}{{name}}{{/wrap}}');
$data = array( $data = array(
'name' => 'Bob', 'name' => 'Bob',
'wrap' => function($text) { 'wrap' => function($text) {
return sprintf('[[%s]]', $text); return sprintf('[[%s]]', $text);
} }
); );
$this->assertEquals(sprintf('[[%s]]', $data['name']), $tpl->render($data)); $this->assertEquals(sprintf('[[%s]]', $data['name']), $tpl->render($data));
} }
} }
class Mustache_Test_FiveThree_Functional_Foo { class Mustache_Test_FiveThree_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 $wrap;
public function __construct() { public function __construct() {
$this->wrap = function($text) { $this->wrap = function($text) {
return sprintf('<em>%s</em>', $text); return sprintf('<em>%s</em>', $text);
}; };
} }
} }
@@ -17,98 +17,98 @@
*/ */
class Mustache_Test_FiveThree_Functional_MustacheSpecTest extends PHPUnit_Framework_TestCase { class Mustache_Test_FiveThree_Functional_MustacheSpecTest extends PHPUnit_Framework_TestCase {
private static $mustache; private static $mustache;
public static function setUpBeforeClass() { public static function setUpBeforeClass() {
self::$mustache = new Mustache_Engine; self::$mustache = new Mustache_Engine;
} }
/** /**
* For some reason data providers can't mark tests skipped, so this test exists * 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. * simply to provide a 'skipped' test if the `spec` submodule isn't initialized.
*/ */
public function testSpecInitialized() { public function testSpecInitialized() {
if (!file_exists(dirname(__FILE__).'/../../../../../vendor/spec/specs/')) { if (!file_exists(dirname(__FILE__).'/../../../../../vendor/spec/specs/')) {
$this->markTestSkipped('Mustache spec submodule not initialized: run "git submodule update --init"'); $this->markTestSkipped('Mustache spec submodule not initialized: run "git submodule update --init"');
} }
} }
/** /**
* @group lambdas * @group lambdas
* @dataProvider loadLambdasSpec * @dataProvider loadLambdasSpec
*/ */
public function testLambdasSpec($desc, $source, $partials, $data, $expected) { public function testLambdasSpec($desc, $source, $partials, $data, $expected) {
$template = self::loadTemplate($source, $partials); $template = self::loadTemplate($source, $partials);
$this->assertEquals($expected, $template($this->prepareLambdasSpec($data)), $desc); $this->assertEquals($expected, $template($this->prepareLambdasSpec($data)), $desc);
} }
public function loadLambdasSpec() { public function loadLambdasSpec() {
return $this->loadSpec('~lambdas'); return $this->loadSpec('~lambdas');
} }
/** /**
* Extract and lambdafy any 'lambda' values found in the $data array. * Extract and lambdafy any 'lambda' values found in the $data array.
*/ */
private function prepareLambdasSpec($data) { private function prepareLambdasSpec($data) {
foreach ($data as $key => $val) { foreach ($data as $key => $val) {
if ($key === 'lambda') { if ($key === 'lambda') {
if (!isset($val['php'])) { if (!isset($val['php'])) {
$this->markTestSkipped(sprintf('PHP lambda test not implemented for this test.')); $this->markTestSkipped(sprintf('PHP lambda test not implemented for this test.'));
} }
$func = $val['php']; $func = $val['php'];
$data[$key] = function($text = null) use ($func) { $data[$key] = function($text = null) use ($func) {
return eval($func); return eval($func);
}; };
} else if (is_array($val)) { } elseif (is_array($val)) {
$data[$key] = $this->prepareLambdasSpec($val); $data[$key] = $this->prepareLambdasSpec($val);
} }
} }
return $data; return $data;
} }
/** /**
* Data provider for the mustache spec test. * Data provider for the mustache spec test.
* *
* Loads YAML files from the spec and converts them to PHPisms. * Loads YAML files from the spec and converts them to PHPisms.
* *
* @access public * @access public
* @return array * @return array
*/ */
private function loadSpec($name) { private function loadSpec($name) {
$filename = dirname(__FILE__) . '/../../../../../vendor/spec/specs/' . $name . '.yml'; $filename = dirname(__FILE__) . '/../../../../../vendor/spec/specs/' . $name . '.yml';
if (!file_exists($filename)) { if (!file_exists($filename)) {
return array(); return array();
} }
$data = array(); $data = array();
$yaml = new sfYamlParser; $yaml = new sfYamlParser;
$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);
} }
$spec = $yaml->parse($file); $spec = $yaml->parse($file);
foreach ($spec['tests'] as $test) { foreach ($spec['tests'] as $test) {
$data[] = array( $data[] = array(
$test['name'] . ': ' . $test['desc'], $test['name'] . ': ' . $test['desc'],
$test['template'], $test['template'],
isset($test['partials']) ? $test['partials'] : array(), isset($test['partials']) ? $test['partials'] : array(),
$test['data'], $test['data'],
$test['expected'], $test['expected'],
); );
} }
return $data; return $data;
} }
private static function loadTemplate($source, $partials) { private static function loadTemplate($source, $partials) {
self::$mustache->setPartials($partials); self::$mustache->setPartials($partials);
return self::$mustache->loadTemplate($source); return self::$mustache->loadTemplate($source);
} }
} }
+5 -5
View File
@@ -1,9 +1,9 @@
<?php <?php
class Partials { class Partials {
public $page = array( public $page = array(
'title' => 'Page Title', 'title' => 'Page Title',
'subtitle' => 'Page Subtitle', 'subtitle' => 'Page Subtitle',
'content' => 'Lorem ipsum dolor sit amet.', 'content' => 'Lorem ipsum dolor sit amet.',
); );
} }