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/term.php

    r35185 r35186  
    88    protected static $post_ids = array();
    99
    10     public static function setUpBeforeClass() {
    11         parent::setUpBeforeClass();
    12 
    13         $factory = new WP_UnitTest_Factory();
    14 
     10    public static function wpSetUpBeforeClass( $factory ) {
    1511        self::$post_ids = $factory->post->create_many( 5 );
    16 
    17         self::commit_transaction();
    18     }
    19 
    20     public static function tearDownAfterClass() {
    21         parent::tearDownAfterClass();
    22 
     12    }
     13
     14    public static function wpTearDownAfterClass() {
    2315        array_map( 'wp_delete_post', self::$post_ids );
    24 
    25         self::commit_transaction();
    2616    }
    2717
Note: See TracChangeset for help on using the changeset viewer.