Daniel Kinzler has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/74170


Change subject: Detect leakage of error_reporting state in tests.
......................................................................

Detect leakage of error_reporting state in tests.

This introduces $wgPHPUnitAssertErrorReporting, which, when turned on, causes
PHPUnit test cases to fail if they changed the PHP error_reporting settings,
and failed to restore it.

Change-Id: I34068eac94c974a461af0ff5753d9fcaa375f2e4
---
M RELEASE-NOTES-1.22
M includes/DefaultSettings.php
M tests/phpunit/MediaWikiTestCase.php
3 files changed, 37 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/70/74170/1

diff --git a/RELEASE-NOTES-1.22 b/RELEASE-NOTES-1.22
index 5e93c0f..5d88b97 100644
--- a/RELEASE-NOTES-1.22
+++ b/RELEASE-NOTES-1.22
@@ -39,6 +39,11 @@
   page protection levels. The rights 'editprotected' and 'editsemiprotected'
   are now used for this purpose instead.
 * (bug 40866) wgOldChangeTagsIndex removed.
+* $wgPHPUnitAssertErrorReporting was introduced (default: false). It determins 
whether PHPUnit
+  tests should assert that tests did not modify PHPs error_reporting setting.
+  This error_reporting is typically modified using wfSuppressWarnings(), and 
restored using
+  wfRestoreWarnings(). Failing to pair these calls correctly can lead to 
failures being silently
+  ignored. This setting is expected to eventually become true per default.
 
 === New features in 1.22 ===
 * (bug 44525) mediawiki.jqueryMsg can now parse (whitelisted) HTML elements 
and attributes.
diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php
index 1f5b2f7..0ad9dce 100644
--- a/includes/DefaultSettings.php
+++ b/includes/DefaultSettings.php
@@ -4758,6 +4758,18 @@
 );
 
 /**
+ * Whether PHPUnit tests should assert that tests did not modify PHPs 
error_reporting setting.
+ * This error_reporting is typically modified using wfSuppressWarnings(), and 
restored using
+ * wfRestoreWarnings(). Failing to pair these calls correctly can lead to 
failures being silently
+ * ignored.
+ *
+ * @todo: set this to true per default once all test cases failing this 
assertion have been fixed.
+ *
+ * @since 1.22
+ */
+$wgPHPUnitAssertErrorReporting = false;
+
+/**
  * Overwrite the caching key prefix with custom value.
  * @since 1.19
  */
diff --git a/tests/phpunit/MediaWikiTestCase.php 
b/tests/phpunit/MediaWikiTestCase.php
index 25ba29e..632889c 100644
--- a/tests/phpunit/MediaWikiTestCase.php
+++ b/tests/phpunit/MediaWikiTestCase.php
@@ -163,6 +163,8 @@
                return $fname;
        }
 
+       private $phpErrorLevel;
+
        /**
         * setUp and tearDown should (where significant)
         * happen in reverse order.
@@ -171,6 +173,8 @@
                wfProfileIn( __METHOD__ );
                parent::setUp();
                $this->called['setUp'] = 1;
+
+               $this->phpErrorLevel = intval( ini_get( 'error_reporting' ) );
 
                /*
                // @todo global variables to restore for *every* test
@@ -233,6 +237,22 @@
                }
                $this->mwGlobals = array();
 
+               $phpErrorLevel = intval( ini_get( 'error_reporting' ) );
+
+               if ( $phpErrorLevel !== $this->phpErrorLevel ) {
+                       ini_set( 'error_reporting', $this->phpErrorLevel );
+
+                       $oldHex = strtoupper( dechex( $this->phpErrorLevel ) );
+                       $newHex = strtoupper( dechex( $phpErrorLevel ) );
+                       $message = "PHP error_reporting setting was lft dirty: 
was 0x$oldHex before test, 0x$newHex after test!";
+
+                       if ( $GLOBALS['wgPHPUnitAssertErrorReporting'] ) {
+                               $this->fail( $message );
+                       } else {
+                               wfDebugLog( __CLASS__, 'Test case ' . 
$this->getName() . ': ' . $message );
+                       }
+               }
+
                parent::tearDown();
                wfProfileOut( __METHOD__ );
        }

-- 
To view, visit https://gerrit.wikimedia.org/r/74170
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I34068eac94c974a461af0ff5753d9fcaa375f2e4
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to