From ada9876c18680cd61a6942bac492fc0d1d670b79 Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Tue, 25 Mar 2014 18:33:26 -0700 Subject: [PATCH] Refactor out test code duplication (enable/disable lambda template cache test) --- .../Functional/HigherOrderSectionsTest.php | 31 ++++++++----------- 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/test/Mustache/Test/Functional/HigherOrderSectionsTest.php b/test/Mustache/Test/Functional/HigherOrderSectionsTest.php index 43e927e..ecbc808 100644 --- a/test/Mustache/Test/Functional/HigherOrderSectionsTest.php +++ b/test/Mustache/Test/Functional/HigherOrderSectionsTest.php @@ -100,36 +100,31 @@ class Mustache_Test_Functional_HigherOrderSectionsTest extends Mustache_Test_Fun $this->assertEquals('' . $foo->name . '', $tpl->render($foo)); } - public function testEnablingLambdaCacheActuallyWorks() + /** + * @dataProvider cacheLambdaTemplatesData + */ + public function testCacheLambdaTemplatesOptionWorks($dirName, $tplPrefix, $enable, $expect) { - $cacheDir = $this->setUpCacheDir('test_enabling_lambda_cache'); + $cacheDir = $this->setUpCacheDir($dirName); $mustache = new Mustache_Engine(array( - 'template_class_prefix' => '_TestEnablingLambdaCache_', + 'template_class_prefix' => $tplPrefix, 'cache' => $cacheDir, - 'cache_lambda_templates' => true, + 'cache_lambda_templates' => $enable, )); $tpl = $mustache->loadTemplate('{{#wrap}}{{name}}{{/wrap}}'); $foo = new Mustache_Test_Functional_Foo; $foo->wrap = array($foo, 'wrapWithEm'); $this->assertEquals('' . $foo->name . '', $tpl->render($foo)); - $this->assertCount(2, glob($cacheDir . '/*.php')); + $this->assertCount($expect, glob($cacheDir . '/*.php')); } - public function testDisablingLambdaCacheActuallyWorks() + public function cacheLambdaTemplatesData() { - $cacheDir = $this->setUpCacheDir('test_disabling_lambda_cache'); - $mustache = new Mustache_Engine(array( - 'template_class_prefix' => '_TestDisablingLambdaCache_', - 'cache' => $cacheDir, - 'cache_lambda_templates' => false, - )); - - $tpl = $mustache->loadTemplate('{{#wrap}}{{name}}{{/wrap}}'); - $foo = new Mustache_Test_Functional_Foo; - $foo->wrap = array($foo, 'wrapWithEm'); - $this->assertEquals('' . $foo->name . '', $tpl->render($foo)); - $this->assertCount(1, glob($cacheDir . '/*.php')); + return array( + array('test_enabling_lambda_cache', '_TestEnablingLambdaCache_', true, 2), + array('test_disabling_lambda_cache', '_TestDisablingLambdaCache_', false, 1), + ); } protected function setUpCacheDir($name)