Index: tests/phpunit/tests/image/intermediateSize.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/tests/phpunit/tests/image/intermediateSize.php b/tests/phpunit/tests/image/intermediateSize.php
--- a/tests/phpunit/tests/image/intermediateSize.php	(revision a855e85c77f3cc978e960321e0c7a63fa808b9c1)
+++ b/tests/phpunit/tests/image/intermediateSize.php	(date 1658221647586)
@@ -15,13 +15,6 @@
 		parent::tear_down();
 	}
 
-	public function _make_attachment( $file, $parent_post_id = 0 ) {
-		$contents = file_get_contents( $file );
-		$upload   = wp_upload_bits( wp_basename( $file ), null, $contents );
-
-		return parent::_make_attachment( $upload, $parent_post_id );
-	}
-
 	public function test_make_intermediate_size_no_size() {
 		$image = image_make_intermediate_size( DIR_TESTDATA . '/images/a2-small.jpg', 0, 0, false );
 
@@ -96,7 +89,7 @@
 		add_image_size( 'test-size', 330, 220, true );
 
 		$file = DIR_TESTDATA . '/images/waffles.jpg';
-		$id   = $this->_make_attachment( $file, 0 );
+		$id   = $this->_upload_file_and_make_attachment( $file );
 
 		// Look for a size by name.
 		$image = image_get_intermediate_size( $id, 'test-size' );
@@ -120,7 +113,7 @@
 		add_image_size( 'false-width', 600, 220, true );
 
 		$file = DIR_TESTDATA . '/images/waffles.jpg';
-		$id   = $this->_make_attachment( $file, 0 );
+		$id   = $this->_upload_file_and_make_attachment( $file );
 
 		// Look for a size by array that exists.
 		// Note: Staying larger than 300px to miss default medium crop.
@@ -143,7 +136,7 @@
 		add_image_size( 'false-width', 150, 220, true );
 
 		$file = DIR_TESTDATA . '/images/waffles.jpg';
-		$id   = $this->_make_attachment( $file, 0 );
+		$id   = $this->_upload_file_and_make_attachment( $file );
 
 		// Look for a size by array that doesn't exist.
 		// Note: Staying larger than 300px to miss default medium crop.
@@ -165,7 +158,7 @@
 		add_image_size( 'false-width', 150, 220, true );
 
 		$file = DIR_TESTDATA . '/images/waffles.jpg';
-		$id   = $this->_make_attachment( $file, 0 );
+		$id   = $this->_upload_file_and_make_attachment( $file );
 
 		// Look for a size by array that doesn't exist.
 		// Note: Staying larger than 300px to miss default medium crop.
@@ -189,7 +182,7 @@
 		add_image_size( 'false-height', $width, 100, true );
 
 		$file = DIR_TESTDATA . '/images/waffles.jpg';
-		$id   = $this->_make_attachment( $file, 0 );
+		$id   = $this->_upload_file_and_make_attachment( $file );
 
 		$original = wp_get_attachment_metadata( $id );
 		$image_w  = $width;
@@ -218,7 +211,7 @@
 		add_image_size( 'false-height', 300, $height, true );
 
 		$file = DIR_TESTDATA . '/images/waffles.jpg';
-		$id   = $this->_make_attachment( $file, 0 );
+		$id   = $this->_upload_file_and_make_attachment( $file );
 
 		$original = wp_get_attachment_metadata( $id );
 		$image_h  = $height;
@@ -245,7 +238,7 @@
 		add_image_size( 'off-by-one', $width, $height, true );
 
 		$file = DIR_TESTDATA . '/images/waffles.jpg';
-		$id   = $this->_make_attachment( $file, 0 );
+		$id   = $this->_upload_file_and_make_attachment( $file );
 
 		$original = wp_get_attachment_metadata( $id );
 		$image_h  = $height;
@@ -267,7 +260,7 @@
 		add_image_size( 'test-size', 200, 100, true );
 
 		$file = DIR_TESTDATA . '/images/waffles.jpg';
-		$id   = $this->_make_attachment( $file, 0 );
+		$id   = $this->_upload_file_and_make_attachment( $file );
 
 		// Request a size by array that doesn't exist and is smaller than the 'thumbnail'.
 		$image = image_get_intermediate_size( $id, array( 50, 25 ) );
@@ -282,7 +275,7 @@
 	 */
 	public function test_get_intermediate_size_with_small_size_array_fallback() {
 		$file = DIR_TESTDATA . '/images/waffles.jpg';
-		$id   = $this->_make_attachment( $file, 0 );
+		$id   = $this->_upload_file_and_make_attachment( $file );
 
 		$original       = wp_get_attachment_metadata( $id );
 		$thumbnail_file = $original['sizes']['thumbnail']['file'];
Index: tests/phpunit/tests/image/siteIcon.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/tests/phpunit/tests/image/siteIcon.php b/tests/phpunit/tests/image/siteIcon.php
--- a/tests/phpunit/tests/image/siteIcon.php	(revision a855e85c77f3cc978e960321e0c7a63fa808b9c1)
+++ b/tests/phpunit/tests/image/siteIcon.php	(date 1658218528989)
@@ -160,12 +160,7 @@
 			return $this->attachment_id;
 		}
 
-		$filename = DIR_TESTDATA . '/images/test-image.jpg';
-		$contents = file_get_contents( $filename );
-
-		$upload = wp_upload_bits( wp_basename( $filename ), null, $contents );
-
-		$this->attachment_id = $this->_make_attachment( $upload );
+		$this->attachment_id = $this->_upload_file_and_make_attachment( DIR_TESTDATA . '/images/test-image.jpg' );
 		return $this->attachment_id;
 	}
 }
Index: tests/phpunit/tests/ajax/Attachments.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/tests/phpunit/tests/ajax/Attachments.php b/tests/phpunit/tests/ajax/Attachments.php
--- a/tests/phpunit/tests/ajax/Attachments.php	(revision a855e85c77f3cc978e960321e0c7a63fa808b9c1)
+++ b/tests/phpunit/tests/ajax/Attachments.php	(date 1658215521820)
@@ -20,11 +20,7 @@
 		// Become an administrator.
 		$this->_setRole( 'administrator' );
 
-		$filename = DIR_TESTDATA . '/images/canola.jpg';
-		$contents = file_get_contents( $filename );
-
-		$upload     = wp_upload_bits( wp_basename( $filename ), null, $contents );
-		$attachment = $this->_make_attachment( $upload );
+		$attachment = $this->_upload_file_and_make_attachment( DIR_TESTDATA . '/images/canola.jpg' );
 
 		// Set up a default request.
 		$_POST['nonce']      = wp_create_nonce( 'media-send-to-editor' );
@@ -67,11 +63,7 @@
 		// Become an administrator.
 		$this->_setRole( 'administrator' );
 
-		$filename = DIR_TESTDATA . '/formatting/entities.txt';
-		$contents = file_get_contents( $filename );
-
-		$upload     = wp_upload_bits( wp_basename( $filename ), null, $contents );
-		$attachment = $this->_make_attachment( $upload );
+		$attachment = $this->_upload_file_and_make_attachment( DIR_TESTDATA . '/formatting/entities.txt' );
 
 		// Set up a default request.
 		$_POST['nonce']      = wp_create_nonce( 'media-send-to-editor' );
Index: tests/phpunit/includes/abstract-testcase.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/tests/phpunit/includes/abstract-testcase.php b/tests/phpunit/includes/abstract-testcase.php
--- a/tests/phpunit/includes/abstract-testcase.php	(revision a855e85c77f3cc978e960321e0c7a63fa808b9c1)
+++ b/tests/phpunit/includes/abstract-testcase.php	(date 1658219714987)
@@ -1507,6 +1507,23 @@
 		return $id;
 	}
 
+	/**
+	 * Uploads given file and creates an attachment post from it.
+	 *
+	 * @since 6.1.0
+	 *
+	 * @param array $filename       Absolute path to the file to upload.
+	 * @param int   $parent_post_id Optional. Parent post ID.
+	 *
+	 * @return int|WP_Error The attachment ID on success. The value 0 or WP_Error on failure.
+	 */
+	public function _upload_file_and_make_attachment( $filename, $parent_post_id = 0 ) {
+		$contents = file_get_contents( $filename );
+		$upload   = wp_upload_bits( wp_basename( $filename ), null, $contents );
+
+		return $this->_make_attachment( $upload, $parent_post_id );
+	}
+
 	/**
 	 * Updates the modified and modified GMT date of a post in the database.
 	 *
Index: tests/phpunit/tests/post/attachments.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/tests/phpunit/tests/post/attachments.php b/tests/phpunit/tests/post/attachments.php
--- a/tests/phpunit/tests/post/attachments.php	(revision a855e85c77f3cc978e960321e0c7a63fa808b9c1)
+++ b/tests/phpunit/tests/post/attachments.php	(date 1658217103253)
@@ -441,11 +441,7 @@
 	}
 
 	public function test_wp_attachment_is() {
-		$filename = DIR_TESTDATA . '/images/test-image.jpg';
-		$contents = file_get_contents( $filename );
-
-		$upload        = wp_upload_bits( wp_basename( $filename ), null, $contents );
-		$attachment_id = $this->_make_attachment( $upload );
+		$attachment_id = $this->_upload_file_and_make_attachment( DIR_TESTDATA . '/images/test-image.jpg' );
 
 		$this->assertTrue( wp_attachment_is_image( $attachment_id ) );
 		$this->assertTrue( wp_attachment_is( 'image', $attachment_id ) );
@@ -459,11 +455,7 @@
 			add_filter( 'upload_mimes', array( $this, 'allow_psd_mime_type' ), 10, 2 );
 		}
 
-		$filename = DIR_TESTDATA . '/images/test-image.psd';
-		$contents = file_get_contents( $filename );
-
-		$upload        = wp_upload_bits( wp_basename( $filename ), null, $contents );
-		$attachment_id = $this->_make_attachment( $upload );
+		$attachment_id = $this->_upload_file_and_make_attachment( DIR_TESTDATA . '/images/test-image.psd' );
 
 		$this->assertFalse( wp_attachment_is_image( $attachment_id ) );
 		$this->assertTrue( wp_attachment_is( 'psd', $attachment_id ) );
Index: tests/phpunit/tests/xmlrpc/wp/getMediaItem.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/tests/phpunit/tests/xmlrpc/wp/getMediaItem.php b/tests/phpunit/tests/xmlrpc/wp/getMediaItem.php
--- a/tests/phpunit/tests/xmlrpc/wp/getMediaItem.php	(revision a855e85c77f3cc978e960321e0c7a63fa808b9c1)
+++ b/tests/phpunit/tests/xmlrpc/wp/getMediaItem.php	(date 1658217017218)
@@ -19,11 +19,7 @@
 
 		add_theme_support( 'post-thumbnails' );
 
-		$filename = ( DIR_TESTDATA . '/images/waffles.jpg' );
-		$contents = file_get_contents( $filename );
-		$upload   = wp_upload_bits( wp_basename( $filename ), null, $contents );
-
-		$this->attachment_id   = $this->_make_attachment( $upload, self::$post_id );
+		$this->attachment_id   = $this->_upload_file_and_make_attachment( DIR_TESTDATA . '/images/waffles.jpg', self::$post_id );
 		$this->attachment_data = get_post( $this->attachment_id, ARRAY_A );
 
 		set_post_thumbnail( self::$post_id, $this->attachment_id );
Index: tests/phpunit/tests/ajax/MediaEdit.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/tests/phpunit/tests/ajax/MediaEdit.php b/tests/phpunit/tests/ajax/MediaEdit.php
--- a/tests/phpunit/tests/ajax/MediaEdit.php	(revision a855e85c77f3cc978e960321e0c7a63fa808b9c1)
+++ b/tests/phpunit/tests/ajax/MediaEdit.php	(date 1658216978976)
@@ -35,11 +35,7 @@
 	public function testCropImageThumbnail() {
 		require_once ABSPATH . 'wp-admin/includes/image-edit.php';
 
-		$filename = DIR_TESTDATA . '/images/canola.jpg';
-		$contents = file_get_contents( $filename );
-
-		$upload = wp_upload_bits( wp_basename( $filename ), null, $contents );
-		$id     = $this->_make_attachment( $upload );
+		$id     = $this->_upload_file_and_make_attachment( DIR_TESTDATA . '/images/canola.jpg' );
 
 		$_REQUEST['action']  = 'image-editor';
 		$_REQUEST['context'] = 'edit-attachment';
@@ -70,11 +66,7 @@
 
 		require_once ABSPATH . 'wp-admin/includes/image-edit.php';
 
-		$filename = DIR_TESTDATA . '/images/canola.jpg';
-		$contents = file_get_contents( $filename );
-
-		$upload = wp_upload_bits( wp_basename( $filename ), null, $contents );
-		$id     = $this->_make_attachment( $upload );
+		$id     = $this->_make_attachment( DIR_TESTDATA . '/images/canola.jpg' );
 
 		$_REQUEST['action']  = 'image-editor';
 		$_REQUEST['context'] = 'edit-attachment';
