From bb1a9c9eb96c491f688e387b1ee812b7948cd880 Mon Sep 17 00:00:00 2001 From: Arkaprabha Chowdhury Date: Tue, 12 May 2026 15:15:29 +0530 Subject: [PATCH 1/8] Tests: Preserve default excluded groups when using --exclude-group. --- tests/phpunit/includes/abstract-testcase.php | 39 ++++++++++ tests/phpunit/includes/bootstrap.php | 82 +++++++++++++++++--- tests/phpunit/tests/phpunit/groupFilters.php | 52 +++++++++++++ 3 files changed, 162 insertions(+), 11 deletions(-) create mode 100644 tests/phpunit/tests/phpunit/groupFilters.php diff --git a/tests/phpunit/includes/abstract-testcase.php b/tests/phpunit/includes/abstract-testcase.php index 3a5d52b0706a9..7e27e496d0123 100644 --- a/tests/phpunit/includes/abstract-testcase.php +++ b/tests/phpunit/includes/abstract-testcase.php @@ -108,6 +108,8 @@ public function set_up() { set_time_limit( 0 ); + $this->skip_default_excluded_groups(); + $this->factory = static::factory(); if ( ! self::$ignore_files ) { @@ -143,6 +145,43 @@ public function set_up() { add_filter( 'wp_hash_password_options', array( $this, 'wp_hash_password_options' ), 1, 2 ); } + /** + * Skips tests that belong to groups excluded by default unless those groups were explicitly requested. + */ + protected function skip_default_excluded_groups() { + $skipped_groups = self::get_default_excluded_groups_for_test( $this->getGroups() ); + + if ( $skipped_groups ) { + $this->markTestSkipped( + sprintf( + 'This test belongs to a group that is skipped by default: %s. Use --group %s to run it.', + implode( ', ', $skipped_groups ), + $skipped_groups[0] + ) + ); + } + } + + /** + * Returns the default-excluded groups that apply to a test and were not explicitly requested. + * + * @param string[] $groups Test groups. + * @return string[] Matching excluded groups. + */ + public static function get_default_excluded_groups_for_test( array $groups ) { + $default_excluded_groups = WP_PHPUnit_Util_Getopt::get_skipped_groups(); + + return array_values( + array_filter( + $groups, + static function ( $group ) use ( $default_excluded_groups ) { + return in_array( $group, $default_excluded_groups, true ) + && ! WP_PHPUnit_Util_Getopt::is_group_requested( $group ); + } + ) + ); + } + /** * Sets the bcrypt cost option for password hashing during tests. * diff --git a/tests/phpunit/includes/bootstrap.php b/tests/phpunit/includes/bootstrap.php index e308dcb5a6e1c..f5749b949f597 100644 --- a/tests/phpunit/includes/bootstrap.php +++ b/tests/phpunit/includes/bootstrap.php @@ -345,42 +345,83 @@ function wp_tests_options( $value ) { * how you call phpunit has no effect. */ class WP_PHPUnit_Util_Getopt { - - public function __construct( $argv ) { + /** + * Groups that are skipped by default for the current test run. + * + * @var array + */ + protected static $skipped_groups = array(); + + /** + * Groups that were explicitly requested via the command line. + * + * @var array + */ + protected static $requested_groups = array(); + + /** + * Initializes the default skipped groups for the current test mode. + * + * @return array The groups skipped by default. + */ + protected static function get_default_skipped_groups() { $skipped_groups = array( - 'ajax' => true, - 'ms-files' => true, - 'external-http' => true, + 'ajax' => true, + 'ms-files' => true, + 'external-http' => true, + 'html-api-html5lib-tests' => true, ); + if ( defined( 'WP_TESTS_MULTISITE' ) && WP_TESTS_MULTISITE ) { + $skipped_groups['ms-excluded'] = true; + $skipped_groups['oembed-headers'] = true; + } else { + $skipped_groups['ms-required'] = true; + } + + return $skipped_groups; + } + + /** + * Resets the parsed command line state. + */ + public static function reset() { + self::$skipped_groups = self::get_default_skipped_groups(); + self::$requested_groups = array(); + } + + public function __construct( $argv ) { + self::reset(); + while ( current( $argv ) ) { $option = current( $argv ); $value = next( $argv ); switch ( $option ) { case '--exclude-group': - foreach ( $skipped_groups as $group_name => $skipped ) { - $skipped_groups[ $group_name ] = false; - } + // PHPUnit replaces XML exclusions when this option is provided. + // Keep our default skipped groups active unless they are requested explicitly. continue 2; case '--group': $groups = explode( ',', $value ); foreach ( $groups as $group ) { + self::$requested_groups[ $group ] = true; + if ( is_numeric( $group ) || preg_match( '/^(UT|Plugin)\d+$/', $group ) ) { WP_UnitTestCase::forceTicket( $group ); } } - foreach ( $skipped_groups as $group_name => $skipped ) { + foreach ( self::$skipped_groups as $group_name => $skipped ) { if ( in_array( $group_name, $groups, true ) ) { - $skipped_groups[ $group_name ] = false; + self::$skipped_groups[ $group_name ] = false; } } continue 2; } } - $skipped_groups = array_filter( $skipped_groups ); + $skipped_groups = array_filter( self::$skipped_groups ); foreach ( $skipped_groups as $group_name => $skipped ) { echo sprintf( 'Not running %1$s tests. To execute these, use --group %1$s.', $group_name ) . PHP_EOL; } @@ -392,5 +433,24 @@ public function __construct( $argv ) { echo PHP_EOL; } } + + /** + * Returns the groups that are still skipped by default for this run. + * + * @return string[] + */ + public static function get_skipped_groups() { + return array_keys( array_filter( self::$skipped_groups ) ); + } + + /** + * Determines whether a group was explicitly requested via the command line. + * + * @param string $group Group name. + * @return bool Whether the group was explicitly requested. + */ + public static function is_group_requested( $group ) { + return isset( self::$requested_groups[ $group ] ); + } } new WP_PHPUnit_Util_Getopt( $_SERVER['argv'] ); diff --git a/tests/phpunit/tests/phpunit/groupFilters.php b/tests/phpunit/tests/phpunit/groupFilters.php new file mode 100644 index 0000000000000..a8d8d0d729124 --- /dev/null +++ b/tests/phpunit/tests/phpunit/groupFilters.php @@ -0,0 +1,52 @@ +assertSame( + array( 'ajax', 'external-http' ), + WP_UnitTestCase_Base::get_default_excluded_groups_for_test( array( 'ajax', 'external-http', 'query' ) ) + ); + } + + public function test_requested_group_is_not_reported_as_default_excluded() { + ob_start(); + new WP_PHPUnit_Util_Getopt( + array( + 'phpunit', + '--group', + 'ajax', + ) + ); + ob_end_clean(); + + $this->assertSame( + array(), + WP_UnitTestCase_Base::get_default_excluded_groups_for_test( array( 'ajax' ) ) + ); + } + + public function test_exclude_group_does_not_clear_default_excluded_groups() { + ob_start(); + new WP_PHPUnit_Util_Getopt( + array( + 'phpunit', + '--exclude-group', + 'import', + ) + ); + ob_end_clean(); + + $this->assertSame( + array( 'ajax', 'ms-required' ), + WP_UnitTestCase_Base::get_default_excluded_groups_for_test( array( 'ajax', 'ms-required' ) ) + ); + } +} From a9c38ec88603de30663a082b3723f6bea8a01d81 Mon Sep 17 00:00:00 2001 From: Arkaprabha Chowdhury Date: Tue, 12 May 2026 15:27:43 +0530 Subject: [PATCH 2/8] Tests: Fix PHPCS alignment warnings in bootstrap. --- tests/phpunit/includes/bootstrap.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/phpunit/includes/bootstrap.php b/tests/phpunit/includes/bootstrap.php index f5749b949f597..d54ed34ab64c4 100644 --- a/tests/phpunit/includes/bootstrap.php +++ b/tests/phpunit/includes/bootstrap.php @@ -366,9 +366,9 @@ class WP_PHPUnit_Util_Getopt { */ protected static function get_default_skipped_groups() { $skipped_groups = array( - 'ajax' => true, - 'ms-files' => true, - 'external-http' => true, + 'ajax' => true, + 'ms-files' => true, + 'external-http' => true, 'html-api-html5lib-tests' => true, ); @@ -386,7 +386,7 @@ protected static function get_default_skipped_groups() { * Resets the parsed command line state. */ public static function reset() { - self::$skipped_groups = self::get_default_skipped_groups(); + self::$skipped_groups = self::get_default_skipped_groups(); self::$requested_groups = array(); } From 59f1cd6b4bd6d53a8ba25c80b9bda6f8cccd921b Mon Sep 17 00:00:00 2001 From: Arkaprabha Chowdhury Date: Tue, 12 May 2026 16:01:56 +0530 Subject: [PATCH 3/8] Tests: Account for multisite default excluded groups. --- tests/phpunit/tests/phpunit/groupFilters.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/tests/phpunit/groupFilters.php b/tests/phpunit/tests/phpunit/groupFilters.php index a8d8d0d729124..f06137aa057e2 100644 --- a/tests/phpunit/tests/phpunit/groupFilters.php +++ b/tests/phpunit/tests/phpunit/groupFilters.php @@ -44,9 +44,11 @@ public function test_exclude_group_does_not_clear_default_excluded_groups() { ); ob_end_clean(); + $multisite_excluded_group = is_multisite() ? 'ms-excluded' : 'ms-required'; + $this->assertSame( - array( 'ajax', 'ms-required' ), - WP_UnitTestCase_Base::get_default_excluded_groups_for_test( array( 'ajax', 'ms-required' ) ) + array( 'ajax', $multisite_excluded_group ), + WP_UnitTestCase_Base::get_default_excluded_groups_for_test( array( 'ajax', $multisite_excluded_group ) ) ); } } From cfd1c8121aadb8869fbd7d8ad36e699affabf0ea Mon Sep 17 00:00:00 2001 From: ArkaPrabhaChowdhury Date: Mon, 2 Nov 2026 16:48:44 +0530 Subject: [PATCH 4/8] Tests: Filter default-excluded groups before fixtures --- phpunit.xml.dist | 3 + tests/phpunit/includes/abstract-testcase.php | 28 ++------ tests/phpunit/includes/bootstrap.php | 60 +++++++++++++--- tests/phpunit/multisite.xml | 3 + tests/phpunit/tests/phpunit/groupFilters.php | 76 ++++++++++++++++---- 5 files changed, 127 insertions(+), 43 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 4b6c149867c7d..ef256ccc93308 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -32,6 +32,9 @@ html-api-html5lib-tests + + + diff --git a/tests/phpunit/includes/abstract-testcase.php b/tests/phpunit/includes/abstract-testcase.php index 7e27e496d0123..f0c702daf08d1 100644 --- a/tests/phpunit/includes/abstract-testcase.php +++ b/tests/phpunit/includes/abstract-testcase.php @@ -108,8 +108,6 @@ public function set_up() { set_time_limit( 0 ); - $this->skip_default_excluded_groups(); - $this->factory = static::factory(); if ( ! self::$ignore_files ) { @@ -145,23 +143,6 @@ public function set_up() { add_filter( 'wp_hash_password_options', array( $this, 'wp_hash_password_options' ), 1, 2 ); } - /** - * Skips tests that belong to groups excluded by default unless those groups were explicitly requested. - */ - protected function skip_default_excluded_groups() { - $skipped_groups = self::get_default_excluded_groups_for_test( $this->getGroups() ); - - if ( $skipped_groups ) { - $this->markTestSkipped( - sprintf( - 'This test belongs to a group that is skipped by default: %s. Use --group %s to run it.', - implode( ', ', $skipped_groups ), - $skipped_groups[0] - ) - ); - } - } - /** * Returns the default-excluded groups that apply to a test and were not explicitly requested. * @@ -171,12 +152,17 @@ protected function skip_default_excluded_groups() { public static function get_default_excluded_groups_for_test( array $groups ) { $default_excluded_groups = WP_PHPUnit_Util_Getopt::get_skipped_groups(); + foreach ( $groups as $group ) { + if ( WP_PHPUnit_Util_Getopt::is_group_requested( $group ) ) { + return array(); + } + } + return array_values( array_filter( $groups, static function ( $group ) use ( $default_excluded_groups ) { - return in_array( $group, $default_excluded_groups, true ) - && ! WP_PHPUnit_Util_Getopt::is_group_requested( $group ); + return in_array( $group, $default_excluded_groups, true ); } ) ); diff --git a/tests/phpunit/includes/bootstrap.php b/tests/phpunit/includes/bootstrap.php index d54ed34ab64c4..bbeb1da08058b 100644 --- a/tests/phpunit/includes/bootstrap.php +++ b/tests/phpunit/includes/bootstrap.php @@ -372,7 +372,7 @@ protected static function get_default_skipped_groups() { 'html-api-html5lib-tests' => true, ); - if ( defined( 'WP_TESTS_MULTISITE' ) && WP_TESTS_MULTISITE ) { + if ( is_multisite() ) { $skipped_groups['ms-excluded'] = true; $skipped_groups['oembed-headers'] = true; } else { @@ -383,9 +383,9 @@ protected static function get_default_skipped_groups() { } /** - * Resets the parsed command line state. + * Initializes the parsed command line state. */ - public static function reset() { + protected static function reset() { self::$skipped_groups = self::get_default_skipped_groups(); self::$requested_groups = array(); } @@ -393,15 +393,20 @@ public static function reset() { public function __construct( $argv ) { self::reset(); - while ( current( $argv ) ) { - $option = current( $argv ); - $value = next( $argv ); + foreach ( $argv as $index => $argument ) { + $option = $argument; + $value = isset( $argv[ $index + 1 ] ) ? $argv[ $index + 1 ] : ''; + + if ( 0 === strpos( $option, '--group=' ) ) { + $value = substr( $option, strlen( '--group=' ) ); + $option = '--group'; + } switch ( $option ) { case '--exclude-group': // PHPUnit replaces XML exclusions when this option is provided. // Keep our default skipped groups active unless they are requested explicitly. - continue 2; + break; case '--group': $groups = explode( ',', $value ); foreach ( $groups as $group ) { @@ -417,7 +422,7 @@ public function __construct( $argv ) { self::$skipped_groups[ $group_name ] = false; } } - continue 2; + break; } } @@ -454,3 +459,42 @@ public static function is_group_requested( $group ) { } } new WP_PHPUnit_Util_Getopt( $_SERVER['argv'] ); + +/** + * Removes default-excluded tests from PHPUnit suites before class fixtures run. + */ +class WP_PHPUnit_Default_Group_Filter implements PHPUnit\Framework\TestListener { + use PHPUnit\Framework\TestListenerDefaultImplementation; + + /** + * Filters default-excluded tests from a suite and all nested suites. + * + * @param PHPUnit\Framework\TestSuite $suite Test suite. + */ + public function startTestSuite( PHPUnit\Framework\TestSuite $suite ): void { + $this->filter_suite( $suite ); + } + + /** + * Filters a test suite recursively. + * + * @param PHPUnit\Framework\TestSuite $suite Test suite. + */ + protected function filter_suite( PHPUnit\Framework\TestSuite $suite ) { + $tests = array(); + + foreach ( $suite->tests() as $test ) { + if ( $test instanceof PHPUnit\Framework\TestSuite ) { + $this->filter_suite( $test ); + + if ( count( $test ) ) { + $tests[] = $test; + } + } elseif ( ! method_exists( $test, 'getGroups' ) || ! WP_UnitTestCase_Base::get_default_excluded_groups_for_test( $test->getGroups() ) ) { + $tests[] = $test; + } + } + + $suite->setTests( $tests ); + } +} diff --git a/tests/phpunit/multisite.xml b/tests/phpunit/multisite.xml index d8f173c6167ac..c62304e896843 100644 --- a/tests/phpunit/multisite.xml +++ b/tests/phpunit/multisite.xml @@ -37,6 +37,9 @@ html-api-html5lib-tests + + + ../../src diff --git a/tests/phpunit/tests/phpunit/groupFilters.php b/tests/phpunit/tests/phpunit/groupFilters.php index f06137aa057e2..fb41a8b0be43b 100644 --- a/tests/phpunit/tests/phpunit/groupFilters.php +++ b/tests/phpunit/tests/phpunit/groupFilters.php @@ -4,8 +4,13 @@ */ class Tests_PHPUnit_GroupFilters extends WP_UnitTestCase { + public function set_up() { + parent::set_up(); + $this->parse_arguments( array( 'phpunit' ) ); + } + public function tear_down() { - WP_PHPUnit_Util_Getopt::reset(); + $this->parse_arguments( $_SERVER['argv'] ); parent::tear_down(); } @@ -16,16 +21,13 @@ public function test_single_site_default_excluded_groups_are_reported() { ); } - public function test_requested_group_is_not_reported_as_default_excluded() { - ob_start(); - new WP_PHPUnit_Util_Getopt( - array( - 'phpunit', - '--group', - 'ajax', - ) - ); - ob_end_clean(); + /** + * @dataProvider data_group_argument_syntax + * + * @param string[] $arguments Command line arguments. + */ + public function test_requested_group_is_not_reported_as_default_excluded( $arguments ) { + $this->parse_arguments( $arguments ); $this->assertSame( array(), @@ -33,16 +35,26 @@ public function test_requested_group_is_not_reported_as_default_excluded() { ); } + /** + * Data provider. + * + * @return array>> + */ + public function data_group_argument_syntax() { + return array( + 'spaced' => array( array( 'phpunit', '--group', 'ajax' ) ), + 'equals' => array( array( 'phpunit', '--group=ajax' ) ), + ); + } + public function test_exclude_group_does_not_clear_default_excluded_groups() { - ob_start(); - new WP_PHPUnit_Util_Getopt( + $this->parse_arguments( array( 'phpunit', '--exclude-group', 'import', ) ); - ob_end_clean(); $multisite_excluded_group = is_multisite() ? 'ms-excluded' : 'ms-required'; @@ -51,4 +63,40 @@ public function test_exclude_group_does_not_clear_default_excluded_groups() { WP_UnitTestCase_Base::get_default_excluded_groups_for_test( array( 'ajax', $multisite_excluded_group ) ) ); } + + public function test_requested_group_allows_a_test_in_a_default_excluded_group() { + $this->parse_arguments( array( 'phpunit', '--group', 'xdebug' ) ); + + $this->assertSame( + array(), + WP_UnitTestCase_Base::get_default_excluded_groups_for_test( array( 'ajax', 'xdebug' ) ) + ); + } + + public function test_default_group_filter_removes_tests_from_nested_suites() { + $test = clone $this; + $test->setGroups( array( 'ajax' ) ); + + $class_suite = new PHPUnit\Framework\TestSuite(); + $class_suite->addTest( $test ); + + $root_suite = new PHPUnit\Framework\TestSuite(); + $root_suite->addTest( $class_suite ); + + $filter = new WP_PHPUnit_Default_Group_Filter(); + $filter->startTestSuite( $root_suite ); + + $this->assertCount( 0, $root_suite ); + } + + /** + * Parses command line arguments without printing group notices. + * + * @param string[] $arguments Command line arguments. + */ + private function parse_arguments( $arguments ) { + ob_start(); + new WP_PHPUnit_Util_Getopt( $arguments ); + ob_end_clean(); + } } From 71350ab9cfba5189319176fd86f030bd220e446b Mon Sep 17 00:00:00 2001 From: ArkaPrabhaChowdhury Date: Mon, 2 Nov 2026 17:09:59 +0530 Subject: [PATCH 5/8] Tests: Preserve groups in filter test suite --- tests/phpunit/tests/phpunit/groupFilters.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/phpunit/tests/phpunit/groupFilters.php b/tests/phpunit/tests/phpunit/groupFilters.php index fb41a8b0be43b..ad3b27c8d79b7 100644 --- a/tests/phpunit/tests/phpunit/groupFilters.php +++ b/tests/phpunit/tests/phpunit/groupFilters.php @@ -75,10 +75,9 @@ public function test_requested_group_allows_a_test_in_a_default_excluded_group() public function test_default_group_filter_removes_tests_from_nested_suites() { $test = clone $this; - $test->setGroups( array( 'ajax' ) ); $class_suite = new PHPUnit\Framework\TestSuite(); - $class_suite->addTest( $test ); + $class_suite->addTest( $test, array( 'ajax' ) ); $root_suite = new PHPUnit\Framework\TestSuite(); $root_suite->addTest( $class_suite ); From 906f55061b451ec165dcdeaf03b5d6382c0357dd Mon Sep 17 00:00:00 2001 From: ArkaPrabhaChowdhury Date: Tue, 3 Nov 2026 13:19:52 +0530 Subject: [PATCH 6/8] Tests: Support legacy PHPUnit group listener --- tests/phpunit/includes/bootstrap.php | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/tests/phpunit/includes/bootstrap.php b/tests/phpunit/includes/bootstrap.php index bbeb1da08058b..ba1dde5f3012c 100644 --- a/tests/phpunit/includes/bootstrap.php +++ b/tests/phpunit/includes/bootstrap.php @@ -463,15 +463,14 @@ public static function is_group_requested( $group ) { /** * Removes default-excluded tests from PHPUnit suites before class fixtures run. */ -class WP_PHPUnit_Default_Group_Filter implements PHPUnit\Framework\TestListener { - use PHPUnit\Framework\TestListenerDefaultImplementation; +trait WP_PHPUnit_Default_Group_Filter_Methods { /** * Filters default-excluded tests from a suite and all nested suites. * * @param PHPUnit\Framework\TestSuite $suite Test suite. */ - public function startTestSuite( PHPUnit\Framework\TestSuite $suite ): void { + public function start_test_suite( $suite ) { $this->filter_suite( $suite ); } @@ -480,7 +479,7 @@ public function startTestSuite( PHPUnit\Framework\TestSuite $suite ): void { * * @param PHPUnit\Framework\TestSuite $suite Test suite. */ - protected function filter_suite( PHPUnit\Framework\TestSuite $suite ) { + protected function filter_suite( $suite ) { $tests = array(); foreach ( $suite->tests() as $test ) { @@ -498,3 +497,17 @@ protected function filter_suite( PHPUnit\Framework\TestSuite $suite ) { $suite->setTests( $tests ); } } + +if ( version_compare( tests_get_phpunit_version(), '6.0', '<' ) ) { + class WP_PHPUnit_Default_Group_Filter implements PHPUnit_Framework_TestListener { + use Yoast\PHPUnitPolyfills\TestListeners\TestListenerDefaultImplementation, WP_PHPUnit_Default_Group_Filter_Methods { + WP_PHPUnit_Default_Group_Filter_Methods::start_test_suite insteadof Yoast\PHPUnitPolyfills\TestListeners\TestListenerDefaultImplementation; + } + } +} else { + class WP_PHPUnit_Default_Group_Filter implements PHPUnit\Framework\TestListener { + use Yoast\PHPUnitPolyfills\TestListeners\TestListenerDefaultImplementation, WP_PHPUnit_Default_Group_Filter_Methods { + WP_PHPUnit_Default_Group_Filter_Methods::start_test_suite insteadof Yoast\PHPUnitPolyfills\TestListeners\TestListenerDefaultImplementation; + } + } +} From 62bf4d92bcfa57c37252223d27d3314baa14adea Mon Sep 17 00:00:00 2001 From: ArkaPrabhaChowdhury Date: Wed, 4 Nov 2026 13:53:03 +0530 Subject: [PATCH 7/8] Tests: Recognize legacy PHPUnit nested suites --- tests/phpunit/includes/bootstrap.php | 2 +- tests/phpunit/tests/phpunit/groupFilters.php | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/tests/phpunit/includes/bootstrap.php b/tests/phpunit/includes/bootstrap.php index ba1dde5f3012c..a4b7025ed750c 100644 --- a/tests/phpunit/includes/bootstrap.php +++ b/tests/phpunit/includes/bootstrap.php @@ -483,7 +483,7 @@ protected function filter_suite( $suite ) { $tests = array(); foreach ( $suite->tests() as $test ) { - if ( $test instanceof PHPUnit\Framework\TestSuite ) { + if ( $test instanceof PHPUnit\Framework\TestSuite || $test instanceof PHPUnit_Framework_TestSuite ) { $this->filter_suite( $test ); if ( count( $test ) ) { diff --git a/tests/phpunit/tests/phpunit/groupFilters.php b/tests/phpunit/tests/phpunit/groupFilters.php index ad3b27c8d79b7..6258361ddf6b6 100644 --- a/tests/phpunit/tests/phpunit/groupFilters.php +++ b/tests/phpunit/tests/phpunit/groupFilters.php @@ -74,10 +74,10 @@ public function test_requested_group_allows_a_test_in_a_default_excluded_group() } public function test_default_group_filter_removes_tests_from_nested_suites() { - $test = clone $this; - - $class_suite = new PHPUnit\Framework\TestSuite(); - $class_suite->addTest( $test, array( 'ajax' ) ); + $class_suite = class_exists( 'PHPUnit_Framework_TestSuite' ) ? new PHPUnit_Framework_TestSuite() : new PHPUnit\Framework\TestSuite(); + $class_suite->addTest( clone $this, array( 'phpunit' ) ); + $class_suite->addTest( clone $this, array( 'ajax' ) ); + $class_suite->addTest( clone $this, array( 'phpunit' ) ); $root_suite = new PHPUnit\Framework\TestSuite(); $root_suite->addTest( $class_suite ); @@ -85,7 +85,8 @@ public function test_default_group_filter_removes_tests_from_nested_suites() { $filter = new WP_PHPUnit_Default_Group_Filter(); $filter->startTestSuite( $root_suite ); - $this->assertCount( 0, $root_suite ); + $this->assertCount( 1, $root_suite ); + $this->assertCount( 2, $class_suite ); } /** From 5738630926e2057f17833bca6378b42daceb97a3 Mon Sep 17 00:00:00 2001 From: ArkaPrabhaChowdhury Date: Wed, 4 Nov 2026 14:08:17 +0530 Subject: [PATCH 8/8] Tests: Count retained nested tests --- tests/phpunit/tests/phpunit/groupFilters.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/phpunit/tests/phpunit/groupFilters.php b/tests/phpunit/tests/phpunit/groupFilters.php index 6258361ddf6b6..eea4333e7ce00 100644 --- a/tests/phpunit/tests/phpunit/groupFilters.php +++ b/tests/phpunit/tests/phpunit/groupFilters.php @@ -85,7 +85,7 @@ public function test_default_group_filter_removes_tests_from_nested_suites() { $filter = new WP_PHPUnit_Default_Group_Filter(); $filter->startTestSuite( $root_suite ); - $this->assertCount( 1, $root_suite ); + $this->assertCount( 2, $root_suite ); $this->assertCount( 2, $class_suite ); }