Mwalker has submitted this change and it was merged.
Change subject: Make sure we don't use objects by ref in setMwGlobals
......................................................................
Make sure we don't use objects by ref in setMwGlobals
If we copy am object by ref into our temporary array
then this doesn't really make this method very useful
as the same object would be restored, with any changes
after the test has run.
Thus objects should be cloned when being dumped in
here, we use unserialize() and serialize() instead as
we would also want to clone the objects within the
object to avoid changes in there!
These is no point in adding an if is_object call so
we just serialize and deserialize everything!
Change-Id: I5e4ef114405888932014edae6b44afc6ee2c4863
---
M tests/phpunit/MediaWikiTestCase.php
1 file changed, 4 insertions(+), 1 deletion(-)
Approvals:
Mwalker: Looks good to me, approved
diff --git a/tests/phpunit/MediaWikiTestCase.php
b/tests/phpunit/MediaWikiTestCase.php
index 87e214c..9ca1cab 100644
--- a/tests/phpunit/MediaWikiTestCase.php
+++ b/tests/phpunit/MediaWikiTestCase.php
@@ -312,7 +312,10 @@
// setMwGlobals() on the same global would override the
original
// value.
if ( !array_key_exists( $key, $this->mwGlobals ) ) {
- $this->mwGlobals[$key] = $GLOBALS[$key];
+ // NOTE: we serialize then unserialize the
value in case it is an object
+ // this stops any objects being passed by
reference. We could use clone
+ // and if is_object but this does account for
objects within objects!
+ $this->mwGlobals[$key] = unserialize(
serialize( $GLOBALS[$key] ) );
}
// Override the global
--
To view, visit https://gerrit.wikimedia.org/r/116958
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I5e4ef114405888932014edae6b44afc6ee2c4863
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Addshore <[email protected]>
Gerrit-Reviewer: Bartosz DziewoĆski <[email protected]>
Gerrit-Reviewer: Hashar <[email protected]>
Gerrit-Reviewer: Hoo man <[email protected]>
Gerrit-Reviewer: Krinkle <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: Mattflaschen <[email protected]>
Gerrit-Reviewer: Mwalker <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits