Description
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)); + }expandedFileName is private and has no getter thus the ugly readAttribute()
bye,
christian