From 79bf20d320799e6c1d9d8b32b63d4fcea0910a75 Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Wed, 25 Apr 2018 22:37:08 +0000 Subject: [PATCH] Tests: Skip multisite-only or single site-only tests correctly based on test doc annotations. Without the `ms-required` and `ms-excluded` groups being marked as excluded in the PHPUnit configurations for the project, those groups were still executed, causing fatal errors. Checking against the groups in the correct structure of the array returned from PHPUnit's `Testcase::getAnnotations()` ensures that those tests are skipped properly. Fixes #43863. git-svn-id: https://develop.svn.wordpress.org/trunk@43005 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/includes/testcase.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tests/phpunit/includes/testcase.php b/tests/phpunit/includes/testcase.php index abdb9cc69e..db3f0b9fb6 100644 --- a/tests/phpunit/includes/testcase.php +++ b/tests/phpunit/includes/testcase.php @@ -654,11 +654,20 @@ class WP_UnitTestCase extends PHPUnit_Framework_TestCase { $annotations = $this->getAnnotations(); - if ( ! empty( $annotations['group'] ) ) { - if ( in_array( 'ms-required', $annotations['group'], true ) ) { + $groups = array(); + if ( ! empty( $annotations['class']['group'] ) ) { + $groups = array_merge( $groups, $annotations['class']['group'] ); + } + if ( ! empty( $annotations['method']['group'] ) ) { + $groups = array_merge( $groups, $annotations['method']['group'] ); + } + + if ( ! empty( $groups ) ) { + if ( in_array( 'ms-required', $groups, true ) ) { $this->skipWithoutMultisite(); } - if ( in_array( 'ms-excluded', $annotations['group'], true ) ) { + + if ( in_array( 'ms-excluded', $groups, true ) ) { $this->skipWithMultisite(); } }