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

    r31676 r35186  
    2424        'html'          => true );
    2525        */
    26     public static function setUpBeforeClass() {
    27         $factory = new WP_UnitTest_Factory;
    28 
     26    public static function wpSetUpBeforeClass( $factory ) {
    2927        self::$users[] = $factory->user->create( array( 'user_login' => 'zack', 'display_name' => 'zack', 'role' => 'author', 'first_name' => 'zack', 'last_name' => 'moon' ) );
    3028        self::$users[] = $factory->user->create( array( 'user_login' => 'bob', 'display_name' => 'bob', 'role' => 'author', 'first_name' => 'bob', 'last_name' => 'reno' ) );
     
    4139            self::$user_urls[] = get_author_posts_url( $userid );
    4240        }
    43 
    44         self::commit_transaction();
    4541    }
    4642
    47     public static function tearDownAfterClass() {
     43    public static function wpTearDownAfterClass() {
    4844        foreach ( array_merge( self::$users, array( self::$fred_id ) ) as $user_id ) {
    4945            if ( is_multisite() ) {
     
    5753            wp_delete_post( $post_id, true );
    5854        }
    59 
    60         self::commit_transaction();
    6155    }
    6256
Note: See TracChangeset for help on using the changeset viewer.