Deprecate and stop using assertType(OrValue)

*assertType is marked as deprecated, and should ideally be removed soon
(i.e. no hard deprecation to follow)
*Most usages of assertType in core were autofixed by using I8ef556b630812aeea77c5606713f53d9af609f1b
*assertTypeOrValue was removed because only used in SiteTest
(codesearch: https://codesearch.wmflabs.org/search/?q=assertTypeOrValue&i=nope&files=&repos=)
*SiteTest::assertTypeOrFalse was removed because unused

Bug: T192167
Change-Id: Icb3014b8fe7d1c43e64a37e0bdaaffec18bb482f
This commit is contained in:
Daimona Eaytoy 2019-12-13 18:44:39 +01:00 committed by Krinkle
parent 2453a76b33
commit 726f10bf5d
8 changed files with 37 additions and 51 deletions

View file

@ -2107,33 +2107,12 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase {
}
}
/**
* Asserts that the provided variable is of the specified
* internal type or equals the $value argument. This is useful
* for testing return types of functions that return a certain
* type or *value* when not set or on error.
*
* @since 1.20
*
* @param string $type
* @param mixed $actual
* @param mixed $value
* @param string $message
*/
protected function assertTypeOrValue( $type, $actual, $value = false, $message = '' ) {
if ( $actual === $value ) {
$this->assertTrue( true, $message );
} else {
$this->assertType( $type, $actual, $message );
}
}
/**
* Asserts the type of the provided value. This can be either
* in internal type such as boolean or integer, or a class or
* interface the value extends or implements.
*
* @since 1.20
* @deprecated since 1.35 Following the PHPUnit deprecation of assertInternalType
*
* @param string $type
* @param mixed $actual

View file

@ -104,20 +104,20 @@ class NameTableStoreFactoryTest extends MediaWikiTestCase {
$services = MediaWikiServices::getInstance();
$factory = $services->getNameTableStoreFactory();
$store = $factory->getChangeTagDef();
$this->assertType( 'array', $store->getMap() );
$this->assertIsArray( $store->getMap() );
}
public function testIntegratedGetContentModels() {
$services = MediaWikiServices::getInstance();
$factory = $services->getNameTableStoreFactory();
$store = $factory->getContentModels();
$this->assertType( 'array', $store->getMap() );
$this->assertIsArray( $store->getMap() );
}
public function testIntegratedGetSlotRoles() {
$services = MediaWikiServices::getInstance();
$factory = $services->getNameTableStoreFactory();
$store = $factory->getSlotRoles();
$this->assertType( 'array', $store->getMap() );
$this->assertIsArray( $store->getMap() );
}
}

View file

@ -25,6 +25,6 @@ class AbstractAuthenticationProviderTest extends \MediaWikiTestCase {
$provider->setConfig( $obj );
$this->assertSame( $obj, $providerPriv->config, 'setConfig' );
$this->assertType( 'string', $provider->getUniqueId(), 'getUniqueId' );
$this->assertIsString( $provider->getUniqueId(), 'getUniqueId' );
}
}

View file

@ -12,7 +12,7 @@ class AuthenticationRequestTest extends \MediaWikiTestCase {
$this->assertSame( get_class( $mock ), $mock->getUniqueId() );
$this->assertType( 'array', $mock->getMetadata() );
$this->assertIsArray( $mock->getMetadata() );
$ret = $mock->describeCredentials();
$this->assertIsArray( $ret );

View file

@ -13,10 +13,10 @@ abstract class AuthenticationRequestTestCase extends \MediaWikiTestCase {
*/
public function testGetFieldInfo( array $args ) {
$info = $this->getInstance( $args )->getFieldInfo();
$this->assertType( 'array', $info );
$this->assertIsArray( $info );
foreach ( $info as $field => $data ) {
$this->assertType( 'array', $data, "Field $field" );
$this->assertIsArray( $data, "Field $field" );
$this->assertArrayHasKey( 'type', $data, "Field $field" );
$this->assertArrayHasKey( 'label', $data, "Field $field" );
$this->assertInstanceOf( \Message::class, $data['label'], "Field $field, label" );
@ -27,13 +27,13 @@ abstract class AuthenticationRequestTestCase extends \MediaWikiTestCase {
}
if ( isset( $data['optional'] ) ) {
$this->assertType( 'bool', $data['optional'], "Field $field, optional" );
$this->assertIsBool( $data['optional'], "Field $field, optional" );
}
if ( isset( $data['image'] ) ) {
$this->assertType( 'string', $data['image'], "Field $field, image" );
$this->assertIsString( $data['image'], "Field $field, image" );
}
if ( isset( $data['sensitive'] ) ) {
$this->assertType( 'bool', $data['sensitive'], "Field $field, sensitive" );
$this->assertIsBool( $data['sensitive'], "Field $field, sensitive" );
}
if ( $data['type'] === 'password' ) {
$this->assertTrue( !empty( $data['sensitive'] ),
@ -48,7 +48,7 @@ abstract class AuthenticationRequestTestCase extends \MediaWikiTestCase {
case 'select':
case 'multiselect':
$this->assertArrayHasKey( 'options', $data, "Field $field" );
$this->assertType( 'array', $data['options'], "Field $field, options" );
$this->assertIsArray( $data['options'], "Field $field, options" );
foreach ( $data['options'] as $val => $msg ) {
$this->assertInstanceOf( \Message::class, $msg, "Field $field, option $val" );
}

View file

@ -151,10 +151,10 @@ class LoadBalancerTest extends MediaWikiTestCase {
$this->assertTrue( $lb->isNonZeroLoad( 1 ) );
for ( $i = 0; $i < $lb->getServerCount(); ++$i ) {
$this->assertType( 'string', $lb->getServerName( $i ) );
$this->assertType( 'array', $lb->getServerInfo( $i ) );
$this->assertType( 'string', $lb->getServerType( $i ) );
$this->assertType( 'array', $lb->getServerAttributes( $i ) );
$this->assertIsString( $lb->getServerName( $i ) );
$this->assertIsArray( $lb->getServerInfo( $i ) );
$this->assertIsString( $lb->getServerType( $i ) );
$this->assertIsArray( $lb->getServerAttributes( $i ) );
}
$dbw = $lb->getConnection( DB_MASTER );

View file

@ -76,7 +76,10 @@ class SiteTest extends MediaWikiTestCase {
* @covers Site::getLanguageCode
*/
public function testGetLanguageCode( Site $site ) {
$this->assertTypeOrValue( 'string', $site->getLanguageCode(), null );
$this->assertThat(
$site->getLanguageCode(),
$this->logicalOr( $this->isNull(), $this->isType( 'string' ) )
);
}
/**
@ -104,7 +107,10 @@ class SiteTest extends MediaWikiTestCase {
* @covers Site::getGlobalId
*/
public function testGetGlobalId( Site $site ) {
$this->assertTypeOrValue( 'string', $site->getGlobalId(), null );
$this->assertThat(
$site->getGlobalId(),
$this->logicalOr( $this->isNull(), $this->isType( 'string' ) )
);
}
/**
@ -132,9 +138,18 @@ class SiteTest extends MediaWikiTestCase {
* @covers Site::getPath
*/
public function testGetPath( Site $site ) {
$this->assertTypeOrValue( 'string', $site->getPath( 'page_path' ), null );
$this->assertTypeOrValue( 'string', $site->getPath( 'file_path' ), null );
$this->assertTypeOrValue( 'string', $site->getPath( 'foobar' ), null );
$this->assertThat(
$site->getPath( 'page_path' ),
$this->logicalOr( $this->isNull(), $this->isType( 'string' ) )
);
$this->assertThat(
$site->getPath( 'file_path' ),
$this->logicalOr( $this->isNull(), $this->isType( 'string' ) )
);
$this->assertThat(
$site->getPath( 'foobar' ),
$this->logicalOr( $this->isNull(), $this->isType( 'string' ) )
);
}
/**
@ -266,14 +281,6 @@ class SiteTest extends MediaWikiTestCase {
$this->assertContains( $expected, $site->getPageUrl( $page ) );
}
protected function assertTypeOrFalse( $type, $value ) {
if ( $value === false ) {
$this->assertTrue( true );
} else {
$this->assertInternalType( $type, $value );
}
}
/**
* @dataProvider instanceProvider
* @param Site $site

View file

@ -1670,7 +1670,7 @@ class LanguageIntegrationTest extends LanguageClassesTestCase {
$this->setMwGlobals( [ 'wgTranslateNumerals' => $translateNumerals ] );
$lang = Language::factory( $langCode );
$formattedNum = $lang->formatNum( $number, $nocommafy );
$this->assertType( 'string', $formattedNum );
$this->assertIsString( $formattedNum );
$this->assertEquals( $expected, $formattedNum );
}