From 3ab0dc20b3e632b9294e828da8a880d22fd03944 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 5 Sep 2022 19:22:27 +0000 Subject: [PATCH] Tests: Prevent an Ajax test for `IMAGE_EDIT_OVERWRITE` from being marked as risky. This affects `Tests_Ajax_MediaEdit::testImageEditOverwriteConstant()`. In case the `$files_that_should_not_exist` file list is empty, the test would be marked as risky, since it would not perform any assertions. This small tweak prevents that from happening. Follow-up to [38113]. Props jrf. See #55652. git-svn-id: https://develop.svn.wordpress.org/trunk@54073 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/ajax/MediaEdit.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/tests/phpunit/tests/ajax/MediaEdit.php b/tests/phpunit/tests/ajax/MediaEdit.php index 686dae08c5..83c478c83b 100644 --- a/tests/phpunit/tests/ajax/MediaEdit.php +++ b/tests/phpunit/tests/ajax/MediaEdit.php @@ -97,14 +97,24 @@ class Tests_Ajax_MediaEdit extends WP_Ajax_UnitTestCase { $file_path = dirname( get_attached_file( $id ) ); + $files_that_should_not_exist = array(); + foreach ( $sizes1 as $key => $size ) { if ( $sizes2[ $key ]['file'] !== $size['file'] ) { - $files_that_shouldnt_exist[] = $file_path . '/' . $size['file']; + $files_that_should_not_exist[] = $file_path . '/' . $size['file']; } } - foreach ( $files_that_shouldnt_exist as $file ) { - $this->assertFileDoesNotExist( $file, 'IMAGE_EDIT_OVERWRITE is leaving garbage image files behind.' ); + if ( ! empty( $files_that_should_not_exist ) ) { + foreach ( $files_that_should_not_exist as $file ) { + $this->assertFileDoesNotExist( $file, 'IMAGE_EDIT_OVERWRITE is leaving garbage image files behind.' ); + } + } else { + /* + * This assertion will always pass due to the "if" condition, but prevents this test + * from being marked as "risky" due to the test not performing any assertions. + */ + $this->assertSame( array(), $files_that_should_not_exist ); } } }