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

    r34122 r35186  
    88class Tests_AdminBar extends WP_UnitTestCase {
    99
    10     static function setUpBeforeClass() {
    11         WP_UnitTestCase::setUpBeforeClass();
    12         require_once ABSPATH . WPINC . '/class-wp-admin-bar.php';
    13     }
    14 
    15     function setUp() {
    16         parent::setUp();
    17         $this->current_user = get_current_user_id();
    18     }
    19 
    20     function tearDown() {
    21         wp_set_current_user( $this->current_user );
    22         parent::tearDown();
     10    public static function setUpBeforeClass() {
     11        require_once( ABSPATH . WPINC . '/class-wp-admin-bar.php' );
    2312    }
    2413
Note: See TracChangeset for help on using the changeset viewer.