WordPress.org

Make WordPress Core


Ignore:
Timestamp:
10/15/2015 04:43:37 AM (5 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/auth.php

    r35175 r35186  
    1616    protected $nonce_failure_hook = 'wp_verify_nonce_failed';
    1717
    18     static function setUpBeforeClass() {
    19         parent::setUpBeforeClass();
    20 
    21         $factory = new WP_UnitTest_Factory();
    22 
     18    public static function wpSetUpBeforeClass( $factory ) {
    2319        self::$_user = $factory->user->create_and_get( array(
    2420            'user_login' => 'password-tests'
     
    2925        require_once( ABSPATH . WPINC . '/class-phpass.php' );
    3026        self::$wp_hasher = new PasswordHash( 8, true );
    31 
    32         self::commit_transaction();
    33     }
    34 
    35     public static function tearDownAfterClass() {
    36         parent::tearDownAfterClass();
    37 
     27    }
     28
     29    public static function wpTearDownAfterClass() {
    3830        if ( is_multisite() ) {
    3931            wpmu_delete_user( self::$user_id );
     
    4133            wp_delete_user( self::$user_id );
    4234        }
    43 
    44         self::commit_transaction();
    4535    }
    4636
Note: See TracChangeset for help on using the changeset viewer.