logging-log4php-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Christian Hammers (JIRA)" <j...@apache.org>
Subject [jira] Created: (LOG4PHP-86) LoggerAppenderRollingFileTest fails due to realpath()=>false on nonexisting files
Date Mon, 14 Sep 2009 23:01:57 GMT
LoggerAppenderRollingFileTest fails due to realpath()=>false on nonexisting files

                 Key: LOG4PHP-86
                 URL: https://issues.apache.org/jira/browse/LOG4PHP-86
             Project: Log4php
          Issue Type: Bug
          Components: Tests
            Reporter: Christian Hammers

The Unit-Tests failed for me and I figured out that it was caused by realpath() which returns
false if the file does not already exist.
That was until PHP-5.3 not true for BSD, btw., which may also explain why it was no issue
on MacOS computers...

--- src/main/php/appenders/LoggerAppenderRollingFile.php        (Revision 814880)      
+++ src/main/php/appenders/LoggerAppenderRollingFile.php        (Arbeitskopie)         
@@ -130,7 +143,11 @@

        public function setFileName($fileName) {
                $this->fileName = $fileName;
-               $this->expandedFileName = realpath($fileName);
+               // As LoggerAppenderFile does not create the directory, it has to exist.
+               // realpath() fails if the argument does not exist so the filename is separated.
+               $this->expandedFileName = realpath(dirname($fileName));
+               if ($this->expandedFileName === false) throw new Exception("Directory of
$fileName does not exist!");
+               $this->expandedFileName .= '/'.basename($fileName);

I added the following test to src/test/php/appenders/LoggerAppenderRollingFileTest.php 

+    public function testSetFileName() {                                                 
+        $appender = new LoggerAppenderRollingFile("mylogger");                          
+        $appender->setFileName('target/temp/../././temp/phpunit/doesnotexist.log');  
+        $expandedFileName = self::readAttribute($appender, 'expandedFileName');         
+        self::assertEquals(1, preg_match('/\/target\/temp\/phpunit\/doesnotexist.log$/',
+    }

expandedFileName is private and has no getter thus the ugly readAttribute()



This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message