From: Marius Hoch Date: Fri, 19 May 2017 21:06:58 +0000 (+0200) Subject: Fix Closure detection in MediaWikiTestCase X-Git-Tag: 1.31.0-rc.0~3212^2 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/banques/?a=commitdiff_plain;h=91159d39d5ca5dc679be7de43866864b0998cc2e;p=lhc%2Fweb%2Fwiklou.git Fix Closure detection in MediaWikiTestCase Sometimes the closure are hidden in arrays, catch this. The $maxDepth check is just for sanity, I don't think it's actually needed. Follows-Up: c2c7452577e Bug: T111641 Change-Id: Id5e036ce4949b8106873fd938f54c2774d3d6a4a --- diff --git a/tests/phpunit/MediaWikiTestCase.php b/tests/phpunit/MediaWikiTestCase.php index 1114f2ae62..df3d5681d7 100644 --- a/tests/phpunit/MediaWikiTestCase.php +++ b/tests/phpunit/MediaWikiTestCase.php @@ -1,6 +1,5 @@ mwGlobals[$globalKey] = clone $GLOBALS[$globalKey]; - } elseif ( $GLOBALS[$globalKey] instanceof Closure ) { + } elseif ( $this->containsClosure( $GLOBALS[$globalKey] ) ) { // Serializing Closure only gives a warning on HHVM while // it throws an Exception on Zend. // Workaround for https://github.com/facebook/hhvm/issues/6206 @@ -754,6 +753,28 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { } } + /** + * @param mixed $var + * @param int $maxDepth + * + * @return bool + */ + private function containsClosure( $var, $maxDepth = 15 ) { + if ( $var instanceof Closure ) { + return true; + } + if ( !is_array( $var ) || $maxDepth === 0 ) { + return false; + } + + foreach ( $var as $value ) { + if ( $this->containsClosure( $value, $maxDepth - 1 ) ) { + return true; + } + } + return false; + } + /** * Merges the given values into a MW global array variable. * Useful for setting some entries in a configuration array, instead of