From e7b4945e9d4da1f2c6d2f52e08d699ffaf54cf24 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sun, 25 Sep 2022 03:38:13 +0000 Subject: [PATCH] Tests: Remove nested empty directories in `WP_UnitTestCase_Base::rmdir()`. Includes: * Checking if the directory exists and returning early otherwise. * Removing a redundant `rmdir()` call in `clean_dirsize_cache()` tests. Follow-up to [49744], [54300]. See #55652. git-svn-id: https://develop.svn.wordpress.org/trunk@54303 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/includes/abstract-testcase.php | 11 +++++++++-- tests/phpunit/tests/multisite/cleanDirsizeCache.php | 2 -- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/tests/phpunit/includes/abstract-testcase.php b/tests/phpunit/includes/abstract-testcase.php index 1e8e23e774..fa667f99ba 100644 --- a/tests/phpunit/includes/abstract-testcase.php +++ b/tests/phpunit/includes/abstract-testcase.php @@ -1355,6 +1355,10 @@ abstract class WP_UnitTestCase_Base extends PHPUnit_Adapter_TestCase { * @param string $path Directory path. */ public function rmdir( $path ) { + if ( ! is_dir( $path ) ) { + return; + } + $files = $this->files_in_dir( $path ); foreach ( $files as $file ) { if ( ! in_array( $file, self::$ignore_files, true ) ) { @@ -1362,9 +1366,12 @@ abstract class WP_UnitTestCase_Base extends PHPUnit_Adapter_TestCase { } } - // If there were no ignored files, remove the empty directory. + /* + * If there were no ignored files, remove the empty directory. + * If there are any nested empty directories, remove them too. + */ if ( ! array_intersect( $files, self::$ignore_files ) ) { - rmdir( $path ); + $this->delete_folders( $path ); } } diff --git a/tests/phpunit/tests/multisite/cleanDirsizeCache.php b/tests/phpunit/tests/multisite/cleanDirsizeCache.php index df38ee33d1..a777feca8a 100644 --- a/tests/phpunit/tests/multisite/cleanDirsizeCache.php +++ b/tests/phpunit/tests/multisite/cleanDirsizeCache.php @@ -295,8 +295,6 @@ if ( is_multisite() ) : // Cleanup. $this->remove_added_uploads(); - rmdir( $upload_dir['basedir'] . '/2/1' ); - restore_current_blog(); }