Make WordPress Core

Changeset 54300


Ignore:
Timestamp:
09/25/2022 02:37:10 AM (17 months ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/includes/abstract-testcase.php

    r54087 r54300  
    13501350     * Does not delete files if their paths are set in the `$ignore_files` property.
    13511351     *
     1352     * @since 4.0.0
     1353     * @since 6.1.0 Removes the empty directory if there are no files left.
     1354     *
    13521355     * @param string $path Directory path.
    13531356     */
     
    13581361                $this->unlink( $file );
    13591362            }
     1363        }
     1364
     1365        // If there were no ignored files, remove the empty directory.
     1366        if ( ! array_intersect( $files, self::$ignore_files ) ) {
     1367            rmdir( $path );
    13601368        }
    13611369    }
Note: See TracChangeset for help on using the changeset viewer.