From 2abbc4b35cb8f20d5108cc54f83e06b9574df927 Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Tue, 25 Mar 2014 18:44:39 -0700 Subject: [PATCH] Refactor away engine logger test duplication. --- test/Mustache/Test/EngineTest.php | 39 ++++++++++++------------------- 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/test/Mustache/Test/EngineTest.php b/test/Mustache/Test/EngineTest.php index faeed29..6904d18 100644 --- a/test/Mustache/Test/EngineTest.php +++ b/test/Mustache/Test/EngineTest.php @@ -298,44 +298,35 @@ class Mustache_Test_EngineTest extends Mustache_Test_FunctionalTestCase public function testCacheWarningLogging() { - $name = tempnam(sys_get_temp_dir(), 'mustache-test'); - $mustache = new Mustache_Engine(array( - 'logger' => new Mustache_Logger_StreamLogger($name, Mustache_Logger::WARNING) - )); - - $result = $mustache->render('{{ foo }}', array('foo' => 'FOO')); - $this->assertEquals('FOO', $result); - + list($name, $mustache) = $this->getLoggedMustache(Mustache_Logger::WARNING); + $mustache->render('{{ foo }}', array('foo' => 'FOO')); $this->assertContains('WARNING: Template cache disabled, evaluating', file_get_contents($name)); } public function testLoggingIsNotTooAnnoying() { - $name = tempnam(sys_get_temp_dir(), 'mustache-test'); - $mustache = new Mustache_Engine(array( - 'logger' => new Mustache_Logger_StreamLogger($name) - )); - - $result = $mustache->render('{{ foo }}{{> bar }}', array('foo' => 'FOO')); - $this->assertEquals('FOO', $result); - + list($name, $mustache) = $this->getLoggedMustache(); + $mustache->render('{{ foo }}{{> bar }}', array('foo' => 'FOO')); $this->assertEmpty(file_get_contents($name)); } public function testVerboseLoggingIsVerbose() + { + list($name, $mustache) = $this->getLoggedMustache(Mustache_Logger::DEBUG); + $mustache->render('{{ foo }}{{> bar }}', array('foo' => 'FOO')); + $log = file_get_contents($name); + $this->assertContains("DEBUG: Instantiating template: ", $log); + $this->assertContains("WARNING: Partial not found: \"bar\"", $log); + } + + private function getLoggedMustache($level = Mustache_Logger::ERROR) { $name = tempnam(sys_get_temp_dir(), 'mustache-test'); $mustache = new Mustache_Engine(array( - 'logger' => new Mustache_Logger_StreamLogger($name, Mustache_Logger::DEBUG) + 'logger' => new Mustache_Logger_StreamLogger($name, $level) )); - $result = $mustache->render('{{ foo }}{{> bar }}', array('foo' => 'FOO')); - $this->assertEquals('FOO', $result); - - $log = file_get_contents($name); - - $this->assertContains("DEBUG: Instantiating template: ", $log); - $this->assertContains("WARNING: Partial not found: \"bar\"", $log); + return array($name, $mustache); } }