tests: Change expectDeprecation to expectDeprecationAndContinue

TestCase::expectDeprecation() is deprecated in PHPUnit 10,
use mediawiki own MediaWikiTestCaseTrait::expectDeprecationAndContinue()
for this case. This avoids the trigger_error call and isolate the
deprecation check into MWDebug class.

The continue part is also helpful in StubGlobalUserTest, where after the
first deprecation access more code exists, that was not executed as
PhpUnit 9 converts deprecations to exceptions.
In RCFeedTest the exception needs to be catched as the code proceed
after the deprecation notice is emitted.

Bug: T342110
Change-Id: Iecf827bec0d5215fd21bbb20b84caf928ee108a0
This commit is contained in:
Umherirrender 2023-07-13 22:00:47 +02:00
parent bffa95de81
commit 0099099bb0
9 changed files with 21 additions and 26 deletions

View file

@ -31,7 +31,8 @@ class DeprecationHelperTest extends MediaWikiIntegrationTestCase {
}, $expectedLevel, $expectedMessage );
} else {
$this->assertDeprecationWarningIssued( function () use ( $propName ) {
$this->assertSame( 1, $this->testClass->$propName );
$expectedValue = $propName === 'fallbackDeprecatedMethodName' ? 'FOO' : 1;
$this->assertSame( $expectedValue, $this->testClass->$propName );
}, $expectedMessage );
}
}
@ -225,8 +226,7 @@ class DeprecationHelperTest extends MediaWikiIntegrationTestCase {
}
protected function assertDeprecationWarningIssued( callable $callback, string $expectedMessage ) {
$this->expectDeprecation();
$this->expectDeprecationMessage( $expectedMessage );
$this->expectDeprecationAndContinue( '/' . preg_quote( $expectedMessage, '/' ) . '/' );
$callback();
}

View file

@ -75,8 +75,8 @@ class StubGlobalUserTest extends MediaWikiIntegrationTestCase {
}
public function testMagicCall() {
$this->expectDeprecation();
$this->expectDeprecationMessage( 'Use of $wgUser was deprecated in MediaWiki 1.35' );
$this->expectDeprecationAndContinue( '/Use of \$wgUser was deprecated in MediaWiki 1\.35/' );
$this->expectDeprecationAndContinue( '/\$wgUser reassignment detected/' );
global $wgUser;
$this->assertInstanceOf(
@ -97,8 +97,8 @@ class StubGlobalUserTest extends MediaWikiIntegrationTestCase {
}
public function testGetMagic() {
$this->expectDeprecation();
$this->expectDeprecationMessage( 'Use of $wgUser was deprecated in MediaWiki 1.35' );
$this->expectDeprecationAndContinue( '/Use of \$wgUser was deprecated in MediaWiki 1\.35/' );
$this->expectDeprecationAndContinue( '/\$wgUser reassignment detected/' );
global $wgUser;
$this->assertInstanceOf(
@ -123,8 +123,8 @@ class StubGlobalUserTest extends MediaWikiIntegrationTestCase {
// and not try to detect and throw exceptions in unstub loops - for some reason it
// thinks this creates a loop.
$this->expectDeprecation();
$this->expectDeprecationMessage( 'Use of $wgUser was deprecated in MediaWiki 1.35' );
$this->expectDeprecationAndContinue( '/Use of \$wgUser was deprecated in MediaWiki 1\.35/' );
$this->expectDeprecationAndContinue( '/\$wgUser reassignment detected/' );
global $wgUser;
$this->assertInstanceOf(
@ -146,7 +146,7 @@ class StubGlobalUserTest extends MediaWikiIntegrationTestCase {
}
public function testDeprecationEmittedWhenReassigned() {
$this->expectDeprecation();
$this->expectDeprecationAndContinue( '/\$wgUser reassignment detected/' );
global $wgUser;
$wgUser = new User;
}

View file

@ -73,8 +73,7 @@ class DeprecatedGlobalTest extends MediaWikiUnitTestCase {
global $wgDummy1;
$wgDummy1 = new DeprecatedGlobal( 'wgDummy1', new HashBagOStuff(), '1.30' );
$this->expectDeprecation();
$this->expectDeprecationMessage( 'Use of $wgDummy1 was deprecated in MediaWiki 1.30' );
$this->expectDeprecationAndContinue( '/Use of \$wgDummy1 was deprecated in MediaWiki 1\.30/' );
$wgDummy1->get( 'foo' );
$this->assertInstanceOf( HashBagOStuff::class, $wgDummy1 );
}

View file

@ -46,8 +46,7 @@ trait RevisionRecordTests {
}
public function testGetIdTriggerDeprecatedWarning() {
$this->expectDeprecation();
$this->expectDeprecationMessageMatches( '/Deprecated cross-wiki access.*/' );
$this->expectDeprecationAndContinue( '/Deprecated cross-wiki access/' );
$revision = $this->newRevision( [ 'wikiId' => 'acmewiki', 'rev_id' => 5 ] );
$revision->getId();
}
@ -64,8 +63,7 @@ trait RevisionRecordTests {
}
public function testGetPageIdTriggerDeprecatedWarning() {
$this->expectDeprecation();
$this->expectDeprecationMessageMatches( '/Deprecated cross-wiki access.*/' );
$this->expectDeprecationAndContinue( '/Deprecated cross-wiki access/' );
$revision = $this->newRevision( [ 'wikiId' => 'acmewiki', 'rev_page_id' => 17 ] );
$revision->getPageId();
}
@ -82,8 +80,7 @@ trait RevisionRecordTests {
}
public function testGetParentIdTriggerDeprecatedWarning() {
$this->expectDeprecation();
$this->expectDeprecationMessageMatches( '/Deprecated cross-wiki access.*/' );
$this->expectDeprecationAndContinue( '/Deprecated cross-wiki access/' );
$revision = $this->newRevision( [ 'wikiId' => 'acmewiki', 'rev_parent_id' => 1 ] );
$revision->getParentId();
}

View file

@ -95,7 +95,7 @@ class WikiAwareEntityTraitTest extends MediaWikiUnitTestCase {
* @dataProvider provideMismatchingWikis
*/
public function testDeprecateInvalidCrossWikiMismatch( $entityWiki, $assertWiki ) {
$this->expectDeprecation();
$this->expectDeprecationAndContinue( '/Deprecated cross-wiki access/' );
TestingAccessWrapper::newFromObject( $this->getEntityInstance( $entityWiki ) )
->deprecateInvalidCrossWiki( $assertWiki, '1.99' );
}

View file

@ -13,8 +13,7 @@ class DeprecatablePropertyArrayTest extends MediaWikiUnitTestCase {
* @dataProvider provideDeprecationWarning
*/
public function testDeprecationWarning( callable $callback, string $message ) {
$this->expectDeprecation();
$this->expectDeprecationMessage( $message );
$this->expectDeprecationAndContinue( '/' . preg_quote( $message, '/' ) . '/' );
$callback();
}

View file

@ -555,7 +555,7 @@ class SQLPlatformTest extends PHPUnit\Framework\TestCase {
* @dataProvider provideUpdateEmptyCondition
*/
public function testUpdateEmptyCondition( $sql ) {
$this->expectDeprecation();
$this->expectDeprecationAndContinue( '/Use of Wikimedia\\\\Rdbms\\\\Platform\\\\SQLPlatform::updateSqlText called with empty \$conds was deprecated in MediaWiki 1\.35/' );
$this->platform->updateSqlText(
$sql['table'],
$sql['values'],

View file

@ -36,8 +36,8 @@ class RCFeedTest extends MediaWikiUnitTestCase {
}
public function testFactoryCustomUriDeprecated() {
$this->expectDeprecation();
$this->expectDeprecationMessage( '$wgRCFeeds without class' );
$this->expectDeprecationAndContinue( '/\$wgRCFeeds without class/' );
$this->expectException( InvalidArgumentException::class );
$feed = RCFeed::factory( [ 'uri' => 'test://bogus' ] );
}

View file

@ -15,7 +15,7 @@ class UserIdentityValueTest extends MediaWikiUnitTestCase {
$foreignWikiId = 'Foreign Wiki';
$user = new UserIdentityValue( 0, 'TestUserName', UserIdentityValue::LOCAL );
$this->expectDeprecation();
$this->expectDeprecationAndContinue( '/Use of MediaWiki\\\\User\\\\UserIdentityValue::getActorId was deprecated in MediaWiki 1\.36/' );
$this->assertSame( 0, $user->getActorId( $foreignWikiId ) );
}
@ -25,7 +25,7 @@ class UserIdentityValueTest extends MediaWikiUnitTestCase {
public function testGetActorIdDeprecated() {
$user = new UserIdentityValue( 0, 'TestUserName' );
$this->expectDeprecation();
$this->expectDeprecationAndContinue( '/Use of MediaWiki\\\\User\\\\UserIdentityValue::getActorId was deprecated in MediaWiki 1\.36/' );
$this->assertSame( 0, $user->getActorId() );
}