Make WordPress Core

Changeset 29869


Ignore:
Timestamp:
10/10/2014 08:25:39 PM (10 years ago)
Author:
boonebgorges
Message:

Only reset taxonomies and post types between tests when running core tests.

A growing number of plugins and other WP-based projects use the core test
tools, such as WP_UnitTestCase, as the basis of their own tests and continuous
integration setups. At the same time, many of these third-party plugins use
custom post types and taxonomies, which are generally registered a single time
during a run of the tests: at 'init', before the testcases have run. Wiping out
these globals between tests will mess with these third-party builds.

Best practice for plugin developers is probably to clean up their own post types
and taxonomies and then reinitialize before each test. But, in the interest of
not breaking everyone's builds, the core test suite will not enforce this.

Fixes #29827.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/phpunit.xml.dist

    r25165 r29869  
    2626        <log type="junit" target="tests/phpunit/build/logs/junit.xml" logIncompleteSkipped="false"/>
    2727    </logging>
     28    <php>
     29        <const name="WP_RUN_CORE_TESTS" value="1" />
     30    </php>
    2831</phpunit>
  • trunk/tests/phpunit/includes/testcase.php

    r29860 r29869  
    3838        $this->factory = new WP_UnitTest_Factory;
    3939        $this->clean_up_global_scope();
    40         $this->reset_post_types();
    41         $this->reset_taxonomies();
     40
     41        /*
     42         * When running core tests, ensure that post types and taxonomies
     43         * are reset for each test. We skip this step for non-core tests,
     44         * given the large number of plugins that register post types and
     45         * taxonomies at 'init'.
     46         */
     47        if ( defined( 'WP_RUN_CORE_TESTS' ) && WP_RUN_CORE_TESTS ) {
     48            $this->reset_post_types();
     49            $this->reset_taxonomies();
     50        }
     51
    4252        $this->start_transaction();
    4353        $this->expectDeprecated();
Note: See TracChangeset for help on using the changeset viewer.