Awight has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/404490 )

Change subject: [WIP] New namespace for tests/phpunit/maintenance, begin 
splitting out maintenance test base classes
......................................................................

[WIP] New namespace for tests/phpunit/maintenance, begin splitting out 
maintenance test base classes

Bug: T184775
Change-Id: I73c2f3c6975deec50cf879201cf292c217b51c51
---
M tests/common/TestsAutoLoader.php
M tests/phpunit/maintenance/DumpTestCase.php
A tests/phpunit/maintenance/MaintenanceFixup.php
M tests/phpunit/maintenance/MaintenanceTest.php
M tests/phpunit/maintenance/backupTextPassTest.php
M tests/phpunit/maintenance/backup_LogTest.php
M tests/phpunit/maintenance/backup_PageTest.php
7 files changed, 186 insertions(+), 139 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/90/404490/1

diff --git a/tests/common/TestsAutoLoader.php b/tests/common/TestsAutoLoader.php
index a51008e..825cee0 100644
--- a/tests/common/TestsAutoLoader.php
+++ b/tests/common/TestsAutoLoader.php
@@ -150,7 +150,8 @@
        'GenericArrayObjectTest' => 
"$testDir/phpunit/includes/libs/GenericArrayObjectTest.php",
 
        # tests/phpunit/maintenance
-       'DumpTestCase' => "$testDir/phpunit/maintenance/DumpTestCase.php",
+       'MediaWiki\Tests\Maintenance\DumpTestCase' => 
"$testDir/phpunit/maintenance/DumpTestCase.php",
+       'MediaWiki\Tests\Maintenance\MaintenanceFixup' => 
"$testDir/phpunit/maintenance/MaintenanceFixup.php",
 
        # tests/phpunit/media
        'FakeDimensionFile' => 
"$testDir/phpunit/includes/media/FakeDimensionFile.php",
diff --git a/tests/phpunit/maintenance/DumpTestCase.php 
b/tests/phpunit/maintenance/DumpTestCase.php
index 58cb6f3..c872993 100644
--- a/tests/phpunit/maintenance/DumpTestCase.php
+++ b/tests/phpunit/maintenance/DumpTestCase.php
@@ -1,5 +1,14 @@
 <?php
 
+namespace MediaWiki\Tests\Maintenance;
+
+use ContentHandler;
+use ExecutableFinder;
+use MediaWikiLangTestCase;
+use Page;
+use User;
+use XMLReader;
+
 /**
  * Base TestCase for dumps
  */
diff --git a/tests/phpunit/maintenance/MaintenanceFixup.php 
b/tests/phpunit/maintenance/MaintenanceFixup.php
new file mode 100644
index 0000000..40da42d
--- /dev/null
+++ b/tests/phpunit/maintenance/MaintenanceFixup.php
@@ -0,0 +1,142 @@
+<?php
+
+namespace MediaWiki\Tests\Maintenance;
+
+use Maintenance;
+use MediaWikiTestCase;
+
+/**
+ * Makes parts of Maintenance class API visible for testing, and makes up for a
+ * stream closing hack in Maintenance.php.
+ *
+ * This class is solely used for being able to test Maintenance right now
+ * without having to apply major refactorings to fix some design issues in
+ * Maintenance.php. Before adding more functions here, please consider whether
+ * this approach is correct, or a refactoring Maintenance to separate concerns
+ * is more appropriate.
+ *
+ * Upon refactoring, keep in mind that besides the maintenance scripts 
themselves
+ * and tests right here, some extensions including Extension:Maintenance make
+ * use of the Maintenance class.
+ *
+ * Due to a hack in Maintenance.php using register_shutdown_function, be sure 
to
+ * call simulateShutdown on MaintenanceFixup instance before a test ends.
+ *
+ * FIXME:
+ * It would be great if we were able to use PHPUnit's getMockForAbstractClass
+ * instead of the MaintenanceFixup hack below. However, we cannot do so
+ * without changing method visibility and without working around hacks in
+ * Maintenance.php
+ *
+ * For the same reason, we cannot just use FakeMaintenance.
+ */
+class MaintenanceFixup extends Maintenance {
+
+       // --- Making up for the register_shutdown_function hack in 
Maintenance.php
+
+       /**
+        * The test case that generated this instance.
+        *
+        * This member is motivated by allowing the destructor to check whether 
or not
+        * the test failed, in order to avoid unnecessary nags about omitted 
shutdown
+        * simulation.
+        * But as it is already available, we also usi it to flagging tests as 
failed
+        *
+        * @var MediaWikiTestCase
+        */
+       private $testCase;
+
+       /**
+        * shutdownSimulated === true if simulateShutdown has done its work
+        *
+        * @var bool
+        */
+       private $shutdownSimulated = false;
+
+       /**
+        * Simulates what Maintenance wants to happen at script's end.
+        */
+       public function simulateShutdown() {
+               if ( $this->shutdownSimulated ) {
+                       $this->testCase->fail( __METHOD__ . " called more than 
once" );
+               }
+
+               // The cleanup action.
+               $this->outputChanneled( false );
+
+               // Bookkeeping that we simulated the clean up.
+               $this->shutdownSimulated = true;
+       }
+
+       // Note that the "public" here does not change visibility
+       public function outputChanneled( $msg, $channel = null ) {
+               if ( $this->shutdownSimulated ) {
+                       if ( $msg !== false ) {
+                               $this->testCase->fail( "Already past simulated 
shutdown, but msg is "
+                                       . "not false. Did the hack in 
Maintenance.php change? Please "
+                                       . "adapt the test case or 
Maintenance.php" );
+                       }
+
+                       // The current call is the one registered via 
register_shutdown_function.
+                       // We can safely ignore it, as we simulated this one 
via simulateShutdown
+                       // before (if we did not, the destructor of this 
instance will warn about
+                       // it)
+                       return;
+               }
+
+               call_user_func_array( [ "parent", __FUNCTION__ ], 
func_get_args() );
+       }
+
+       /**
+        * Safety net around register_shutdown_function of Maintenance.php
+        */
+       public function __destruct() {
+               if ( !$this->shutdownSimulated ) {
+                       // Someone generated a MaintenanceFixup instance 
without calling
+                       // simulateShutdown. We'd have to raise a PHPUnit 
exception to correctly
+                       // flag this illegal usage. However, we are already in 
a destruktor, which
+                       // would trigger undefined behavior. Hence, we can only 
report to the
+                       // error output :( Hopefully people read the PHPUnit 
output.
+                       $name = $this->testCase->getName();
+                       fwrite( STDERR, "ERROR! Instance of " . __CLASS__ . " 
for test $name "
+                               . "destructed without calling simulateShutdown 
method. Call "
+                               . "simulateShutdown on the instance before it 
gets destructed." );
+               }
+
+               // The following guard is required, as PHP does not offer 
default destructors :(
+               if ( is_callable( "parent::__destruct" ) ) {
+                       parent::__destruct();
+               }
+       }
+
+       public function __construct( MediaWikiTestCase $testCase ) {
+               parent::__construct();
+               $this->testCase = $testCase;
+       }
+
+       // --- Making protected functions visible for test
+
+       public function output( $out, $channel = null ) {
+               // Just to make PHP not nag about signature mismatches, we 
copied
+               // Maintenance::output signature. However, we do not use (or 
rely on)
+               // those variables. Instead we pass to Maintenance::output 
whatever we
+               // receive at runtime.
+               return call_user_func_array( [ "parent", __FUNCTION__ ], 
func_get_args() );
+       }
+
+       public function addOption( $name, $description, $required = false,
+               $withArg = false, $shortName = false, $multiOccurance = false
+       ) {
+               return call_user_func_array( [ "parent", __FUNCTION__ ], 
func_get_args() );
+       }
+
+       public function getOption( $name, $default = null ) {
+               return call_user_func_array( [ "parent", __FUNCTION__ ], 
func_get_args() );
+       }
+
+       // --- Requirements for getting instance of abstract class
+
+       public function execute() {
+               $this->testCase->fail( __METHOD__ . " called unexpectedly" );
+       }
+}
diff --git a/tests/phpunit/maintenance/MaintenanceTest.php 
b/tests/phpunit/maintenance/MaintenanceTest.php
index 253327b..ecb4f34 100644
--- a/tests/phpunit/maintenance/MaintenanceTest.php
+++ b/tests/phpunit/maintenance/MaintenanceTest.php
@@ -1,142 +1,9 @@
 <?php
 
+namespace MediaWiki\Tests\Maintenance;
+
 use MediaWiki\MediaWikiServices;
-
-/**
- * Makes parts of Maintenance class API visible for testing, and makes up for a
- * stream closing hack in Maintenance.php.
- *
- * This class is solely used for being able to test Maintenance right now
- * without having to apply major refactorings to fix some design issues in
- * Maintenance.php. Before adding more functions here, please consider whether
- * this approach is correct, or a refactoring Maintenance to separate concerns
- * is more appropriate.
- *
- * Upon refactoring, keep in mind that besides the maintenance scripts 
themselves
- * and tests right here, some extensions including Extension:Maintenance make
- * use of the Maintenance class.
- *
- * Due to a hack in Maintenance.php using register_shutdown_function, be sure 
to
- * call simulateShutdown on MaintenanceFixup instance before a test ends.
- *
- * FIXME:
- * It would be great if we were able to use PHPUnit's getMockForAbstractClass
- * instead of the MaintenanceFixup hack below. However, we cannot do so
- * without changing method visibility and without working around hacks in
- * Maintenance.php
- *
- * For the same reason, we cannot just use FakeMaintenance.
- */
-class MaintenanceFixup extends Maintenance {
-
-       // --- Making up for the register_shutdown_function hack in 
Maintenance.php
-
-       /**
-        * The test case that generated this instance.
-        *
-        * This member is motivated by allowing the destructor to check whether 
or not
-        * the test failed, in order to avoid unnecessary nags about omitted 
shutdown
-        * simulation.
-        * But as it is already available, we also usi it to flagging tests as 
failed
-        *
-        * @var MediaWikiTestCase
-        */
-       private $testCase;
-
-       /**
-        * shutdownSimulated === true if simulateShutdown has done its work
-        *
-        * @var bool
-        */
-       private $shutdownSimulated = false;
-
-       /**
-        * Simulates what Maintenance wants to happen at script's end.
-        */
-       public function simulateShutdown() {
-               if ( $this->shutdownSimulated ) {
-                       $this->testCase->fail( __METHOD__ . " called more than 
once" );
-               }
-
-               // The cleanup action.
-               $this->outputChanneled( false );
-
-               // Bookkeeping that we simulated the clean up.
-               $this->shutdownSimulated = true;
-       }
-
-       // Note that the "public" here does not change visibility
-       public function outputChanneled( $msg, $channel = null ) {
-               if ( $this->shutdownSimulated ) {
-                       if ( $msg !== false ) {
-                               $this->testCase->fail( "Already past simulated 
shutdown, but msg is "
-                                       . "not false. Did the hack in 
Maintenance.php change? Please "
-                                       . "adapt the test case or 
Maintenance.php" );
-                       }
-
-                       // The current call is the one registered via 
register_shutdown_function.
-                       // We can safely ignore it, as we simulated this one 
via simulateShutdown
-                       // before (if we did not, the destructor of this 
instance will warn about
-                       // it)
-                       return;
-               }
-
-               call_user_func_array( [ "parent", __FUNCTION__ ], 
func_get_args() );
-       }
-
-       /**
-        * Safety net around register_shutdown_function of Maintenance.php
-        */
-       public function __destruct() {
-               if ( !$this->shutdownSimulated ) {
-                       // Someone generated a MaintenanceFixup instance 
without calling
-                       // simulateShutdown. We'd have to raise a PHPUnit 
exception to correctly
-                       // flag this illegal usage. However, we are already in 
a destruktor, which
-                       // would trigger undefined behavior. Hence, we can only 
report to the
-                       // error output :( Hopefully people read the PHPUnit 
output.
-                       $name = $this->testCase->getName();
-                       fwrite( STDERR, "ERROR! Instance of " . __CLASS__ . " 
for test $name "
-                               . "destructed without calling simulateShutdown 
method. Call "
-                               . "simulateShutdown on the instance before it 
gets destructed." );
-               }
-
-               // The following guard is required, as PHP does not offer 
default destructors :(
-               if ( is_callable( "parent::__destruct" ) ) {
-                       parent::__destruct();
-               }
-       }
-
-       public function __construct( MediaWikiTestCase $testCase ) {
-               parent::__construct();
-               $this->testCase = $testCase;
-       }
-
-       // --- Making protected functions visible for test
-
-       public function output( $out, $channel = null ) {
-               // Just to make PHP not nag about signature mismatches, we 
copied
-               // Maintenance::output signature. However, we do not use (or 
rely on)
-               // those variables. Instead we pass to Maintenance::output 
whatever we
-               // receive at runtime.
-               return call_user_func_array( [ "parent", __FUNCTION__ ], 
func_get_args() );
-       }
-
-       public function addOption( $name, $description, $required = false,
-               $withArg = false, $shortName = false, $multiOccurance = false
-       ) {
-               return call_user_func_array( [ "parent", __FUNCTION__ ], 
func_get_args() );
-       }
-
-       public function getOption( $name, $default = null ) {
-               return call_user_func_array( [ "parent", __FUNCTION__ ], 
func_get_args() );
-       }
-
-       // --- Requirements for getting instance of abstract class
-
-       public function execute() {
-               $this->testCase->fail( __METHOD__ . " called unexpectedly" );
-       }
-}
+use MediaWikiTestCase;
 
 /**
  * @covers Maintenance
diff --git a/tests/phpunit/maintenance/backupTextPassTest.php 
b/tests/phpunit/maintenance/backupTextPassTest.php
index 0a1f3b4..d8cc435 100644
--- a/tests/phpunit/maintenance/backupTextPassTest.php
+++ b/tests/phpunit/maintenance/backupTextPassTest.php
@@ -1,5 +1,15 @@
 <?php
 
+namespace MediaWiki\Tests\Maintenance;
+
+use MediaWikiLangTestCase;
+use Page;
+use TextContentHandler;
+use TextPassDumper;
+use Title;
+use WikiExporter;
+use WikiPage;
+
 require_once __DIR__ . "/../../../maintenance/dumpTextPass.php";
 
 /**
@@ -34,7 +44,7 @@
                $this->tablesUsed[] = 'text';
 
                $this->mergeMwGlobalArrayValue( 'wgContentHandlers', [
-                       "BackupTextPassTestModel" => 
"BackupTextPassTestModelHandler"
+                       "BackupTextPassTestModel" => 
'MediaWiki\Tests\Maintenance\BackupTextPassTestModelHandler',
                ] );
 
                $ns = $this->getDefaultWikitextNS();
diff --git a/tests/phpunit/maintenance/backup_LogTest.php 
b/tests/phpunit/maintenance/backup_LogTest.php
index 91e1b1e..c215b99 100644
--- a/tests/phpunit/maintenance/backup_LogTest.php
+++ b/tests/phpunit/maintenance/backup_LogTest.php
@@ -1,4 +1,13 @@
 <?php
+
+namespace MediaWiki\Tests\Maintenance;
+
+use DumpBackup;
+use ManualLogEntry;
+use Title;
+use User;
+use WikiExporter;
+
 /**
  * Tests for log dumps of BackupDumper
  *
diff --git a/tests/phpunit/maintenance/backup_PageTest.php 
b/tests/phpunit/maintenance/backup_PageTest.php
index 554d5f6..4010f42 100644
--- a/tests/phpunit/maintenance/backup_PageTest.php
+++ b/tests/phpunit/maintenance/backup_PageTest.php
@@ -1,4 +1,14 @@
 <?php
+
+namespace MediaWiki\Tests\Maintenance;
+
+use DumpBackup;
+use Language;
+use Title;
+use User;
+use WikiExporter;
+use WikiPage;
+
 /**
  * Tests for page dumps of BackupDumper
  *
@@ -6,7 +16,6 @@
  * @group Dump
  * @covers BackupDumper
  */
-
 class BackupDumperPageTest extends DumpTestCase {
 
        // We'll add several pages, revision and texts. The following variables 
hold the

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

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

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

Reply via email to