From 395bae1776106c319150bc32591372aa3d1f93cc Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sun, 25 Sep 2022 02:37:10 +0000 Subject: [PATCH] Tests: Remove empty directory in `WP_UnitTestCase_Base::rmdir()`. The `WP_UnitTestCase_Base::rmdir()` method selectively deletes files from a directory, skipping any paths from the `$ignore_files` property. This commit updates the method to remove the empty directory if there are no files left, bringing some parity with PHP native `rmdir()` function. Follow-up to [677/tests], [29120]. See #55652. git-svn-id: https://develop.svn.wordpress.org/trunk@54300 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/includes/abstract-testcase.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/phpunit/includes/abstract-testcase.php b/tests/phpunit/includes/abstract-testcase.php index c20f450f7c..1e8e23e774 100644 --- a/tests/phpunit/includes/abstract-testcase.php +++ b/tests/phpunit/includes/abstract-testcase.php @@ -1349,6 +1349,9 @@ abstract class WP_UnitTestCase_Base extends PHPUnit_Adapter_TestCase { * * Does not delete files if their paths are set in the `$ignore_files` property. * + * @since 4.0.0 + * @since 6.1.0 Removes the empty directory if there are no files left. + * * @param string $path Directory path. */ public function rmdir( $path ) { @@ -1358,6 +1361,11 @@ abstract class WP_UnitTestCase_Base extends PHPUnit_Adapter_TestCase { $this->unlink( $file ); } } + + // If there were no ignored files, remove the empty directory. + if ( ! array_intersect( $files, self::$ignore_files ) ) { + rmdir( $path ); + } } /**