Fix for partial regression in r84534: Block::newFromId was no longer handling the...
authorBrion Vibber <brion@users.mediawiki.org>
Wed, 15 Jun 2011 19:05:25 +0000 (19:05 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Wed, 15 Jun 2011 19:05:25 +0000 (19:05 +0000)
This bug was showing up in test results like this:

  BlockTest::testInitializerFunctionsReturnCorrectBlock
  Trying to get property of non-object

  /home/ci/cruisecontrol-bin-2.8.3/projects/mw/source/includes/Block.php:340
  /home/ci/cruisecontrol-bin-2.8.3/projects/mw/source/includes/Block.php:365
  /home/ci/cruisecontrol-bin-2.8.3/projects/mw/source/includes/Block.php:118
  /home/ci/cruisecontrol-bin-2.8.3/projects/mw/source/tests/phpunit/includes/BlockTest.php:60
  /home/ci/cruisecontrol-bin-2.8.3/projects/mw/source/tests/phpunit/MediaWikiTestCase.php:60
  /home/ci/cruisecontrol-bin-2.8.3/projects/mw/source/tests/phpunit/MediaWikiPHPUnitCommand.php:20
  /home/ci/cruisecontrol-bin-2.8.3/projects/mw/source/tests/phpunit/phpunit.php:60

However, that only triggers because the actual test is failing -- it's expecting to get a return back. This can only be reproduce when using the suite.xml configuration file, and not when running the BlockTest standalone.

includes/Block.php

index 2856824..280552b 100644 (file)
@@ -105,7 +105,7 @@ class Block {
         * Load a blocked user from their block id.
         *
         * @param $id Integer: Block id to search for
-        * @return Block object
+        * @return Block object or null
         */
        public static function newFromID( $id ) {
                $dbr = wfGetDB( DB_SLAVE );
@@ -115,7 +115,11 @@ class Block {
                        array( 'ipb_id' => $id ),
                        __METHOD__
                );
-               return Block::newFromRow( $res );
+               if ( $res ) {
+                       return Block::newFromRow( $res );
+               } else {
+                       return null;
+               }
        }
 
        /**