Replace complicated assertions with assertIsString() and such
This patch tries to make assertions in tests more readable by using more self-documenting assertions as provided by modern PHPUnit versions. Among a few others, these two main changes are done: * I found a lot of assertions with the expected value being the *second* parameter. I did not changed all of them. Only some that can be replaced with assertNull() and such. * I try to replace all `assertTrue( is_…() )` with dedicated assertions. Change-Id: I1fc72188fbd0edacf13886e7f9a9eacbd85f13c2
This commit is contained in:
parent
e963682c34
commit
9c57ea2b7f
13 changed files with 27 additions and 31 deletions
|
|
@ -34,10 +34,7 @@ class LessFileCompilationTest extends ResourceLoaderTestCase {
|
|||
|
||||
public function testLessFileCompilation() {
|
||||
$thisString = $this->toString();
|
||||
$this->assertTrue(
|
||||
is_string( $this->file ) && is_file( $this->file ) && is_readable( $this->file ),
|
||||
"$thisString must refer to a readable file"
|
||||
);
|
||||
$this->assertIsReadable( $this->file, "$thisString must refer to a readable file" );
|
||||
|
||||
$rlContext = $this->getResourceLoaderContext();
|
||||
|
||||
|
|
|
|||
|
|
@ -678,7 +678,7 @@ class ActorMigrationTest extends MediaWikiLangTestCase {
|
|||
$m = new ActorMigration( $stage );
|
||||
list( $fields, $callback )
|
||||
= $m->getInsertValuesWithTempTable( $this->db, 'am1_user', $this->getTestUser()->getUser() );
|
||||
$this->assertTrue( is_callable( $callback ) );
|
||||
$this->assertIsCallable( $callback );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -952,7 +952,7 @@ class CommentStoreTest extends MediaWikiLangTestCase {
|
|||
|
||||
$this->hideDeprecated( 'CommentStore::insertWithTempTable for ipb_reason' );
|
||||
list( $fields, $callback ) = $store->insertWithTempTable( $this->db, 'ipb_reason', 'foo' );
|
||||
$this->assertTrue( is_callable( $callback ) );
|
||||
$this->assertIsCallable( $callback );
|
||||
}
|
||||
|
||||
public function testInsertTruncation() {
|
||||
|
|
|
|||
|
|
@ -228,7 +228,7 @@ class FauxRequestTest extends MediaWikiIntegrationTestCase {
|
|||
$request = new FauxRequest();
|
||||
$request->setHeader( 'Accept', $value );
|
||||
|
||||
$this->assertFalse( $request->getHeader( 'Nonexistent' ) );
|
||||
$this->assertSame( false, $request->getHeader( 'Nonexistent' ) );
|
||||
$this->assertSame( $value, $request->getHeader( 'Accept' ) );
|
||||
$this->assertSame( $value, $request->getHeader( 'ACCEPT' ) );
|
||||
$this->assertSame( $value, $request->getHeader( 'accept' ) );
|
||||
|
|
@ -247,7 +247,7 @@ class FauxRequestTest extends MediaWikiIntegrationTestCase {
|
|||
$request = new FauxRequest();
|
||||
|
||||
$this->assertSame( [], $request->getAllHeaders() );
|
||||
$this->assertFalse( $request->getHeader( 'test' ) );
|
||||
$this->assertSame( false, $request->getHeader( 'test' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1089,7 +1089,7 @@ abstract class RevisionStoreDbTestBase extends MediaWikiTestCase {
|
|||
$arQuery['tables'], $arQuery['fields'], [ 'ar_rev_id' => $orig->getId() ],
|
||||
__METHOD__, [], $arQuery['joins']
|
||||
);
|
||||
$this->assertTrue( is_object( $res ), 'query failed' );
|
||||
$this->assertIsObject( $res, 'query failed' );
|
||||
|
||||
$row = $res->fetchObject();
|
||||
$res->free();
|
||||
|
|
@ -1119,7 +1119,7 @@ abstract class RevisionStoreDbTestBase extends MediaWikiTestCase {
|
|||
$arQuery['tables'], $arQuery['fields'], [ 'ar_rev_id' => $orig->getId() ],
|
||||
__METHOD__, [], $arQuery['joins']
|
||||
);
|
||||
$this->assertTrue( is_object( $res ), 'query failed' );
|
||||
$this->assertIsObject( $res, 'query failed' );
|
||||
|
||||
$row = $res->fetchObject();
|
||||
$res->free();
|
||||
|
|
|
|||
|
|
@ -391,7 +391,7 @@ abstract class RevisionDbTestBase extends MediaWikiTestCase {
|
|||
$revQuery = Revision::getQueryInfo();
|
||||
$res = $dbr->select( $revQuery['tables'], $revQuery['fields'], [ 'rev_id' => $orig->getId() ],
|
||||
__METHOD__, [], $revQuery['joins'] );
|
||||
$this->assertTrue( is_object( $res ), 'query failed' );
|
||||
$this->assertIsObject( $res, 'query failed' );
|
||||
|
||||
$row = $res->fetchObject();
|
||||
$res->free();
|
||||
|
|
@ -481,7 +481,7 @@ abstract class RevisionDbTestBase extends MediaWikiTestCase {
|
|||
$arQuery['tables'], $arQuery['fields'], [ 'ar_rev_id' => $orig->getId() ],
|
||||
__METHOD__, [], $arQuery['joins']
|
||||
);
|
||||
$this->assertTrue( is_object( $res ), 'query failed' );
|
||||
$this->assertIsObject( $res, 'query failed' );
|
||||
|
||||
$row = $res->fetchObject();
|
||||
$res->free();
|
||||
|
|
@ -511,7 +511,7 @@ abstract class RevisionDbTestBase extends MediaWikiTestCase {
|
|||
$arQuery['tables'], $arQuery['fields'], [ 'ar_rev_id' => $orig->getId() ],
|
||||
__METHOD__, [], $arQuery['joins']
|
||||
);
|
||||
$this->assertTrue( is_object( $res ), 'query failed' );
|
||||
$this->assertIsObject( $res, 'query failed' );
|
||||
|
||||
$row = $res->fetchObject();
|
||||
$res->free();
|
||||
|
|
|
|||
|
|
@ -52,9 +52,9 @@ class ApiRevisionDeleteTest extends ApiTestCase {
|
|||
|
||||
// Now check that that revision was actually hidden
|
||||
$rev = Revision::newFromId( $revid );
|
||||
$this->assertEquals( $rev->getContent( Revision::FOR_PUBLIC ), null );
|
||||
$this->assertEquals( $rev->getComment( Revision::FOR_PUBLIC ), '' );
|
||||
$this->assertEquals( $rev->getUser( Revision::FOR_PUBLIC ), 0 );
|
||||
$this->assertNull( $rev->getContent( Revision::FOR_PUBLIC ) );
|
||||
$this->assertNull( $rev->getComment( Revision::FOR_PUBLIC ) );
|
||||
$this->assertSame( 0, $rev->getUser( Revision::FOR_PUBLIC ) );
|
||||
|
||||
// Now test unhiding!
|
||||
$out2 = $this->doApiRequest( [
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ class JpegPixelFormatTest extends MediaWikiMediaTestCase {
|
|||
$this->assertTrue( !$thumb->isError(), "created JPEG thumbnail for pixel format $fmtStr" );
|
||||
|
||||
$path = $thumb->getLocalCopyPath();
|
||||
$this->assertTrue( is_string( $path ), "path returned for JPEG thumbnail for $fmtStr" );
|
||||
$this->assertIsString( $path, "path returned for JPEG thumbnail for $fmtStr" );
|
||||
|
||||
$result = Shell::command( 'identify',
|
||||
'-format',
|
||||
|
|
|
|||
|
|
@ -81,19 +81,19 @@ class ParserOutputTest extends MediaWikiLangTestCase {
|
|||
$po->setProperty( 'foo', 'val' );
|
||||
|
||||
$properties = $po->getProperties();
|
||||
$this->assertEquals( $po->getProperty( 'foo' ), 'val' );
|
||||
$this->assertEquals( $properties['foo'], 'val' );
|
||||
$this->assertSame( 'val', $po->getProperty( 'foo' ) );
|
||||
$this->assertSame( 'val', $properties['foo'] );
|
||||
|
||||
$po->setProperty( 'foo', 'second val' );
|
||||
|
||||
$properties = $po->getProperties();
|
||||
$this->assertEquals( $po->getProperty( 'foo' ), 'second val' );
|
||||
$this->assertEquals( $properties['foo'], 'second val' );
|
||||
$this->assertSame( 'second val', $po->getProperty( 'foo' ) );
|
||||
$this->assertSame( 'second val', $properties['foo'] );
|
||||
|
||||
$po->unsetProperty( 'foo' );
|
||||
|
||||
$properties = $po->getProperties();
|
||||
$this->assertEquals( $po->getProperty( 'foo' ), false );
|
||||
$this->assertSame( false, $po->getProperty( 'foo' ) );
|
||||
$this->assertArrayNotHasKey( 'foo', $properties );
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ class SearchEngineTest extends MediaWikiLangTestCase {
|
|||
$this->markTestIncomplete( __CLASS__ . " does no yet support non-wikitext content "
|
||||
. "in the main namespace" );
|
||||
}
|
||||
$this->assertTrue( is_object( $results ) );
|
||||
$this->assertIsObject( $results );
|
||||
|
||||
$matches = [];
|
||||
foreach ( $results as $row ) {
|
||||
|
|
|
|||
|
|
@ -91,14 +91,14 @@ class DBSiteStoreTest extends MediaWikiTestCase {
|
|||
$site = $store->getSite( 'ertrywuutr' );
|
||||
$this->assertInstanceOf( Site::class, $site );
|
||||
$this->assertEquals( 'en', $site->getLanguageCode() );
|
||||
$this->assertTrue( is_int( $site->getInternalId() ) );
|
||||
$this->assertTrue( $site->getInternalId() >= 0 );
|
||||
$this->assertIsInt( $site->getInternalId() );
|
||||
$this->assertGreaterThanOrEqual( 0, $site->getInternalId() );
|
||||
|
||||
$site = $store->getSite( 'sdfhxujgkfpth' );
|
||||
$this->assertInstanceOf( Site::class, $site );
|
||||
$this->assertEquals( 'nl', $site->getLanguageCode() );
|
||||
$this->assertTrue( is_int( $site->getInternalId() ) );
|
||||
$this->assertTrue( $site->getInternalId() >= 0 );
|
||||
$this->assertIsInt( $site->getInternalId() );
|
||||
$this->assertGreaterThanOrEqual( 0, $site->getInternalId() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -188,7 +188,7 @@ class SiteListTest extends MediaWikiTestCase {
|
|||
public function testGetGlobalIdentifiers( SiteList $sites ) {
|
||||
$identifiers = $sites->getGlobalIdentifiers();
|
||||
|
||||
$this->assertTrue( is_array( $identifiers ) );
|
||||
$this->assertIsArray( $identifiers );
|
||||
|
||||
$expected = [];
|
||||
|
||||
|
|
|
|||
|
|
@ -164,9 +164,8 @@ class XmlSelectTest extends \MediaWikiUnitTestCase {
|
|||
);
|
||||
|
||||
# inexistent keys should give us 'null'
|
||||
$this->assertEquals(
|
||||
$this->select->getAttribute( 'I DO NOT EXIT' ),
|
||||
null
|
||||
$this->assertNull(
|
||||
$this->select->getAttribute( 'I DO NOT EXIT' )
|
||||
);
|
||||
|
||||
# verify string / integer
|
||||
|
|
|
|||
Loading…
Reference in a new issue