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
This commit is contained in:
Felix Arntz 2018-04-25 22:37:08 +00:00
parent f6c215c8bf
commit 79bf20d320
1 changed files with 12 additions and 3 deletions

View File

@ -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();
}
}