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/user/countUserPosts.php

    r32523 r35186  
    99    static $post_ids = array();
    1010
    11     public static function setUpBeforeClass() {
    12         $factory = new WP_UnitTest_Factory();
    13 
     11    public static function wpSetUpBeforeClass( $factory ) {
    1412        self::$user_id = $factory->user->create( array(
    1513            'role' => 'author',
     
    3432            'post_type'   => 'wptests_pt',
    3533        ) ) );
    36 
    37         self::commit_transaction();
    3834    }
    3935
    40     public static function tearDownAfterClass() {
     36    public static function wpTearDownAfterClass() {
    4137        if ( is_multisite() ) {
    4238            wpmu_delete_user( self::$user_id );
     
    4844            wp_delete_post( $post_id, true );
    4945        }
    50 
    51         self::commit_transaction();
    5246    }
    5347
Note: See TracChangeset for help on using the changeset viewer.