From: demeritcowboy Date: Sat, 8 Jan 2022 01:41:57 +0000 (-0500) Subject: fails in unusual situation on php 7 X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=4bda8e715af29379972b1d8587d223d0ecfbb292;p=civicrm-core.git fails in unusual situation on php 7 --- diff --git a/CRM/Utils/File.php b/CRM/Utils/File.php index 493597cc00..dbdcca1608 100644 --- a/CRM/Utils/File.php +++ b/CRM/Utils/File.php @@ -1124,9 +1124,10 @@ HTACCESS; * It should either return FALSE, or the value returned from is_dir(). * * @param string|null $dir - * @return bool + * @return bool|null + * In php8 the return value from is_dir() is always bool but in php7 it can be null. */ - public static function isDir(?string $dir): bool { + public static function isDir(?string $dir) { set_error_handler(function($errno, $errstr) { // If this is open_basedir-related, convert it to an exception so we // can catch it. diff --git a/tests/phpunit/CRM/Utils/FileTest.php b/tests/phpunit/CRM/Utils/FileTest.php index 5af809fda0..d1e2c59ba3 100644 --- a/tests/phpunit/CRM/Utils/FileTest.php +++ b/tests/phpunit/CRM/Utils/FileTest.php @@ -253,9 +253,16 @@ class CRM_Utils_FileTest extends CiviUnitTestCase { // Note that in php8 is_dir changed in php itself to return false with no warning for these. It used to give `is_dir() expects parameter 1 to be a valid path, string given`. See https://github.com/php/php-src/commit/7bc7a80445f2bb349891d3cccfef2d589c48607e clearstatcache(); - $this->assertFalse(CRM_Utils_File::isDir('./testIsDir/' . chr(0))); - clearstatcache(); - $this->assertFalse(CRM_Utils_File::isDir("testIsDir\0")); + if (version_compare(PHP_VERSION, '8.0.0', '<')) { + $this->assertNull(CRM_Utils_File::isDir('./testIsDir/' . chr(0))); + clearstatcache(); + $this->assertNull(CRM_Utils_File::isDir("testIsDir\0")); + } + else { + $this->assertFalse(CRM_Utils_File::isDir('./testIsDir/' . chr(0))); + clearstatcache(); + $this->assertFalse(CRM_Utils_File::isDir("testIsDir\0")); + } $this->assertTrue(chdir($old_cwd)); rmdir($a_dir);