Pass phpcs-strict on some test files (5/x)
authorSiebrand Mazeland <siebrand@kitano.nl>
Thu, 24 Apr 2014 15:05:10 +0000 (17:05 +0200)
committerSiebrand Mazeland <siebrand@kitano.nl>
Thu, 24 Apr 2014 16:51:45 +0000 (18:51 +0200)
Change-Id: I690645cd8a9b1165dcc8271b201c695ea9391226

tests/phpunit/includes/XmlTest.php
tests/phpunit/includes/api/ApiLoginTest.php
tests/phpunit/includes/api/ApiOptionsTest.php
tests/phpunit/includes/api/ApiParseTest.php
tests/phpunit/includes/api/ApiPurgeTest.php
tests/phpunit/includes/api/ApiTestCase.php
tests/phpunit/includes/api/ApiTestCaseUpload.php
tests/phpunit/includes/api/ApiUploadTest.php
tests/phpunit/includes/api/RandomImageGenerator.php
tests/phpunit/includes/api/query/ApiQueryContinueTestBase.php

index 86b4c35..6a8ae87 100644 (file)
@@ -151,7 +151,11 @@ class XmlTest extends MediaWikiTestCase {
                }
 
                $this->assertEquals(
-                       '<label for="year">From year (and earlier):</label> <input id="year" maxlength="4" size="7" type="number" value="2011" name="year" /> <label for="month">From month (and earlier):</label> <select id="month" name="month" class="mw-month-selector"><option value="-1">all</option>' . "\n" .
+                       '<label for="year">From year (and earlier):</label> ' .
+                               '<input id="year" maxlength="4" size="7" type="number" value="2011" name="year" /> ' .
+                               '<label for="month">From month (and earlier):</label> ' .
+                               '<select id="month" name="month" class="mw-month-selector">' .
+                               '<option value="-1">all</option>' . "\n" .
                                '<option value="1">January</option>' . "\n" .
                                '<option value="2" selected="">February</option>' . "\n" .
                                '<option value="3">March</option>' . "\n" .
@@ -168,7 +172,11 @@ class XmlTest extends MediaWikiTestCase {
                        "Date menu for february 2011"
                );
                $this->assertEquals(
-                       '<label for="year">From year (and earlier):</label> <input id="year" maxlength="4" size="7" type="number" value="2011" name="year" /> <label for="month">From month (and earlier):</label> <select id="month" name="month" class="mw-month-selector"><option value="-1">all</option>' . "\n" .
+                       '<label for="year">From year (and earlier):</label> ' .
+                               '<input id="year" maxlength="4" size="7" type="number" value="2011" name="year" /> ' .
+                               '<label for="month">From month (and earlier):</label> ' .
+                               '<select id="month" name="month" class="mw-month-selector">' .
+                               '<option value="-1">all</option>' . "\n" .
                                '<option value="1">January</option>' . "\n" .
                                '<option value="2">February</option>' . "\n" .
                                '<option value="3">March</option>' . "\n" .
@@ -198,7 +206,10 @@ class XmlTest extends MediaWikiTestCase {
                );
 
                $this->assertEquals(
-                       '<label for="year">From year (and earlier):</label> <input id="year" maxlength="4" size="7" type="number" name="year" /> <label for="month">From month (and earlier):</label> <select id="month" name="month" class="mw-month-selector"><option value="-1">all</option>' . "\n" .
+                       '<label for="year">From year (and earlier):</label> ' .
+                               '<input id="year" maxlength="4" size="7" type="number" name="year" /> ' .
+                               '<label for="month">From month (and earlier):</label> ' .
+                               '<select id="month" name="month" class="mw-month-selector"><option value="-1">all</option>' . "\n" .
                                '<option value="1">January</option>' . "\n" .
                                '<option value="2">February</option>' . "\n" .
                                '<option value="3">March</option>' . "\n" .
index f1199e0..67a75f3 100644 (file)
@@ -107,7 +107,8 @@ class ApiLoginTest extends ApiTestCase {
         * @group Broken
         */
        public function testApiLoginGotCookie() {
-               $this->markTestIncomplete( "The server can't do external HTTP requests, and the internal one won't give cookies" );
+               $this->markTestIncomplete( "The server can't do external HTTP requests, "
+                       . "and the internal one won't give cookies" );
 
                global $wgServer, $wgScriptPath;
 
@@ -147,7 +148,10 @@ class ApiLoginTest extends ApiTestCase {
                $this->assertNotEquals( false, $serverName );
                $serializedCookie = $cj->serializeToHttpRequest( $wgScriptPath, $serverName );
                $this->assertNotEquals( '', $serializedCookie );
-               $this->assertRegexp( '/_session=[^;]*; .*UserID=[0-9]*; .*UserName=' . $user->userName . '; .*Token=/', $serializedCookie );
+               $this->assertRegexp(
+                       '/_session=[^;]*; .*UserID=[0-9]*; .*UserName=' . $user->userName . '; .*Token=/',
+                       $serializedCookie
+               );
        }
 
        public function testRunLogin() {
index 15bd8bb..e031ce3 100644 (file)
@@ -318,7 +318,9 @@ class ApiOptionsTest extends MediaWikiLangTestCase {
                $this->mUserMock->expects( $this->once() )
                        ->method( 'saveSettings' );
 
-               $request = $this->getSampleRequest( array( 'change' => 'willBeNull|willBeEmpty=|willBeHappy=Happy' ) );
+               $request = $this->getSampleRequest( array(
+                       'change' => 'willBeNull|willBeEmpty=|willBeHappy=Happy'
+               ) );
 
                $response = $this->executeQuery( $request );
 
@@ -382,7 +384,8 @@ class ApiOptionsTest extends MediaWikiLangTestCase {
                        ->method( 'saveSettings' );
 
                $request = $this->getSampleRequest( array(
-                       'change' => 'testmultiselect-opt1=1|testmultiselect-opt2|testmultiselect-opt3=|testmultiselect-opt4=0'
+                       'change' => 'testmultiselect-opt1=1|testmultiselect-opt2|'
+                               . 'testmultiselect-opt3=|testmultiselect-opt4=0'
                ) );
 
                $response = $this->executeQuery( $request );
index d303d4b..d038a4f 100644 (file)
@@ -24,8 +24,12 @@ class ApiParseTest extends ApiTestCase {
 
                        $this->fail( "API did not return an error when parsing a nonexistent page" );
                } catch ( UsageException $ex ) {
-                       $this->assertEquals( 'missingtitle', $ex->getCodeString(),
-                               "Parse request for nonexistent page must give 'missingtitle' error: " . var_export( $ex->getMessageArray(), true ) );
+                       $this->assertEquals(
+                               'missingtitle',
+                               $ex->getCodeString(),
+                               "Parse request for nonexistent page must give 'missingtitle' error: "
+                                       . var_export( $ex->getMessageArray(), true )
+                       );
                }
        }
 }
index d25a4c1..7fce134 100644 (file)
@@ -31,8 +31,11 @@ class ApiPurgeTest extends ApiTestCase {
                $this->assertArrayHasKey( 'purge', $data[0],
                        "Must receive a 'purge' result from API" );
 
-               $this->assertEquals( 3, count( $data[0]['purge'] ),
-                       "Purge request for three articles should give back three results received: " . var_export( $data[0]['purge'], true ) );
+               $this->assertEquals(
+                       3,
+                       count( $data[0]['purge'] ),
+                       "Purge request for three articles should give back three results received: "
+                               . var_export( $data[0]['purge'], true ) );
 
                $pages = array( 'UTPage' => 'purged', $somePage => 'missing', '%5D' => 'invalid' );
                foreach ( $data[0]['purge'] as $v ) {
index 843c88d..87ad2cd 100644 (file)
@@ -72,7 +72,9 @@ abstract class ApiTestCase extends MediaWikiLangTestCase {
         *
         * @return array
         */
-       protected function doApiRequest( array $params, array $session = null, $appendModule = false, User $user = null ) {
+       protected function doApiRequest( array $params, array $session = null,
+               $appendModule = false, User $user = null
+       ) {
                global $wgRequest, $wgUser;
 
                if ( is_null( $session ) ) {
@@ -112,15 +114,19 @@ abstract class ApiTestCase extends MediaWikiLangTestCase {
 
        /**
         * Add an edit token to the API request
-        * This is cheating a bit -- we grab a token in the correct format and then add it to the pseudo-session and to the
-        * request, without actually requesting a "real" edit token
+        * This is cheating a bit -- we grab a token in the correct format and then
+        * add it to the pseudo-session and to the request, without actually
+        * requesting a "real" edit token.
+        *
         * @param array $params Key-value API params
         * @param array|null $session session array
         * @param User|null $user A User object for the context
         * @return mixed Result of the API call
         * @throws Exception in case wsToken is not set in the session
         */
-       protected function doApiRequestWithToken( array $params, array $session = null, User $user = null ) {
+       protected function doApiRequestWithToken( array $params, array $session = null,
+               User $user = null
+       ) {
                global $wgRequest;
 
                if ( $session === null ) {
index 42f02fa..40407dc 100644 (file)
@@ -40,10 +40,18 @@ abstract class ApiTestCaseUpload extends ApiTestCase {
                        $noOldArchive = ""; // yes this really needs to be set this way
                        $comment = "removing for test";
                        $restrictDeletedVersions = false;
-                       $status = FileDeleteForm::doDelete( $title, $file, $noOldArchive, $comment, $restrictDeletedVersions );
+                       $status = FileDeleteForm::doDelete(
+                               $title,
+                               $file,
+                               $noOldArchive,
+                               $comment,
+                               $restrictDeletedVersions
+                       );
+
                        if ( !$status->isGood() ) {
                                return false;
                        }
+
                        $page = WikiPage::factory( $title );
                        $page->doDeleteArticle( "removing for test" );
 
@@ -66,7 +74,8 @@ abstract class ApiTestCaseUpload extends ApiTestCase {
        }
 
        /**
-        * Helper function -- given a file on the filesystem, find matching content in the db (and associated articles) and remove them.
+        * Helper function -- given a file on the filesystem, find matching
+        * content in the db (and associated articles) and remove them.
         *
         * @param string $filePath path to file on the filesystem
         *
index ba7fb25..74219bd 100644 (file)
@@ -1,5 +1,4 @@
 <?php
-
 /**
  * @group API
  * @group Database
  * user that will run tests.
  */
 
-// Note for reviewers: this intentionally duplicates functionality already in "ApiSetup" and so on.
-// This framework works better IMO and has less strangeness (such as test cases inheriting from "ApiSetup"...)
-// (and in the case of the other Upload tests, this flat out just actually works... )
+// Note for reviewers: this intentionally duplicates functionality already in
+// "ApiSetup" and so on. This framework works better IMO and has less
+// strangeness (such as test cases inheriting from "ApiSetup"...) (and in the
+// case of the other Upload tests, this flat out just actually works... )
 
-// TODO: port the other Upload tests, and other API tests to this framework
+// @todo Port the other Upload tests, and other API tests to this framework
 
 require_once 'ApiTestCaseUpload.php';
 
@@ -427,14 +427,16 @@ class ApiUploadTest extends ApiTestCaseUpload {
         */
        public function testUploadChunks( $session ) {
                $this->setMwGlobals( array(
-                       'wgUser' => self::$users['uploader']->user, // @todo FIXME: still used somewhere
+                       // @todo FIXME: still used somewhere
+                       'wgUser' => self::$users['uploader']->user,
                ) );
 
                $chunkSize = 1048576;
                // Download a large image file
                // ( using RandomImageGenerator for large files is not stable )
                $mimeType = 'image/jpeg';
-               $url = 'http://upload.wikimedia.org/wikipedia/commons/e/ed/Oberaargletscher_from_Oberaar%2C_2010_07.JPG';
+               $url = 'http://upload.wikimedia.org/wikipedia/commons/'
+                       . 'e/ed/Oberaargletscher_from_Oberaar%2C_2010_07.JPG';
                $filePath = wfTempDir() . '/Oberaargletscher_from_Oberaar.jpg';
                try {
                        // Only download if the file is not avaliable in the temp location:
@@ -464,13 +466,19 @@ class ApiUploadTest extends ApiTestCaseUpload {
                $chunkSessionKey = false;
                $resultOffset = 0;
                // Open the file:
+               wfSuppressWarnings();
                $handle = @fopen( $filePath, "r" );
+               wfRestoreWarnings();
+
                if ( $handle === false ) {
                        $this->markTestIncomplete( "could not open file: $filePath" );
                }
+
                while ( !feof( $handle ) ) {
                        // Get the current chunk
-                       $chunkData = @fread( $handle, $chunkSize );
+                       wfSuppressWarnings();
+                       $chunkData = fread( $handle, $chunkSize );
+                       wfRestoreWarnings();
 
                        // Upload the current chunk into the $_FILE object:
                        $this->fakeUploadChunk( 'chunk', 'blob', $mimeType, $chunkData );
@@ -500,7 +508,8 @@ class ApiUploadTest extends ApiTestCaseUpload {
                        }
                        // Filekey set to chunk session
                        $params['filekey'] = $chunkSessionKey;
-                       // Update the offset ( always add chunkSize for subquent chunks should be in-sync with $result['upload']['offset'] )
+                       // Update the offset ( always add chunkSize for subquent chunks
+                       // should be in-sync with $result['upload']['offset'] )
                        $params['offset'] += $chunkSize;
                        // Make sure param offset is insync with resultOffset:
                        $this->assertEquals( $resultOffset, $params['offset'] );
@@ -528,7 +537,8 @@ class ApiUploadTest extends ApiTestCaseUpload {
                fclose( $handle );
 
                // Check that we got a valid file result:
-               wfDebug( __METHOD__ . " hohoh filesize {$fileSize} info {$result['upload']['imageinfo']['size']}\n\n" );
+               wfDebug( __METHOD__
+                       . " hohoh filesize {$fileSize} info {$result['upload']['imageinfo']['size']}\n\n" );
                $this->assertEquals( $fileSize, $result['upload']['imageinfo']['size'] );
                $this->assertEquals( $mimeType, $result['upload']['imageinfo']['mime'] );
                $this->assertTrue( isset( $result['upload']['filekey'] ) );
index 877e353..e3eea4c 100644 (file)
@@ -1,20 +1,23 @@
 <?php
-
 /**
  * RandomImageGenerator -- does what it says on the tin.
- * Requires Imagick, the ImageMagick library for PHP, or the command line equivalent (usually 'convert').
+ * Requires Imagick, the ImageMagick library for PHP, or the command line
+ * equivalent (usually 'convert').
  *
- * Because MediaWiki tests the uniqueness of media upload content, and filenames, it is sometimes useful to generate
- * files that are guaranteed (or at least very likely) to be unique in both those ways.
- * This generates a number of filenames with random names and random content (colored triangles)
+ * Because MediaWiki tests the uniqueness of media upload content, and
+ * filenames, it is sometimes useful to generate files that are guaranteed (or
+ * at least very likely) to be unique in both those ways. This generates a
+ * number of filenames with random names and random content (colored triangles).
  *
- * It is also useful to have fresh content because our tests currently run in a "destructive" mode, and don't create a fresh new wiki for each
- * test run.
- * Consequently, if we just had a few static files we kept re-uploading, we'd get lots of warnings about matching content or filenames,
- * and even if we deleted those files, we'd get warnings about archived files.
+ * It is also useful to have fresh content because our tests currently run in a
+ * "destructive" mode, and don't create a fresh new wiki for each test run.
+ * Consequently, if we just had a few static files we kept re-uploading, we'd
+ * get lots of warnings about matching content or filenames, and even if we
+ * deleted those files, we'd get warnings about archived files.
  *
- * This can also be used with a cronjob to generate random files all the time -- I use it to have a constant, never ending supply when I'm
- * testing interactively.
+ * This can also be used with a cronjob to generate random files all the time.
+ * I use it to have a constant, never ending supply when I'm testing
+ * interactively.
  *
  * @file
  * @author Neil Kandalgaonkar <neilk@wikimedia.org>
@@ -25,7 +28,6 @@
  * Can fetch a random image, or also write a number of them to disk with random filenames.
  */
 class RandomImageGenerator {
-
        private $dictionaryFile;
        private $minWidth = 400;
        private $maxWidth = 800;
@@ -34,10 +36,11 @@ class RandomImageGenerator {
        private $shapesToDraw = 5;
 
        /**
-        * Orientations: 0th row, 0th column, Exif orientation code, rotation 2x2 matrix that is opposite of orientation
-        * n.b. we do not handle the 'flipped' orientations, which is why there is no entry for 2, 4, 5, or 7. Those
-        * seem to be rare in real images anyway
-        * (we also would need a non-symmetric shape for the images to test those, like a letter F)
+        * Orientations: 0th row, 0th column, Exif orientation code, rotation 2x2
+        * matrix that is opposite of orientation. N.b. we do not handle the
+        * 'flipped' orientations, which is why there is no entry for 2, 4, 5, or 7.
+        * Those seem to be rare in real images anyway (we also would need a
+        * non-symmetric shape for the images to test those, like a letter F).
         */
        private static $orientations = array(
                array(
@@ -67,7 +70,9 @@ class RandomImageGenerator {
        );
 
        public function __construct( $options = array() ) {
-               foreach ( array( 'dictionaryFile', 'minWidth', 'minHeight', 'maxWidth', 'maxHeight', 'shapesToDraw' ) as $property ) {
+               foreach ( array( 'dictionaryFile', 'minWidth', 'minHeight',
+                       'maxWidth', 'maxHeight', 'shapesToDraw' ) as $property
+               ) {
                        if ( isset( $options[$property] ) ) {
                                $this->$property = $options[$property];
                        }
@@ -89,12 +94,14 @@ class RandomImageGenerator {
                        }
                }
                if ( !isset( $this->dictionaryFile ) ) {
-                       throw new Exception( "RandomImageGenerator: dictionary file not found or not specified properly" );
+                       throw new Exception( "RandomImageGenerator: dictionary file not "
+                               . "found or not specified properly" );
                }
        }
 
        /**
-        * Writes random images with random filenames to disk in the directory you specify, or current working directory
+        * Writes random images with random filenames to disk in the directory you
+        * specify, or current working directory.
         *
         * @param int $number Number of filenames to write
         * @param string $format Optional, must be understood by ImageMagick, such as 'jpg' or 'gif'
@@ -128,11 +135,15 @@ class RandomImageGenerator {
                        global $wgExiv2Command;
                        if ( class_exists( 'Imagick' ) && $wgExiv2Command && is_executable( $wgExiv2Command ) ) {
                                return 'writeImageWithApi';
-                       } elseif ( $wgUseImageMagick && $wgImageMagickConvertCommand && is_executable( $wgImageMagickConvertCommand ) ) {
+                       } elseif ( $wgUseImageMagick
+                               && $wgImageMagickConvertCommand
+                               && is_executable( $wgImageMagickConvertCommand )
+                       ) {
                                return 'writeImageWithCommandLine';
                        }
                }
-               throw new Exception( "RandomImageGenerator: could not find a suitable method to write images in '$format' format" );
+               throw new Exception( "RandomImageGenerator: could not find a suitable "
+                       . "method to write images in '$format' format" );
        }
 
        /**
@@ -163,9 +174,11 @@ class RandomImageGenerator {
 
        /**
         * Generate data representing an image of random size (within limits),
-        * consisting of randomly colored and sized upward pointing triangles against a random background color
-        * (This data is used in the writeImage* methods).
-        * @return {Mixed}
+        * consisting of randomly colored and sized upward pointing triangles
+        * against a random background color. (This data is used in the
+        * writeImage* methods).
+        *
+        * @return mixed
         */
        public function getImageSpec() {
                $spec = array();
@@ -264,8 +277,10 @@ class RandomImageGenerator {
 
                $image = new Imagick();
                /**
-                * If the format is 'jpg', will also add a random orientation -- the image will be drawn rotated with triangle points
-                * facing in some direction (0, 90, 180 or 270 degrees) and a countering rotation should turn the triangle points upward again
+                * If the format is 'jpg', will also add a random orientation -- the
+                * image will be drawn rotated with triangle points facing in some
+                * direction (0, 90, 180 or 270 degrees) and a countering rotation
+                * should turn the triangle points upward again.
                 */
                $orientation = self::$orientations[0]; // default is normal orientation
                if ( $format == 'jpg' ) {
@@ -289,8 +304,10 @@ class RandomImageGenerator {
 
                $image->writeImage( $filename );
 
-               // because the above setImageOrientation call doesn't work... nor can I get an external imagemagick binary to do this either...
-               // hacking this for now (only works if you have exiv2 installed, a program to read and manipulate exif)
+               // because the above setImageOrientation call doesn't work... nor can I
+               // get an external imagemagick binary to do this either... Hacking this
+               // for now (only works if you have exiv2 installed, a program to read
+               // and manipulate exif).
                if ( $wgExiv2Command ) {
                        $cmd = wfEscapeShellArg( $wgExiv2Command )
                                . " -M "
@@ -360,7 +377,8 @@ class RandomImageGenerator {
        }
 
        /**
-        * Based on an image specification, write such an image to disk, using the command line ImageMagick program ('convert').
+        * Based on an image specification, write such an image to disk, using the
+        * command line ImageMagick program ('convert').
         *
         * Sample command line:
         *  $ convert -size 100x60 xc:rgb(90,87,45) \
@@ -369,8 +387,8 @@ class RandomImageGenerator {
         *   -draw 'fill rgb(240,12,32)  circle 50,21 50,3'  filename.png
         *
         * @param array $spec Spec describing background and shapes to draw
-        * @param string $format File format to write (unused by this method but kept so it has the same signature as
-        * writeImageWithApi)
+        * @param string $format File format to write (unused by this method but
+        *   kept so it has the same signature as writeImageWithApi).
         * @param string $filename Filename to write to
         *
         * @return bool
@@ -410,7 +428,8 @@ class RandomImageGenerator {
        }
 
        /**
-        * Get an array of random pairs of random words, like array( array( 'foo', 'bar' ), array( 'quux', 'baz' ) );
+        * Get an array of random pairs of random words, like
+        * array( array( 'foo', 'bar' ), array( 'quux', 'baz' ) );
         *
         * @param int $number Number of pairs
         * @return array two-element arrays
@@ -447,8 +466,9 @@ class RandomImageGenerator {
                }
 
                /*
-                * This algorithm obtains N random lines from a file in one single pass. It does this by replacing elements of
-                * a fixed-size array of lines, less and less frequently as it reads the file.
+                * This algorithm obtains N random lines from a file in one single pass.
+                * It does this by replacing elements of a fixed-size array of lines,
+                * less and less frequently as it reads the file.
                 */
                $fh = fopen( $filepath, "r" );
                if ( !$fh ) {
index f1b773a..d8765ee 100644 (file)
@@ -173,7 +173,11 @@ abstract class ApiQueryContinueTestBase extends ApiQueryTestBase {
         * @param bool $numericIds If true, treat keys as ids to be merged instead of appending
         */
        protected function mergeResult( &$results, $newResult, $numericIds = false ) {
-               $this->assertEquals( is_array( $results ), is_array( $newResult ), 'Type of result and data do not match' );
+               $this->assertEquals(
+                       is_array( $results ),
+                       is_array( $newResult ),
+                       'Type of result and data do not match'
+               );
                if ( !is_array( $results ) ) {
                        $this->assertEquals( $results, $newResult, 'Repeated result must be the same as before' );
                } else {