tests: Commit initial version of DevelopmentSettings.php
authorTimo Tijhof <krinklemail@gmail.com>
Sun, 8 Oct 2017 20:17:35 +0000 (21:17 +0100)
committerKrinkle <krinklemail@gmail.com>
Wed, 27 Dec 2017 22:13:24 +0000 (22:13 +0000)
* Store in the includes/ directory.
* Use by default in Travis CI builds.
* Add command-line option to phpunit.php to use it.
* See commit ## for use by Jenkins jobs, which will load it directly
  from LocalSettings.php (instead of via phpunit) so that it applies
  to web entry points and other maintenance scripts as well.

Bug: T177669
Change-Id: I6e5dc5f0dddc1960761980552ed2bb31e6ae9fd9

.travis.yml
includes/DevelopmentSettings.php [new file with mode: 0644]
maintenance/Maintenance.php
tests/phpunit/phpunit.php

index 64414b5..29fb890 100644 (file)
@@ -67,6 +67,8 @@ before_script:
       --dbuser "$dbuser"
       --dbpass ""
       --scriptpath "/w"
+  - echo -en "\n\nrequire_once __DIR__ . '/includes/DevelopmentSettings.php';\n" >> ./LocalSettings.php
+  - php -l ./LocalSettings.php
 
 script:
   - php tests/phpunit/phpunit.php
diff --git a/includes/DevelopmentSettings.php b/includes/DevelopmentSettings.php
new file mode 100644 (file)
index 0000000..a74353a
--- /dev/null
@@ -0,0 +1,59 @@
+<?php
+/**
+ * Extra settings useful for MediaWiki development.
+ *
+ * To enable built-in debug and development settings, add the
+ * following to your LocalSettings.php file.
+ *
+ *     require "$IP/includes/DevelopmentSettings.php";
+ *
+ * Alternatively, if running phpunit.php (or another Maintenance script),
+ * you can use the --mwdebug option to automatically load these settings.
+ *
+ * @file
+ */
+
+/**
+ * Debugging: PHP
+ */
+
+// Enable showing of errors
+error_reporting( -1 );
+ini_set( 'display_errors', 1 );
+
+/**
+ * Debugging: MediaWiki
+ */
+global $wgDevelopmentWarnings, $wgShowDBErrorBacktrace, $wgShowExceptionDetails,
+       $wgShowSQLErrors, $wgDebugRawPage,
+       $wgDebugComments, $wgDebugDumpSql, $wgDebugTimestamps,
+       $wgCommandLineMode, $wgDebugLogFile, $wgDBerrorLog, $wgDebugLogGroups;
+
+// Use of wfWarn() should cause tests to fail
+$wgDevelopmentWarnings = true;
+
+// Enable showing of errors
+$wgShowDBErrorBacktrace = true;
+$wgShowExceptionDetails = true;
+$wgShowSQLErrors = true;
+$wgDebugRawPage = true; // T49960
+
+// Enable verbose logging
+$wgDebugComments = true;
+$wgDebugDumpSql = true;
+$wgDebugTimestamps = true;
+
+// Enable log files
+$logDir = getenv( 'MW_LOG_DIR' );
+if ( $logDir ) {
+       if ( $wgCommandLineMode ) {
+               $wgDebugLogFile = "$logDir/mw-debug-cli.log";
+       } else {
+               $wgDebugLogFile = "$logDir/mw-debug-www.log";
+       }
+       $wgDBerrorLog = "$logDir/mw-dberror.log";
+       $wgDebugLogGroups['ratelimit'] = "$logDir/mw-ratelimit.log";
+       $wgDebugLogGroups['exception'] = "$logDir/mw-exception.log";
+       $wgDebugLogGroups['error'] = "$logDir/mw-error.log";
+}
+unset( $logDir );
index a3e0ffd..b8c554d 100644 (file)
@@ -502,6 +502,8 @@ abstract class Maintenance {
                        "http://en.wikipedia.org. This is sometimes necessary because " .
                        "server name detection may fail in command line scripts.", false, true );
                $this->addOption( 'profiler', 'Profiler output format (usually "text")', false, true );
+               // This is named --mwdebug, because --debug would conflict in the phpunit.php CLI script.
+               $this->addOption( 'mwdebug', 'Enable built-in MediaWiki development settings', false, true );
 
                # Save generic options to display them separately in help
                $this->mGenericParameters = $this->mParams;
@@ -1131,6 +1133,11 @@ abstract class Maintenance {
                        MediaWikiServices::getInstance()->getDBLoadBalancerFactory()->destroy();
                }
 
+               # Apply debug settings
+               if ( $this->hasOption( 'mwdebug' ) ) {
+                       require __DIR__ . '/../includes/DevelopmentSettings.php';
+               }
+
                // Per-script profiling; useful for debugging
                $this->activateProfiler();
 
index 7203777..a78bd82 100755 (executable)
@@ -21,6 +21,7 @@ class PHPUnitMaintClass extends Maintenance {
                'use-bagostuff' => false,
                'use-jobqueue' => false,
                'use-normal-tables' => false,
+               'mwdebug' => false,
                'reuse-db' => false,
                'wiki' => false,
                'profiler' => false,