Refactor away engine logger test duplication.

This commit is contained in:
Justin Hileman
2014-03-25 18:44:58 -07:00
parent 0b85c9daff
commit 2abbc4b35c
+15 -24
View File
@@ -298,44 +298,35 @@ class Mustache_Test_EngineTest extends Mustache_Test_FunctionalTestCase
public function testCacheWarningLogging() public function testCacheWarningLogging()
{ {
$name = tempnam(sys_get_temp_dir(), 'mustache-test'); list($name, $mustache) = $this->getLoggedMustache(Mustache_Logger::WARNING);
$mustache = new Mustache_Engine(array( $mustache->render('{{ foo }}', array('foo' => 'FOO'));
'logger' => new Mustache_Logger_StreamLogger($name, Mustache_Logger::WARNING)
));
$result = $mustache->render('{{ foo }}', array('foo' => 'FOO'));
$this->assertEquals('FOO', $result);
$this->assertContains('WARNING: Template cache disabled, evaluating', file_get_contents($name)); $this->assertContains('WARNING: Template cache disabled, evaluating', file_get_contents($name));
} }
public function testLoggingIsNotTooAnnoying() public function testLoggingIsNotTooAnnoying()
{ {
$name = tempnam(sys_get_temp_dir(), 'mustache-test'); list($name, $mustache) = $this->getLoggedMustache();
$mustache = new Mustache_Engine(array( $mustache->render('{{ foo }}{{> bar }}', array('foo' => 'FOO'));
'logger' => new Mustache_Logger_StreamLogger($name)
));
$result = $mustache->render('{{ foo }}{{> bar }}', array('foo' => 'FOO'));
$this->assertEquals('FOO', $result);
$this->assertEmpty(file_get_contents($name)); $this->assertEmpty(file_get_contents($name));
} }
public function testVerboseLoggingIsVerbose() 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'); $name = tempnam(sys_get_temp_dir(), 'mustache-test');
$mustache = new Mustache_Engine(array( $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')); return array($name, $mustache);
$this->assertEquals('FOO', $result);
$log = file_get_contents($name);
$this->assertContains("DEBUG: Instantiating template: ", $log);
$this->assertContains("WARNING: Partial not found: \"bar\"", $log);
} }
} }