r63353 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r63352‎ | r63353 | r63354 >
Date:01:51, 7 March 2010
Author:demon
Status:ok (Comments)
Tags:
Comment:
Test case for wfLocalFile() returning valid objects when a file does not exist
Modified paths:
  • /trunk/phase3/maintenance/tests/LocalFileTest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/tests/LocalFileTest.php
@@ -92,6 +92,11 @@
9393 $this->assertEquals( '/testurl/Test%21', $this->file_hl0->getUrl() );
9494 $this->assertEquals( '/testurl/a/a2/Test%21', $this->file_hl2->getUrl() );
9595 }
 96+
 97+ function testWfLocalFile() {
 98+ $file = wfLocalFile( "File:Some_file_that_probably_doesn't exist.png" );
 99+ $this->assertThat( $file, $this->isInstanceOf( 'LocalFile' ), 'wfLocalFile() returns LocalFile for valid Titles' );
 100+ }
96101 }
97102
98103

Comments

#Comment by Ilmari Karonen (talk | contribs)   14:28, 8 March 2010

Um, I'm not very familiar with PHPUnit, but I'm fairly sure that the test case object won't and shouldn't be an instance of LocalFile. Should that perhaps say "$file->isInstanceOf( 'LocalFile' )"?

#Comment by 😂 (talk | contribs)   15:03, 8 March 2010

That's how PHPUnit does assertions. The first parameter to assertThat() is $file, the variable on which to perform the assertion. The second parameter $this->isInstanceOf( 'LocalFile' ) indicates which constraint to apply to $file. If you read the line in order without $this, it makes a bit more sense: "assertThat $file isInstanceOf( LocalFile )." I can see how this might look confusing though.

#Comment by Ilmari Karonen (talk | contribs)   15:11, 8 March 2010

OK, then PHPUnit is weirder than I thought it was. I had no idea that was even possible in PHP.

Oh, wait, I think I see it now... I suppose isInstanceOf() doesn't actually return a boolean as I'd assumed, but rather some object that tells assertThat() what condition to check $file against. Sneaky.

Status & tagging log