loaders = spl_autoload_functions(); if (!is_array($this->loaders)) { // spl_autoload_functions does not return empty array when no // autoloaders registered... $this->loaders = array(); } Zend_Loader_Autoloader::resetInstance(); $this->autoloader = Zend_Loader_Autoloader::getInstance(); $this->application = new Zend_Application('testing'); $this->bootstrap = new Zend_Application_Bootstrap_Bootstrap($this->application); Zend_Controller_Front::getInstance()->resetInstance(); } public function tearDown() { // Restore original autoloaders $loaders = spl_autoload_functions(); foreach ($loaders as $loader) { spl_autoload_unregister($loader); } foreach ($this->loaders as $loader) { spl_autoload_register($loader); } // Reset autoloader instance so it doesn't affect other tests Zend_Loader_Autoloader::resetInstance(); } public function testInitializationInitializesLogObject() { $resource = new Zend_Application_Resource_Log(array()); $resource->setBootstrap($this->bootstrap); $resource->setOptions(array( 'Mock' => array('writerName' => 'Mock'), )); $resource->init(); $this->assertTrue($resource->getLog() instanceof Zend_Log); } public function testInitializationReturnsLogObject() { $resource = new Zend_Application_Resource_Log(array()); $resource->setBootstrap($this->bootstrap); $resource->setOptions(array( 'Mock' => array('writerName' => 'Mock'), )); $test = $resource->init(); $this->assertTrue($test instanceof Zend_Log); } public function testOptionsPassedToResourceAreUsedToInitializeLog() { $stream = fopen('php://memory', 'w+', false); $options = array('memory' => array( 'writerName' => 'Stream', 'writerParams' => array( 'stream' => $stream, ) )); $resource = new Zend_Application_Resource_Log($options); $resource->setBootstrap($this->bootstrap); $resource->init(); $log = $resource->getLog(); $this->assertTrue($log instanceof Zend_Log); $log->log($message = 'logged-message', Zend_Log::INFO); rewind($stream); $this->assertContains($message, stream_get_contents($stream)); } /** * @group ZF-8602 */ public function testNumericLogStreamFilterParamsPriorityDoesNotFail() { $options = array( 'stream' => array( 'writerName' => 'Stream', 'writerParams' => array( 'stream' => "php://memory", 'mode' => 'a' ), 'filterName' => 'Priority', 'filterParams' => array( 'priority' => '4' ), ), ); $resource = new Zend_Application_Resource_Log($options); $resource->setBootstrap($this->bootstrap); $resource->init(); } /** * @group ZF-9790 */ public function testInitializationWithFilterAndFormatter() { $stream = fopen('php://memory', 'w+'); $options = array( 'memory' => array( 'writerName' => 'Stream', 'writerParams' => array( 'stream' => $stream, ), 'filterName' => 'Priority', 'filterParams' => array( 'priority' => Zend_Log::INFO, ), 'formatterName' => 'Simple', 'formatterParams' => array( 'format' => '%timestamp%: %message%', ) ) ); $message = 'tottakai'; $resource = new Zend_Application_Resource_Log($options); $resource->setBootstrap($this->bootstrap); $log = $resource->init(); $this->assertTrue($log instanceof Zend_Log); $log->log($message, Zend_Log::INFO); rewind($stream); $contents = stream_get_contents($stream); $this->assertStringEndsWith($message, $contents); $this->assertRegexp('/\d\d:\d\d:\d\d/', $contents); } } if (PHPUnit_MAIN_METHOD == 'Zend_Application_Resource_LogTest::main') { Zend_Application_Resource_LogTest::main(); }