diff --git a/tests/phpunit/includes/testcase-ajax.php b/tests/phpunit/includes/testcase-ajax.php index b415976f21..e48647201f 100644 --- a/tests/phpunit/includes/testcase-ajax.php +++ b/tests/phpunit/includes/testcase-ajax.php @@ -50,6 +50,21 @@ abstract class WP_Ajax_UnitTestCase extends WP_UnitTestCase { 'wp-remove-post-lock', 'dismiss-wp-pointer', 'heartbeat', 'nopriv_heartbeat', ); + /** + * Don't preserve the global state when using an external object cache. + * + * Most of the Ajax tests are running in a separate PHP process, and thus PHPUnit attempts + * to preserve the global state from the parent process by serializing all globals. + * But this doesn't work for external object caches so we have to disable this "feature". + */ + public function run( PHPUnit_Framework_TestResult $result = NULL ) { + if ( wp_using_ext_object_cache() ) { + $this->setPreserveGlobalState( false ); + } + + return parent::run( $result ); + } + /** * Set up the test fixture. * Override wp_die(), pretend to be ajax, and suppres E_WARNINGs diff --git a/tests/phpunit/tests/ajax/Response.php b/tests/phpunit/tests/ajax/Response.php index c987bf7ccb..9c48a8161d 100644 --- a/tests/phpunit/tests/ajax/Response.php +++ b/tests/phpunit/tests/ajax/Response.php @@ -6,6 +6,7 @@ * @subpackage UnitTests * @since 3.5.0 * @group ajax + * @runInSeparateProcess */ class Tests_Ajax_Response extends WP_UnitTestCase { @@ -64,7 +65,6 @@ class Tests_Ajax_Response extends WP_UnitTestCase { * Needs a separate process to get around the headers/output from the * bootstrapper * @ticket 19448 - * @runInSeparateProcess */ public function test_response_charset_in_header() {