From 0b85c9daff75d770955ea3ffbdf270f529060e20 Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Tue, 25 Mar 2014 18:38:21 -0700 Subject: [PATCH] Refactor out section callback test duplication. --- .../Functional/HigherOrderSectionsTest.php | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/test/Mustache/Test/Functional/HigherOrderSectionsTest.php b/test/Mustache/Test/Functional/HigherOrderSectionsTest.php index ecbc808..b042455 100644 --- a/test/Mustache/Test/Functional/HigherOrderSectionsTest.php +++ b/test/Mustache/Test/Functional/HigherOrderSectionsTest.php @@ -22,24 +22,26 @@ class Mustache_Test_Functional_HigherOrderSectionsTest extends Mustache_Test_Fun $this->mustache = new Mustache_Engine; } - public function testRuntimeSectionCallback() + /** + * @dataProvider sectionCallbackData + */ + public function testSectionCallback($data, $tpl, $expect) { - $tpl = $this->mustache->loadTemplate('{{#doublewrap}}{{name}}{{/doublewrap}}'); + $this->assertEquals($expect, $this->mustache->render($tpl, $data)); + } + public function sectionCallbackData() + { $foo = new Mustache_Test_Functional_Foo; $foo->doublewrap = array($foo, 'wrapWithBoth'); - $this->assertEquals(sprintf('%s', $foo->name), $tpl->render($foo)); - } + $bar = new Mustache_Test_Functional_Foo; + $bar->trimmer = array(get_class($bar), 'staticTrim'); - public function testStaticSectionCallback() - { - $tpl = $this->mustache->loadTemplate('{{#trimmer}} {{name}} {{/trimmer}}'); - - $foo = new Mustache_Test_Functional_Foo; - $foo->trimmer = array(get_class($foo), 'staticTrim'); - - $this->assertEquals($foo->name, $tpl->render($foo)); + return array( + array($foo, '{{#doublewrap}}{{name}}{{/doublewrap}}', sprintf('%s', $foo->name)), + array($bar, '{{#trimmer}} {{name}} {{/trimmer}}', $bar->name), + ); } public function testViewArraySectionCallback()