[wp-trac] [WordPress Trac] #56248: Reduce code duplication in tests that upload file as attachment

WordPress Trac noreply at wordpress.org
Tue Jul 19 07:32:00 UTC 2022


#56248: Reduce code duplication in tests that upload file as attachment
--------------------------+-----------------------------
 Reporter:  martin.krcho  |      Owner:  (none)
     Type:  enhancement   |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:  trunk
 Severity:  minor         |   Keywords:  needs-patch
  Focuses:                |
--------------------------+-----------------------------
 Couple of unit tests contain code to upload a file and make it an
 attachment. These could be simplified by removing some of the duplication.

 **Example of the duplicated code**
 {{{
 $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 );
 }}}

 As already discussed in [https://core.trac.wordpress.org/ticket/56203
 56203], the solution can be a general helper method in
 `WP_UnitTestCase_Base`, next to the `::_make_attachment()` method. That
 way it can also be reused in other tests. The name would probably be
 `_upload_file_and_make_attachment()` for consistency.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/56248>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list