Coding standards fixes.

This commit is contained in:
Justin Hileman
2012-08-02 10:36:07 -07:00
parent 345a0c45f7
commit 277288137b
6 changed files with 35 additions and 23 deletions
+2 -1
View File
@@ -244,7 +244,8 @@ class Mustache_Test_EngineTest extends PHPUnit_Framework_TestCase
} }
} }
class MustacheStub extends Mustache_Engine { class MustacheStub extends Mustache_Engine
{
public $source; public $source;
public $template; public $template;
public function loadTemplate($source) public function loadTemplate($source)
@@ -13,15 +13,17 @@
* @group lambdas * @group lambdas
* @group functional * @group functional
*/ */
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;
@@ -33,7 +35,8 @@ class Mustache_Test_FiveThree_Functional_HigherOrderSectionsTest extends PHPUnit
$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}}');
@@ -44,7 +47,8 @@ class Mustache_Test_FiveThree_Functional_HigherOrderSectionsTest extends PHPUnit
$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(
@@ -58,12 +62,14 @@ class Mustache_Test_FiveThree_Functional_HigherOrderSectionsTest extends PHPUnit
} }
} }
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);
}; };
@@ -15,11 +15,12 @@
* @group mustache-spec * @group mustache-spec
* @group functional * @group functional
*/ */
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;
} }
@@ -27,7 +28,8 @@ class Mustache_Test_FiveThree_Functional_MustacheSpecTest extends PHPUnit_Framew
* 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"');
} }
@@ -37,19 +39,22 @@ class Mustache_Test_FiveThree_Functional_MustacheSpecTest extends PHPUnit_Framew
* @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'])) {
@@ -76,7 +81,8 @@ class Mustache_Test_FiveThree_Functional_MustacheSpecTest extends PHPUnit_Framew
* @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();
@@ -106,7 +112,8 @@ class Mustache_Test_FiveThree_Functional_MustacheSpecTest extends PHPUnit_Framew
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);
@@ -116,7 +116,7 @@ class Mustache_Test_Functional_ExamplesTest extends PHPUnit_Framework_TestCase
* *
* @param string $path * @param string $path
* *
* @return array $partials * @return array $partials
*/ */
private function loadPartials($path) private function loadPartials($path)
{ {
@@ -49,7 +49,6 @@ class Mustache_Test_Functional_MustacheInjectionTest extends PHPUnit_Framework_T
$this->assertEquals('{{ b }}', $tpl->render($data)); $this->assertEquals('{{ b }}', $tpl->render($data));
} }
// sections // sections
public function testSectionInjection() public function testSectionInjection()
@@ -78,7 +77,6 @@ class Mustache_Test_Functional_MustacheInjectionTest extends PHPUnit_Framework_T
$this->assertEquals('{{ c }}', $tpl->render($data)); $this->assertEquals('{{ c }}', $tpl->render($data));
} }
// partials // partials
public function testPartialInjection() public function testPartialInjection()
@@ -111,7 +109,6 @@ class Mustache_Test_Functional_MustacheInjectionTest extends PHPUnit_Framework_T
$this->assertEquals('{{ b }}', $tpl->render($data)); $this->assertEquals('{{ b }}', $tpl->render($data));
} }
// lambdas // lambdas
public function testLambdaInterpolationInjection() public function testLambdaInterpolationInjection()
+2 -1
View File
@@ -1,6 +1,7 @@
<?php <?php
class Partials { class Partials
{
public $page = array( public $page = array(
'title' => 'Page Title', 'title' => 'Page Title',
'subtitle' => 'Page Subtitle', 'subtitle' => 'Page Subtitle',