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
This commit is contained in:
Sergey Biryukov
2022-09-25 02:37:10 +00:00
parent 4f58e18cba
commit 395bae1776

View File

@@ -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 );
}
}
/**