From 666d07352e06b2a915297434304538892f803b4b Mon Sep 17 00:00:00 2001 From: "Dominik Schilling (ocean90)" Date: Thu, 15 Oct 2015 20:34:08 +0000 Subject: [PATCH] Tests: Don't preserve the global state for Ajax tests 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". See #31491. git-svn-id: https://develop.svn.wordpress.org/trunk@35209 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/includes/testcase-ajax.php | 15 +++++++++++++++ tests/phpunit/tests/ajax/Response.php | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) 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() {