From ac45d611522a09162eadcfac955dac562cc22e71 Mon Sep 17 00:00:00 2001 From: Tim van Dijen <tvdijen@gmail.com> Date: Sat, 26 Feb 2022 23:45:00 +0100 Subject: [PATCH] Windows fix --- lib/SimpleSAML/Logger/FileLoggingHandler.php | 19 ++++++++++++++----- lib/SimpleSAML/Module.php | 2 +- tests/lib/SimpleSAML/ModuleTest.php | 7 ++++--- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/lib/SimpleSAML/Logger/FileLoggingHandler.php b/lib/SimpleSAML/Logger/FileLoggingHandler.php index 64e6e21e5..a11eff283 100644 --- a/lib/SimpleSAML/Logger/FileLoggingHandler.php +++ b/lib/SimpleSAML/Logger/FileLoggingHandler.php @@ -133,11 +133,20 @@ class FileLoggingHandler implements LoggingHandlerInterface array_push($replacements, date($format)); } - $this->fileSystem->appendToFile( - $this->logFile, - str_replace($formats, $replacements, $string) . \PHP_EOL, - false, - ); + if (preg_match('/^php:\/\//', $this->logFile)) { + // Dirty hack to get unit tests for Windows working.. Symfony doesn't deal well with them. + file_put_contents( + $this->logFile, + str_replace($formats, $replacements, $string) . \PHP_EOL, + FILE_APPEND, + ); + } else { + $this->fileSystem->appendToFile( + $this->logFile, + str_replace($formats, $replacements, $string) . \PHP_EOL, + false, + ); + } } } } diff --git a/lib/SimpleSAML/Module.php b/lib/SimpleSAML/Module.php index 4824cc2e4..cb3d9be3b 100644 --- a/lib/SimpleSAML/Module.php +++ b/lib/SimpleSAML/Module.php @@ -505,7 +505,7 @@ class Module } $hooks = []; - $hook_dir = dirname(dirname(dirname(__FILE__))) . '/modules/' . $module . '/hooks'; + $hook_dir = Path::canonicalize(dirname(dirname(dirname(__FILE__))) . '/modules/' . $module . '/hooks'); if ((new Filesystem())->exists($hook_dir)) { $finder = new Finder(); $finder->files()->in($hook_dir)->depth(0); diff --git a/tests/lib/SimpleSAML/ModuleTest.php b/tests/lib/SimpleSAML/ModuleTest.php index 966f9c75f..c5bb51e3c 100644 --- a/tests/lib/SimpleSAML/ModuleTest.php +++ b/tests/lib/SimpleSAML/ModuleTest.php @@ -8,6 +8,7 @@ use Exception; use PHPUnit\Framework\TestCase; use SimpleSAML\Configuration; use SimpleSAML\Module; +use Symfony\Component\Filesystem\Path; /** * @covers \SimpleSAML\Module @@ -31,8 +32,8 @@ class ModuleTest extends TestCase { // test for the most basic functionality $this->assertEquals( - dirname(dirname(dirname(dirname(__FILE__)))) . '/modules/module', - Module::getModuleDir('module') + Path::canonicalize(dirname(dirname(dirname(dirname(__FILE__)))) . '/modules/module'), + Path::canonicalize(Module::getModuleDir('module')), ); } @@ -121,7 +122,7 @@ class ModuleTest extends TestCase $hooks = Module::getModuleHooks('cron'); $this->assertArrayHasKey('configpage', $hooks); $this->assertEquals('cron_hook_configpage', $hooks['configpage']['func']); - $expectedFile = dirname(__DIR__, 3) . '/modules/cron/hooks/hook_configpage.php'; + $expectedFile = Path::canonicalize(dirname(__DIR__, 3) . '/modules/cron/hooks/hook_configpage.php'); $this->assertEquals($expectedFile, $hooks['configpage']['file']); } -- GitLab