diff --git tests/phpunit/includes/testcase-ajax.php tests/phpunit/includes/testcase-ajax.php
index 930ac4d3c4..2227413511 100644
--- tests/phpunit/includes/testcase-ajax.php
+++ tests/phpunit/includes/testcase-ajax.php
@@ -59,9 +59,7 @@ abstract class WP_Ajax_UnitTestCase extends WP_UnitTestCase {
 	);
 
 	public static function setUpBeforeClass() {
-		if ( ! defined( 'DOING_AJAX' ) ) {
-			define( 'DOING_AJAX', true );
-		}
+		add_filter( 'wp_doing_ajax', '__return_true' );		
 
 		remove_action( 'admin_init', '_maybe_update_core' );
 		remove_action( 'admin_init', '_maybe_update_plugins' );
diff --git tests/phpunit/tests/ajax/Response.php tests/phpunit/tests/ajax/Response.php
index bc99341fb0..b08b716313 100644
--- tests/phpunit/tests/ajax/Response.php
+++ tests/phpunit/tests/ajax/Response.php
@@ -23,8 +23,7 @@ class Tests_Ajax_Response extends WP_UnitTestCase {
 		parent::setUp();
 
 		add_filter( 'wp_die_ajax_handler', array( $this, 'getDieHandler' ), 1, 1 );
-		if ( !defined( 'DOING_AJAX' ) )
-			define( 'DOING_AJAX', true );
+		add_filter( 'wp_doing_ajax', '__return_true' );
 
 		// Suppress warnings from "Cannot modify header information - headers already sent by"
 		$this->_error_level = error_reporting();
diff --git tests/phpunit/tests/customize/manager.php tests/phpunit/tests/customize/manager.php
index 36905e292d..0f64400c00 100644
--- tests/phpunit/tests/customize/manager.php
+++ tests/phpunit/tests/customize/manager.php
@@ -1544,9 +1544,7 @@ class Tests_WP_Customize_Manager extends WP_UnitTestCase {
 	 * @group ajax
 	 */
 	function test_doing_ajax() {
-		if ( ! defined( 'DOING_AJAX' ) ) {
-			define( 'DOING_AJAX', true );
-		}
+		add_filter( 'wp_doing_ajax', '__return_true' );
 
 		$manager = $this->manager;
 		$this->assertTrue( $manager->doing_ajax() );
@@ -1560,10 +1558,6 @@ class Tests_WP_Customize_Manager extends WP_UnitTestCase {
 	 * Test ! WP_Customize_Manager::doing_ajax().
 	 */
 	function test_not_doing_ajax() {
-		if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
-			$this->markTestSkipped( 'Cannot test when DOING_AJAX' );
-		}
-
 		$manager = $this->manager;
 		$this->assertFalse( $manager->doing_ajax() );
 	}
diff --git tests/phpunit/tests/customize/selective-refresh-ajax.php tests/phpunit/tests/customize/selective-refresh-ajax.php
index 35ac86c281..f7fdb2b9ed 100644
--- tests/phpunit/tests/customize/selective-refresh-ajax.php
+++ tests/phpunit/tests/customize/selective-refresh-ajax.php
@@ -37,10 +37,8 @@ class Test_WP_Customize_Selective_Refresh_Ajax extends WP_UnitTestCase {
 	function setUp() {
 		parent::setUp();
 
-		// Define DOING_AJAX so that wp_die() will be used instead of die().
-		if ( ! defined( 'DOING_AJAX' ) ) {
-			define( 'DOING_AJAX', true );
-		}
+		// Define wp_doing_ajax so that wp_die() will be used instead of die().
+		add_filter( 'wp_doing_ajax', '__return_true' );
 		add_filter( 'wp_die_ajax_handler', array( $this, 'get_wp_die_handler' ), 1, 1 );
 
 		require_once( ABSPATH . WPINC . '/class-wp-customize-manager.php' );
