Make WordPress Core


Ignore:
Timestamp:
10/15/2015 04:43:37 AM (9 years ago)
Author:
wonderboymusic
Message:

Unit Tests: implement setUpBeforeClass() and tearDownAfterClass() on WP_UnitTestCase. Use late static binding (plus a gross fallback for PHP 5.2) to check if wpSetUpBeforeClass() or wpTearDownAfterClass() exist on the called class, and then call it and pass a static WP_UnitTest_Factory instance via Dependency Injection, if it exists.

This makes it way easier to add fixtures, and tear them down, without needing to instantiate WP_UnitTest_Factory in every class - removes the need to call commit_transaction() in each individual class.

See #30017, #33968.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/media.php

    r35181 r35186  
    88    protected static $large_id;
    99
    10     public static function setUpBeforeClass() {
    11         parent::setUpBeforeClass();
    12 
    13         $factory = new WP_UnitTest_Factory();
    14 
     10    public static function wpSetUpBeforeClass( $factory ) {
    1511        $filename = DIR_TESTDATA . '/images/test-image-large.png';
    1612        self::$large_id = $factory->attachment->create_upload_object( $filename );
    17 
    18         self::commit_transaction();
    19     }
    20 
    21     public static function tearDownAfterClass() {
    22         parent::tearDownAfterClass();
    23 
     13    }
     14
     15    public static function wpTearDownAfterClass() {
    2416        wp_delete_attachment( self::$large_id );
    25 
    26         self::commit_transaction();
    2717    }
    2818
Note: See TracChangeset for help on using the changeset viewer.