From 57f4fc14d8cbb8d86840105890b1eb7a856cd3a7 Mon Sep 17 00:00:00 2001 From: MDW Date: Fri, 1 Mar 2024 12:50:51 +0100 Subject: [PATCH] Fix: phpunit - Add adapter to "not existing directory" assertion (#28534) # Fix: phpunit - Add adapter to "not existing directory" assertion This is a helper function added to the common test class which is useful to maintain cross phpunit version compatibility without triggering a deprecation error for internal phpunit test functions. Used in a testcase for dol_dir_move in a pending PR --- test/phpunit/CommonClassTest.class.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/phpunit/CommonClassTest.class.php b/test/phpunit/CommonClassTest.class.php index e5c63965f55..0e5f49dd24b 100644 --- a/test/phpunit/CommonClassTest.class.php +++ b/test/phpunit/CommonClassTest.class.php @@ -339,4 +339,24 @@ abstract class CommonClassTest extends TestCase 'workstation' => 'Workstation', 'zapier' => 'Zapier', ); + + /** + * Assert that a directory does not exist without triggering deprecation + * + * @param string $directory The directory to test + * @param string $message The message to show if the directory exists + * + * @return void + */ + protected function assertDirectoryNotExistsCompat($directory, $message = '') + { + $phpunitVersion = \PHPUnit\Runner\Version::id(); + + // Check if PHPUnit version is less than 9.0.0 + if (version_compare($phpunitVersion, '9.0.0', '<')) { + $this->assertDirectoryNotExists($directory, $message); + } else { + $this->assertDirectoryDoesNotExist($directory, $message); + } + } }