Make WordPress Core


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

    r35165 r35186  
    1717        }
    1818
    19         public static function setUpBeforeClass() {
    20                 $factory = new WP_UnitTest_Factory();
    21 
     19        public static function wpSetUpBeforeClass( $factory ) {
    2220                // note that our top/children/grandchildren arrays are 1-indexed
    2321
    … …  
    6563                        }
    6664                }
    67 
    68                 self::commit_transaction();
    69         }
    70 
    71         public static function tearDownAfterClass() {
     65        }
     66
     67        public static function wpTearDownAfterClass() {
    7268                foreach ( self::$post_ids as $post_id ) {
    7369                        wp_delete_post( $post_id, true );
    7470                }
    75 
    76                 self::commit_transaction();
    7771        }
    7872
Note: See TracChangeset for help on using the changeset viewer.