Skip to content

Commit bc4104f

Browse files
committed
Add a cleanup function under unzip file tests.
1 parent 33e9b64 commit bc4104f

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

tests/phpunit/tests/filesystem/unzipFilePclzip.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,27 @@ public function test_should_apply_unzip_file_filters() {
6363

6464
// Prepare test environment.
6565
$unzip_destination = self::$test_data_dir . 'archive/';
66+
$this->cleanup_unzip_destination( $unzip_destination );
6667
mkdir( $unzip_destination );
6768

6869
_unzip_file_pclzip( self::$test_data_dir . 'archive.zip', $unzip_destination );
6970

7071
// Cleanup test environment.
71-
$this->rmdir( $unzip_destination );
72-
$this->delete_folders( $unzip_destination );
72+
$this->cleanup_unzip_destination( $unzip_destination );
7373

7474
$this->assertSame( 1, $filter->get_call_count() );
7575
}
76+
77+
/**
78+
* Cleanup the unzip destination.
79+
*
80+
* @param string $unzip_destination Unzip destination.
81+
* @return void
82+
*/
83+
public function cleanup_unzip_destination( $unzip_destination ) {
84+
if ( file_exists( $unzip_destination ) ) {
85+
$this->rmdir( $unzip_destination );
86+
$this->delete_folders( $unzip_destination );
87+
}
88+
}
7689
}

tests/phpunit/tests/filesystem/unzipFileZiparchive.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,27 @@ public function test_should_apply_unzip_file_filters() {
7171

7272
// Prepare test environment.
7373
$unzip_destination = self::$test_data_dir . 'archive/';
74+
$this->cleanup_unzip_destination( $unzip_destination );
7475
mkdir( $unzip_destination );
7576

7677
_unzip_file_ziparchive( self::$test_data_dir . 'archive.zip', $unzip_destination );
7778

7879
// Cleanup test environment.
79-
$this->rmdir( $unzip_destination );
80-
$this->delete_folders( $unzip_destination );
80+
$this->cleanup_unzip_destination( $unzip_destination );
8181

8282
$this->assertSame( 1, $filter->get_call_count() );
8383
}
84+
85+
/**
86+
* Cleanup the unzip destination.
87+
*
88+
* @param string $unzip_destination Unzip destination.
89+
* @return void
90+
*/
91+
public function cleanup_unzip_destination( $unzip_destination ) {
92+
if ( file_exists( $unzip_destination ) ) {
93+
$this->rmdir( $unzip_destination );
94+
$this->delete_folders( $unzip_destination );
95+
}
96+
}
8497
}

0 commit comments

Comments
 (0)