Addshore has uploaded a new change for review.
https://gerrit.wikimedia.org/r/277435
Change subject: Reset WatchedItemStore default instance after tests
......................................................................
Reset WatchedItemStore default instance after tests
Prior to this change in tests the overridden store
would remain in the instance static and thus could
be used in other places.
The override method now takes null as a default
meaning next time getDefaultInstance would be called
a new instance would be created.
I have added the reset call to the tearDown method
for convenience and to avoid it being missed in
this test class in the future.
This was found while writing more tests...
Change-Id: I9aa71425642174ae9ea2c6d4f85dcd07d724af11
---
M includes/WatchedItemStore.php
M tests/phpunit/includes/WatchedItemUnitTest.php
2 files changed, 11 insertions(+), 2 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/35/277435/1
diff --git a/includes/WatchedItemStore.php b/includes/WatchedItemStore.php
index 806db5e..ffb888b 100644
--- a/includes/WatchedItemStore.php
+++ b/includes/WatchedItemStore.php
@@ -101,11 +101,14 @@
* Overrides the default instance of this class
* This is intended for use while testing and will fail if
MW_PHPUNIT_TEST is not defined.
*
- * @param WatchedItemStore $store
+ * If this method is used it MUST also be called with null after a test
to ensure a new
+ * default instance is created next time getDefaultInstance is called.
+ *
+ * @param WatchedItemStore|null $store
*
* @throws MWException
*/
- public static function overrideDefaultInstance( WatchedItemStore $store
) {
+ public static function overrideDefaultInstance( WatchedItemStore $store
= null ) {
if ( !defined( 'MW_PHPUNIT_TEST' ) ) {
throw new MWException(
'Cannot override ' . __CLASS__ . 'default
instance in operation.'
diff --git a/tests/phpunit/includes/WatchedItemUnitTest.php
b/tests/phpunit/includes/WatchedItemUnitTest.php
index bc37311..fd7eeb9 100644
--- a/tests/phpunit/includes/WatchedItemUnitTest.php
+++ b/tests/phpunit/includes/WatchedItemUnitTest.php
@@ -7,6 +7,12 @@
*/
class WatchedItemUnitTest extends PHPUnit_Framework_TestCase {
+ public function tearDown() {
+ parent::tearDown();
+ // Reset the WatchedItemStore default instance if we overrode it
+ WatchedItemStore::overrideDefaultInstance();
+ }
+
public function provideUserTitleTimestamp() {
return [
[ User::newFromId( 111 ), Title::newFromText(
'SomeTitle' ), null ],
--
To view, visit https://gerrit.wikimedia.org/r/277435
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I9aa71425642174ae9ea2c6d4f85dcd07d724af11
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Addshore <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits