diff --git a/tests/phpunit/includes/abstract-testcase.php b/tests/phpunit/includes/abstract-testcase.php index 5b080fc7ceb9f..64a57e0d9dba3 100644 --- a/tests/phpunit/includes/abstract-testcase.php +++ b/tests/phpunit/includes/abstract-testcase.php @@ -1864,4 +1864,18 @@ private function retry_on_error( callable $callback, $url, $args ) { return $result; } + + /** + * Clean up the unzip destination. + * + * @since 6.9.0 + * + * @param string $unzip_destination Unzip destination. + */ + public function clean_up_unzip_destination( $unzip_destination ) { + if ( file_exists( $unzip_destination ) ) { + $this->rmdir( $unzip_destination ); + $this->delete_folders( $unzip_destination ); + } + } } diff --git a/tests/phpunit/tests/filesystem/unzipFilePclzip.php b/tests/phpunit/tests/filesystem/unzipFilePclzip.php index 5a195417febb9..4bd459ebf13aa 100644 --- a/tests/phpunit/tests/filesystem/unzipFilePclzip.php +++ b/tests/phpunit/tests/filesystem/unzipFilePclzip.php @@ -41,13 +41,13 @@ public function test_should_apply_pre_unzip_file_filters() { // Prepare test environment. $unzip_destination = self::$test_data_dir . 'archive/'; + $this->clean_up_unzip_destination( $unzip_destination ); // See #63443 for details. mkdir( $unzip_destination ); _unzip_file_pclzip( self::$test_data_dir . 'archive.zip', $unzip_destination ); // Cleanup test environment. - $this->rmdir( $unzip_destination ); - $this->delete_folders( $unzip_destination ); + $this->clean_up_unzip_destination( $unzip_destination ); $this->assertSame( 1, $filter->get_call_count() ); } @@ -63,13 +63,13 @@ public function test_should_apply_unzip_file_filters() { // Prepare test environment. $unzip_destination = self::$test_data_dir . 'archive/'; + $this->clean_up_unzip_destination( $unzip_destination ); // See #63443 for details. mkdir( $unzip_destination ); _unzip_file_pclzip( self::$test_data_dir . 'archive.zip', $unzip_destination ); // Cleanup test environment. - $this->rmdir( $unzip_destination ); - $this->delete_folders( $unzip_destination ); + $this->clean_up_unzip_destination( $unzip_destination ); $this->assertSame( 1, $filter->get_call_count() ); } diff --git a/tests/phpunit/tests/filesystem/unzipFileZiparchive.php b/tests/phpunit/tests/filesystem/unzipFileZiparchive.php index 53cabd945439e..ce4cfd0ad4281 100644 --- a/tests/phpunit/tests/filesystem/unzipFileZiparchive.php +++ b/tests/phpunit/tests/filesystem/unzipFileZiparchive.php @@ -45,13 +45,13 @@ public function test_should_apply_pre_unzip_file_filters() { // Prepare test environment. $unzip_destination = self::$test_data_dir . 'archive/'; + $this->clean_up_unzip_destination( $unzip_destination ); // See #63443 for details. mkdir( $unzip_destination ); _unzip_file_ziparchive( self::$test_data_dir . 'archive.zip', $unzip_destination ); // Cleanup test environment. - $this->rmdir( $unzip_destination ); - $this->delete_folders( $unzip_destination ); + $this->clean_up_unzip_destination( $unzip_destination ); $this->assertSame( 1, $filter->get_call_count() ); } @@ -71,13 +71,13 @@ public function test_should_apply_unzip_file_filters() { // Prepare test environment. $unzip_destination = self::$test_data_dir . 'archive/'; + $this->clean_up_unzip_destination( $unzip_destination ); // See #65443 for details. mkdir( $unzip_destination ); _unzip_file_ziparchive( self::$test_data_dir . 'archive.zip', $unzip_destination ); // Cleanup test environment. - $this->rmdir( $unzip_destination ); - $this->delete_folders( $unzip_destination ); + $this->clean_up_unzip_destination( $unzip_destination ); $this->assertSame( 1, $filter->get_call_count() ); }