| 1 | diff --git a/tests/phpunit/includes/abstract-testcase.php b/tests/phpunit/includes/abstract-testcase.php |
|---|
| 2 | index abc1234..def5678 100644 |
|---|
| 3 | --- a/tests/phpunit/includes/abstract-testcase.php |
|---|
| 4 | +++ b/tests/phpunit/includes/abstract-testcase.php |
|---|
| 5 | @@ class WP_UnitTestCase { |
|---|
| 6 | protected function set_up_fixtures() { |
|---|
| 7 | parent::set_up_fixtures(); |
|---|
| 8 | + $this->cleanup_unzip_destination(); |
|---|
| 9 | } |
|---|
| 10 | |
|---|
| 11 | + /** |
|---|
| 12 | + * Clean up any existing archive directory used in ZIP tests. |
|---|
| 13 | + * Prevents failures when the directory is leftover from previous runs. |
|---|
| 14 | + * |
|---|
| 15 | + * @return void |
|---|
| 16 | + */ |
|---|
| 17 | + protected function cleanup_unzip_destination() { |
|---|
| 18 | + $dest = WP_TESTS_DIR . '/phpunit/data/filesystem/archive'; |
|---|
| 19 | + if ( is_dir( $dest ) ) { |
|---|
| 20 | + $this->recursive_remove( $dest ); |
|---|
| 21 | + } |
|---|
| 22 | + } |
|---|
| 23 | |
|---|
| 24 | + /** |
|---|
| 25 | + * Recursively remove a directory. |
|---|
| 26 | + * |
|---|
| 27 | + * @param string $dir Directory path. |
|---|
| 28 | + * @return void |
|---|
| 29 | + */ |
|---|
| 30 | + protected function recursive_remove( $dir ) { |
|---|
| 31 | + foreach ( glob( $dir . '/*' ) as $file ) { |
|---|
| 32 | + if ( is_dir( $file ) ) { |
|---|
| 33 | + $this->recursive_remove( $file ); |
|---|
| 34 | + } else { |
|---|
| 35 | + unlink( $file ); |
|---|
| 36 | + } |
|---|
| 37 | + } |
|---|
| 38 | + rmdir( $dir ); |
|---|
| 39 | + } |
|---|
| 40 | } |
|---|