Refactor away engine logger test duplication.
This commit is contained in:
@@ -298,45 +298,36 @@ 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()
|
||||||
{
|
{
|
||||||
$name = tempnam(sys_get_temp_dir(), 'mustache-test');
|
list($name, $mustache) = $this->getLoggedMustache(Mustache_Logger::DEBUG);
|
||||||
$mustache = new Mustache_Engine(array(
|
$mustache->render('{{ foo }}{{> bar }}', array('foo' => 'FOO'));
|
||||||
'logger' => new Mustache_Logger_StreamLogger($name, Mustache_Logger::DEBUG)
|
|
||||||
));
|
|
||||||
|
|
||||||
$result = $mustache->render('{{ foo }}{{> bar }}', array('foo' => 'FOO'));
|
|
||||||
$this->assertEquals('FOO', $result);
|
|
||||||
|
|
||||||
$log = file_get_contents($name);
|
$log = file_get_contents($name);
|
||||||
|
|
||||||
$this->assertContains("DEBUG: Instantiating template: ", $log);
|
$this->assertContains("DEBUG: Instantiating template: ", $log);
|
||||||
$this->assertContains("WARNING: Partial not found: \"bar\"", $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, $level)
|
||||||
|
));
|
||||||
|
|
||||||
|
return array($name, $mustache);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class MustacheStub extends Mustache_Engine
|
class MustacheStub extends Mustache_Engine
|
||||||
|
|||||||
Reference in New Issue
Block a user