Many more function case mismatches
[lhc/web/wiklou.git] / tests / phpunit / maintenance / backupTextPassTest.php
index c216864..d7e72bb 100644 (file)
@@ -1,10 +1,15 @@
 <?php
 
-require_once __DIR__ . "/../../../maintenance/backupTextPass.inc";
+require_once __DIR__ . "/../../../maintenance/dumpTextPass.php";
 
 /**
  * Tests for TextPassDumper that rely on the database
  *
+ * Some of these tests use the old constuctor for TextPassDumper
+ * and the dump() function, while others use the new loadWithArgv( $args )
+ * function and execute(). This is to ensure both the old and new methods
+ * work properly.
+ *
  * @group Database
  * @group Dump
  * @covers TextPassDumper
@@ -27,9 +32,9 @@ class TextPassDumperDatabaseTest extends DumpTestCase {
                $this->tablesUsed[] = 'revision';
                $this->tablesUsed[] = 'text';
 
-               $this->mergeMwGlobalArrayValue( 'wgContentHandlers', array(
+               $this->mergeMwGlobalArrayValue( 'wgContentHandlers', [
                        "BackupTextPassTestModel" => "BackupTextPassTestModelHandler"
-               ) );
+               ] );
 
                $ns = $this->getDefaultWikitextNS();
 
@@ -97,8 +102,8 @@ class TextPassDumperDatabaseTest extends DumpTestCase {
                // class), we have to assert, that the page id are consecutively
                // increasing
                $this->assertEquals(
-                       array( $this->pageId2, $this->pageId3, $this->pageId4 ),
-                       array( $this->pageId1 + 1, $this->pageId2 + 1, $this->pageId3 + 1 ),
+                       [ $this->pageId2, $this->pageId3, $this->pageId4 ],
+                       [ $this->pageId1 + 1, $this->pageId2 + 1, $this->pageId3 + 1 ],
                        "Page ids increasing without holes" );
        }
 
@@ -106,10 +111,10 @@ class TextPassDumperDatabaseTest extends DumpTestCase {
                // Setting up the dump
                $nameStub = $this->setUpStub();
                $nameFull = $this->getNewTempFile();
-               $dumper = new TextPassDumper( array( "--stub=file:" . $nameStub,
-                       "--output=file:" . $nameFull ) );
+               $dumper = new TextPassDumper( [ "--stub=file:" . $nameStub,
+                       "--output=file:" . $nameFull ] );
                $dumper->reporting = false;
-               $dumper->setDb( $this->db );
+               $dumper->setDB( $this->db );
 
                // Performing the dump
                $dumper->dump( WikiExporter::FULL, WikiExporter::TEXT );
@@ -158,13 +163,13 @@ class TextPassDumperDatabaseTest extends DumpTestCase {
 
        function testPrefetchPlain() {
                // The mapping between ids and text, for the hits of the prefetch mock
-               $prefetchMap = array(
-                       array( $this->pageId1, $this->revId1_1, "Prefetch_________1Text1" ),
-                       array( $this->pageId2, $this->revId2_3, "Prefetch_________2Text3" )
-               );
+               $prefetchMap = [
+                       [ $this->pageId1, $this->revId1_1, "Prefetch_________1Text1" ],
+                       [ $this->pageId2, $this->revId2_3, "Prefetch_________2Text3" ]
+               ];
 
                // The mock itself
-               $prefetchMock = $this->getMock( 'BaseDump', array( 'prefetch' ), array(), '', false );
+               $prefetchMock = $this->getMock( 'BaseDump', [ 'prefetch' ], [], '', false );
                $prefetchMock->expects( $this->exactly( 6 ) )
                        ->method( 'prefetch' )
                        ->will( $this->returnValueMap( $prefetchMap ) );
@@ -172,11 +177,13 @@ class TextPassDumperDatabaseTest extends DumpTestCase {
                // Setting up of the dump
                $nameStub = $this->setUpStub();
                $nameFull = $this->getNewTempFile();
-               $dumper = new TextPassDumper( array( "--stub=file:"
-                       . $nameStub, "--output=file:" . $nameFull ) );
+
+               $dumper = new TextPassDumper( [ "--stub=file:" . $nameStub,
+                       "--output=file:" . $nameFull ] );
+
                $dumper->prefetch = $prefetchMock;
                $dumper->reporting = false;
-               $dumper->setDb( $this->db );
+               $dumper->setDB( $this->db );
 
                // Performing the dump
                $dumper->dump( WikiExporter::FULL, WikiExporter::TEXT );
@@ -261,18 +268,19 @@ class TextPassDumperDatabaseTest extends DumpTestCase {
                        $this->assertTrue( wfMkdirParents( $nameOutputDir ),
                                "Creating temporary output directory " );
                        $this->setUpStub( $nameStub, $iterations );
-                       $dumper = new TextPassDumper( array( "--stub=file:" . $nameStub,
+                       $dumper = new TextPassDumper();
+                       $dumper->loadWithArgv( [ "--stub=file:" . $nameStub,
                                "--output=" . $checkpointFormat . ":" . $nameOutputDir . "/full",
                                "--maxtime=1" /*This is in minutes. Fixup is below*/,
                                "--buffersize=32768", // The default of 32 iterations fill up 32KB about twice
-                               "--checkpointfile=checkpoint-%s-%s.xml.gz" ) );
-                       $dumper->setDb( $this->db );
+                               "--checkpointfile=checkpoint-%s-%s.xml.gz" ] );
+                       $dumper->setDB( $this->db );
                        $dumper->maxTimeAllowed = $checkpointAfter; // Patching maxTime from 1 minute
                        $dumper->stderr = $stderr;
 
                        // The actual dump and taking time
                        $ts_before = microtime( true );
-                       $dumper->dump( WikiExporter::FULL, WikiExporter::TEXT );
+                       $dumper->execute();
                        $ts_after = microtime( true );
                        $lastDuration = $ts_after - $ts_before;
 
@@ -301,7 +309,6 @@ class TextPassDumperDatabaseTest extends DumpTestCase {
 
                // The dump (hopefully) did take long enough to produce more than one
                // checkpoint file.
-               //
                // We now check all the checkpoint files for validity.
 
                $files = scandir( $nameOutputDir );
@@ -635,7 +642,9 @@ class TextPassDumperDatabaselessTest extends MediaWikiLangTestCase {
         * @dataProvider bufferSizeProvider
         */
        function testBufferSizeSetting( $expected, $size, $msg ) {
-               $dumper = new TextPassDumperAccessor( array( "--buffersize=" . $size ) );
+               $dumper = new TextPassDumperAccessor();
+               $dumper->loadWithArgv( [ "--buffersize=" . $size ] );
+               $dumper->execute();
                $this->assertEquals( $expected, $dumper->getBufferSize(), $msg );
        }
 
@@ -646,11 +655,11 @@ class TextPassDumperDatabaselessTest extends MediaWikiLangTestCase {
         */
        function bufferSizeProvider() {
                // expected, bufferSize to initialize with, message
-               return array(
-                       array( 512 * 1024, 512 * 1024, "Setting 512KB is not effective" ),
-                       array( 8192, 8192, "Setting 8KB is not effective" ),
-                       array( 4096, 2048, "Could set buffer size below lower bound" )
-               );
+               return [
+                       [ 512 * 1024, 512 * 1024, "Setting 512KB is not effective" ],
+                       [ 8192, 8192, "Setting 8KB is not effective" ],
+                       [ 4096, 2048, "Could set buffer size below lower bound" ]
+               ];
        }
 }
 
@@ -675,4 +684,8 @@ class TextPassDumperAccessor extends TextPassDumper {
        public function getBufferSize() {
                return $this->bufferSize;
        }
+
+       function dump( $history, $text = null ) {
+               return true;
+       }
 }