r90147 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r90146‎ | r90147 | r90148 >
Date:20:43, 15 June 2011
Author:brion
Status:ok (Comments)
Tags:
Comment:
Fix for BlockTest -- when setup ran multiple times, the block entry wouldn't get re-saved and we'd end up with null or 0 as our block id.
By first removing any matching block, we can re-insert it at will and have a fresh working block to test.
Modified paths:
  • /trunk/phase3/tests/phpunit/includes/BlockTest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/phpunit/includes/BlockTest.php
@@ -28,7 +28,14 @@
2929
3030 $user->saveSettings();
3131 }
32 -
 32+
 33+ // Delete the last round's block if it's still there
 34+ $oldBlock = Block::newFromTarget( 'UTBlockee' );
 35+ if ( $oldBlock ) {
 36+ // An old block will prevent our new one from saving.
 37+ $oldBlock->delete();
 38+ }
 39+
3340 $this->block = new Block( 'UTBlockee', 1, 0,
3441 self::REASON
3542 );
@@ -38,7 +45,12 @@
3946 // save up ID for use in assertion. Since ID is an autoincrement,
4047 // its value might change depending on the order the tests are run.
4148 // ApiBlockTest insert its own blocks!
42 - $this->blockId = $this->block->getId();
 49+ $newBlockId = $this->block->getId();
 50+ if ($newBlockId) {
 51+ $this->blockId = $newBlockId;
 52+ } else {
 53+ throw new MWException( "Failed to insert block for BlockTest; old leftover block remaining?" );
 54+ }
4355 }
4456
4557 /**

Comments

#Comment by 😂 (talk | contribs)   20:52, 15 June 2011

Thank you!!

(I owe Brion 3 beers for this)

#Comment by Hashar (talk | contribs)   20:56, 15 June 2011

Add two more from me!

Status & tagging log