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/post.php

    r35183 r35186  
    1010        protected static $grammarian_id;
    1111
    12         public static function setUpBeforeClass() {
    13                 parent::setUpBeforeClass();
    14 
    15                 $factory = new WP_UnitTest_Factory();
    16 
     12        public static function wpSetUpBeforeClass( $factory ) {
    1713                self::$editor_id = $factory->user->create( array( 'role' => 'editor' ) );
    1814
     
    2521
    2622                self::$grammarian_id = $factory->user->create( array( 'role' => 'grammarian' ) );
    27 
    28                 self::commit_transaction();
    29         }
    30 
    31         public static function tearDownAfterClass() {
    32                 parent::tearDownAfterClass();
    33 
     23        }
     24
     25        public static function wpTearDownAfterClass() {
    3426                $ids = array( self::$editor_id, self::$grammarian_id );
    3527                foreach ( $ids as $id ) {
     
    4032                        }
    4133                }
    42 
    43                 self::commit_transaction();
    4434        }
    4535
Note: See TracChangeset for help on using the changeset viewer.