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/feed/rss2.php

    r35162 r35186  
    1313    static $posts;
    1414
    15     public static function setUpBeforeClass() {
    16         $factory = new WP_UnitTest_Factory();
    17 
     15    public static function wpSetUpBeforeClass( $factory ) {
    1816        self::$user = $factory->user->create();
    1917        self::$posts = $factory->post->create_many( 5, array(
    2018            'post_author' => self::$user,
    2119        ) );
    22 
    23         self::commit_transaction();
    2420    }
    2521
    26     public static function tearDownAfterClass() {
     22    public static function wpTearDownAfterClass() {
    2723        if ( is_multisite() ) {
    2824            wpmu_delete_user( self::$user );
     
    3430            wp_delete_post( $post, true );
    3531        }
    36 
    37         self::commit_transaction();
    3832    }
    3933
Note: See TracChangeset for help on using the changeset viewer.