tests: Change use of AtEase to at operator

Follows-up I361fde0de7f4406bce6ed075ed397effa5be3359.

Per T253461, not mass-changing source code, but the use of the native
error silencing operator (@) is especially useful in tests because:

1. It requires any/all statements to be explicitly marked. The
   suppressWarnings/restoreWarnings sections encourage developers to
   be "lazy" and thus encapsulate more than needed if there are multiple
   ones near each other, which would ignore potentially important
   warnings in a test case, which is generally exactly the time when
   it is really useful to get warnings etc.

2. It avoids leaking state, for example in LBFactoryTest the
   assertFalse call would throw a PHPUnit assertion error (not meant
   to be caught by the local catch), and thus won't reach
   AtEase::restoreWarnings. This then causes later code to end up
   in a mismatching state and creates a confusing error_reporting
   state.

See .phpcs.xml, where the at operator is allowed for all test code.

Change-Id: I68d1725d685e0a7586468bc9de6dc29ceea31b8a
This commit is contained in:
Timo Tijhof 2022-02-24 19:57:59 +00:00
parent 99e1b7312e
commit 128debb64b
30 changed files with 70 additions and 201 deletions

View file

@ -1,12 +1,8 @@
<?php
use Wikimedia\AtEase\AtEase;
/**
* @file
* @ingroup Testing
*/
class ParserTestResultNormalizer {
protected $doc, $xpath, $invalid;
@ -24,15 +20,13 @@ class ParserTestResultNormalizer {
protected function __construct( $text ) {
$this->doc = new DOMDocument( '1.0', 'utf-8' );
// Note: parsing a supposedly XHTML document with an XML parser is not
// Parsing a supposedly-XHTML document with an XML parser is not
// guaranteed to give accurate results. For example, it may introduce
// differences in the number of line breaks in <pre> tags.
AtEase::suppressWarnings();
if ( !$this->doc->loadXML( '<html><body>' . $text . '</body></html>' ) ) {
if ( !@$this->doc->loadXML( '<html><body>' . $text . '</body></html>' ) ) {
$this->invalid = true;
}
AtEase::restoreWarnings();
$this->xpath = new DOMXPath( $this->doc );
$this->body = $this->xpath->query( '//body' )->item( 0 );
}

View file

@ -32,7 +32,6 @@ use MediaWiki\Revision\MutableRevisionRecord;
use MediaWiki\Revision\RevisionRecord;
use MediaWiki\Revision\SlotRecord;
use Psr\Log\NullLogger;
use Wikimedia\AtEase\AtEase;
use Wikimedia\Parsoid\ParserTests\ParserHook as ParsoidParserHook;
use Wikimedia\Parsoid\ParserTests\RawHTML as ParsoidRawHTML;
use Wikimedia\Parsoid\ParserTests\StyleTag as ParsoidStyleTag;
@ -1356,9 +1355,7 @@ class ParserTestRunner {
MediaWikiServices::getInstance()->getLanguageConverterFactory()
->getLanguageConverter( $context->getLanguage() )
);
AtEase::suppressWarnings();
$wrapper->reloadTables();
AtEase::restoreWarnings();
@$wrapper->reloadTables();
// Reset context to the restored globals
$context->setUser( StubGlobalUser::getRealUser( $GLOBALS['wgUser'] ) );

View file

@ -1,7 +1,6 @@
<?php
use MediaWiki\Settings\SettingsBuilder;
use Wikimedia\AtEase\AtEase;
use Wikimedia\ScopedCallback;
require_once __DIR__ . '/../../maintenance/Maintenance.php';
@ -166,9 +165,7 @@ class ParserFuzzTest extends Maintenance {
public function guessVarSize( $var ) {
$length = 0;
try {
AtEase::suppressWarnings();
$length = strlen( serialize( $var ) );
AtEase::restoreWarnings();
$length = strlen( @serialize( $var ) );
} catch ( Exception $e ) {
}
return $length;

View file

@ -15,7 +15,6 @@ use PHPUnit\Framework\TestResult;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
use SebastianBergmann\Comparator\ComparisonFailure;
use Wikimedia\AtEase\AtEase;
use Wikimedia\Rdbms\Database;
use Wikimedia\Rdbms\IDatabase;
use Wikimedia\Rdbms\IMaintainableDatabase;
@ -2285,12 +2284,9 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase {
protected function markTestSkippedIfNoDiff3() {
global $wgDiff3;
# This check may also protect against code injection in
# case of broken installations.
AtEase::suppressWarnings();
$haveDiff3 = $wgDiff3 && is_file( $wgDiff3 );
AtEase::restoreWarnings();
// This check may also protect against code injection in
// case of broken installations.
$haveDiff3 = $wgDiff3 && @is_file( $wgDiff3 );
if ( !$haveDiff3 ) {
$this->markTestSkipped( "Skip test, since diff3 is not configured" );
}

View file

@ -1,8 +1,6 @@
<?php
use Wikimedia\AtEase\AtEase;
use Wikimedia\Rdbms\IMaintainableDatabase;
use Wikimedia\ScopedCallback;
/**
* @group Database
@ -716,13 +714,11 @@ class CommentStoreTest extends MediaWikiLangTestCase {
}
public function testGetCommentErrors() {
AtEase::suppressWarnings();
$reset = new ScopedCallback( [ AtEase::class, 'restoreWarnings' ] );
$store = $this->makeStore( MIGRATION_OLD );
$res = $store->getComment( 'dummy', [ 'dummy' => 'comment' ] );
// Ignore: Missing dummy_text and dummy_data fields
$res = @$store->getComment( 'dummy', [ 'dummy' => 'comment' ] );
$this->assertSame( '', $res->text );
$res = $store->getComment( 'dummy', [ 'dummy' => 'comment' ], true );
$res = @$store->getComment( 'dummy', [ 'dummy' => 'comment' ], true );
$this->assertSame( 'comment', $res->text );
$store = $this->makeStore( MIGRATION_NEW );
@ -732,7 +728,8 @@ class CommentStoreTest extends MediaWikiLangTestCase {
} catch ( InvalidArgumentException $ex ) {
$this->assertSame( '$row does not contain fields needed for comment dummy', $ex->getMessage() );
}
$res = $store->getComment( 'dummy', [ 'dummy' => 'comment' ], true );
// Ignore: Using deprecated fallback handling for comment dummy
$res = @$store->getComment( 'dummy', [ 'dummy' => 'comment' ], true );
$this->assertSame( 'comment', $res->text );
try {
$store->getComment( 'dummy', [ 'dummy_id' => 1 ] );
@ -754,7 +751,7 @@ class CommentStoreTest extends MediaWikiLangTestCase {
'$row does not contain fields needed for comment rev_comment', $ex->getMessage()
);
}
$res = $store->getComment( 'rev_comment', [ 'rev_comment' => 'comment' ], true );
$res = @$store->getComment( 'rev_comment', [ 'rev_comment' => 'comment' ], true );
$this->assertSame( 'comment', $res->text );
try {
$store->getComment( 'rev_comment', [ 'rev_comment_pk' => 1 ] );

View file

@ -1,7 +1,6 @@
<?php
use MediaWiki\Logger\LegacyLogger;
use Wikimedia\AtEase\AtEase;
/**
* @group Database
@ -563,10 +562,7 @@ class GlobalTest extends MediaWikiIntegrationTestCase {
public function testWfMkdirParents() {
// Should not return true if file exists instead of directory
$fname = $this->getNewTempFile();
AtEase::suppressWarnings();
$ok = wfMkdirParents( $fname );
AtEase::restoreWarnings();
$this->assertFalse( $ok );
$this->assertFalse( @wfMkdirParents( $fname ) );
}
/**

View file

@ -1,9 +1,6 @@
<?php
use Wikimedia\AtEase\AtEase;
class HtmlTest extends MediaWikiIntegrationTestCase {
private $restoreWarnings;
protected function setUp(): void {
parent::setUp();
@ -64,17 +61,6 @@ class HtmlTest extends MediaWikiIntegrationTestCase {
101 => "Personalizado discusión",
] );
$this->setUserLang( $userLangObj );
$this->restoreWarnings = false;
}
protected function tearDown(): void {
if ( $this->restoreWarnings ) {
$this->restoreWarnings = false;
AtEase::restoreWarnings();
}
parent::tearDown();
}
/**
@ -870,10 +856,11 @@ class HtmlTest extends MediaWikiIntegrationTestCase {
*/
public function testInlineScript( $code, $expected, $error = false ) {
if ( $error ) {
AtEase::suppressWarnings();
$this->restoreWarnings = true;
$html = @Html::inlineScript( $code );
} else {
$html = Html::inlineScript( $code );
}
$this->assertSame( $expected, Html::inlineScript( $code ) );
$this->assertSame( $expected, $html );
}
}

View file

@ -3,7 +3,6 @@
use MediaWiki\Revision\MutableRevisionRecord;
use MediaWiki\Revision\RevisionRecord;
use MediaWiki\Revision\SlotRecord;
use Wikimedia\AtEase\AtEase;
/**
* @group Database
@ -20,11 +19,9 @@ class LinkerTest extends MediaWikiLangTestCase {
// We'd also test the warning, but injecting a mock logger into a static method is tricky.
if ( !$userName ) {
AtEase::suppressWarnings();
}
$actual = Linker::userLink( $userId, $userName, $altUserName );
if ( !$userName ) {
AtEase::restoreWarnings();
$actual = @Linker::userLink( $userId, $userName, $altUserName );
} else {
$actual = Linker::userLink( $userId, $userName, $altUserName );
}
$this->assertEquals( $expected, $actual, $msg );
@ -162,11 +159,9 @@ class LinkerTest extends MediaWikiLangTestCase {
public function testUserToolLinks( $expected, $userId, $userText ) {
// We'd also test the warning, but injecting a mock logger into a static method is tricky.
if ( $userText === '' ) {
AtEase::suppressWarnings();
}
$actual = Linker::userToolLinks( $userId, $userText );
if ( $userText === '' ) {
AtEase::restoreWarnings();
$actual = @Linker::userToolLinks( $userId, $userText );
} else {
$actual = Linker::userToolLinks( $userId, $userText );
}
$this->assertSame( $expected, $actual );
@ -190,11 +185,9 @@ class LinkerTest extends MediaWikiLangTestCase {
public function testUserTalkLink( $expected, $userId, $userText ) {
// We'd also test the warning, but injecting a mock logger into a static method is tricky.
if ( $userText === '' ) {
AtEase::suppressWarnings();
}
$actual = Linker::userTalkLink( $userId, $userText );
if ( $userText === '' ) {
AtEase::restoreWarnings();
$actual = @Linker::userTalkLink( $userId, $userText );
} else {
$actual = Linker::userTalkLink( $userId, $userText );
}
$this->assertSame( $expected, $actual );
@ -218,11 +211,9 @@ class LinkerTest extends MediaWikiLangTestCase {
public function testBlockLink( $expected, $userId, $userText ) {
// We'd also test the warning, but injecting a mock logger into a static method is tricky.
if ( $userText === '' ) {
AtEase::suppressWarnings();
}
$actual = Linker::blockLink( $userId, $userText );
if ( $userText === '' ) {
AtEase::restoreWarnings();
$actual = @Linker::blockLink( $userId, $userText );
} else {
$actual = Linker::blockLink( $userId, $userText );
}
$this->assertSame( $expected, $actual );
@ -246,11 +237,9 @@ class LinkerTest extends MediaWikiLangTestCase {
public function testEmailLink( $expected, $userId, $userText ) {
// We'd also test the warning, but injecting a mock logger into a static method is tricky.
if ( $userText === '' ) {
AtEase::suppressWarnings();
}
$actual = Linker::emailLink( $userId, $userText );
if ( $userText === '' ) {
AtEase::restoreWarnings();
$actual = @Linker::emailLink( $userId, $userText );
} else {
$actual = Linker::emailLink( $userId, $userText );
}
$this->assertSame( $expected, $actual );

View file

@ -1,7 +1,5 @@
<?php
use Wikimedia\AtEase\AtEase;
/**
* @covers \MagicWordFactory
*
@ -39,12 +37,7 @@ class MagicWordFactoryTest extends MediaWikiIntegrationTestCase {
$magicWordFactory = $this->makeMagicWordFactory();
$this->expectException( MWException::class );
AtEase::suppressWarnings();
try {
$magicWordFactory->get( 'invalid magic word' );
} finally {
AtEase::restoreWarnings();
}
@$magicWordFactory->get( 'invalid magic word' );
}
public function testGetVariableIDs() {

View file

@ -8,7 +8,6 @@ use MediaWiki\Page\PageStoreRecord;
use MediaWiki\Permissions\Authority;
use MediaWiki\Tests\Unit\Permissions\MockAuthorityTrait;
use PHPUnit\Framework\MockObject\MockObject;
use Wikimedia\AtEase\AtEase;
use Wikimedia\DependencyStore\KeyValueDependencyStore;
use Wikimedia\TestingAccessWrapper;
@ -491,13 +490,8 @@ class OutputPageTest extends MediaWikiIntegrationTestCase {
$callback( $op, $this );
}
// Avoid a complaint about not being able to disable compression
AtEase::suppressWarnings();
try {
$this->assertEquals( $expected, $op->checkLastModified( $timestamp ) );
} finally {
AtEase::restoreWarnings();
}
// Ignore complaint about not being able to disable compression
$this->assertEquals( $expected, @$op->checkLastModified( $timestamp ) );
}
public function provideCheckLastModified() {
@ -2790,9 +2784,7 @@ class OutputPageTest extends MediaWikiIntegrationTestCase {
] );
// Some of these paths don't exist and will cause warnings
AtEase::suppressWarnings();
$actual = OutputPage::transformResourcePath( $conf, $path );
AtEase::restoreWarnings();
$actual = @OutputPage::transformResourcePath( $conf, $path );
$this->assertEquals( $expected ?: $path, $actual );
}

View file

@ -38,7 +38,6 @@ use TitleFactory;
use User;
use WANObjectCache;
use Wikimedia\Assert\PreconditionException;
use Wikimedia\AtEase\AtEase;
use Wikimedia\Rdbms\Database;
use Wikimedia\Rdbms\DatabaseDomain;
use Wikimedia\Rdbms\DatabaseSqlite;
@ -1534,9 +1533,7 @@ class RevisionStoreDbTest extends MediaWikiIntegrationTestCase {
'ar_actor' => null,
];
AtEase::suppressWarnings();
$record = $store->newRevisionFromArchiveRow( $row );
AtEase::suppressWarnings( true );
$record = @$store->newRevisionFromArchiveRow( $row );
$this->assertInstanceOf( RevisionRecord::class, $record );
$this->assertInstanceOf( UserIdentityValue::class, $record->getUser() );
@ -1583,9 +1580,7 @@ class RevisionStoreDbTest extends MediaWikiIntegrationTestCase {
$row->ar_actor = $this->db->insertId();
AtEase::suppressWarnings();
$record = $store->newRevisionFromArchiveRow( $row );
AtEase::suppressWarnings( true );
$record = @$store->newRevisionFromArchiveRow( $row );
$this->assertInstanceOf( RevisionRecord::class, $record );
$this->assertInstanceOf( UserIdentityValue::class, $record->getUser() );
@ -1622,10 +1617,7 @@ class RevisionStoreDbTest extends MediaWikiIntegrationTestCase {
'rev_content_model' => null,
];
AtEase::suppressWarnings();
$record = $store->newRevisionFromRow( $row, 0, $title );
AtEase::suppressWarnings( true );
$record = @$store->newRevisionFromRow( $row, 0, $title );
$this->assertNotNull( $record );
$this->assertNotNull( $record->getUser() );
$this->assertNotEmpty( $record->getUser()->getName() );

View file

@ -22,7 +22,6 @@ use Status;
use TextContent;
use Title;
use User;
use Wikimedia\AtEase\AtEase;
use WikiPage;
use WikitextContent;
@ -709,9 +708,7 @@ class PageUpdaterTest extends MediaWikiIntegrationTestCase {
// to emulate confusion due to a page move.
$title->resetArticleID( 886655 );
AtEase::suppressWarnings();
$updater->saveRevision( $summary, EDIT_UPDATE );
AtEase::restoreWarnings();
@$updater->saveRevision( $summary, EDIT_UPDATE );
$this->assertTrue( $updater->wasSuccessful(), 'wasSuccessful()' );
}

View file

@ -11,7 +11,6 @@ use MediaWiki\Storage\SqlBlobStore;
use MediaWikiIntegrationTestCase;
use TitleValue;
use WANObjectCache;
use Wikimedia\AtEase\AtEase;
use Wikimedia\Rdbms\LoadBalancer;
/**
@ -537,11 +536,9 @@ class SqlBlobStoreTest extends MediaWikiIntegrationTestCase {
$this->checkPHPExtension( 'zlib' );
$blobStore = $this->getBlobStore();
AtEase::suppressWarnings();
$this->assertFalse(
$blobStore->expandBlob( $raw, explode( ',', $flags ) )
@$blobStore->expandBlob( $raw, explode( ',', $flags ) )
);
AtEase::restoreWarnings();
}
public function provideExpandBlobWithLegacyEncoding() {

View file

@ -1524,16 +1524,12 @@ class TitleTest extends MediaWikiIntegrationTestCase {
* @covers Title::getTalkPageIfDefined
*/
public function testGetTalkPage_broken( Title $title, Title $expected, $valid ) {
$errorLevel = error_reporting( E_ERROR );
// NOTE: Eventually we want to throw in this case. But while there is still code that
// calls this method without checking, we want to avoid fatal errors.
// See discussion on T227817.
$result = $title->getTalkPage();
$result = @$title->getTalkPage();
$this->assertTrue( $expected->equals( $result ) );
$this->assertSame( $valid, $result->isValid() );
error_reporting( $errorLevel );
}
/**

View file

@ -22,7 +22,6 @@
use MediaWiki\Revision\RevisionRecord;
use Psr\Container\ContainerInterface;
use Wikimedia\AtEase\AtEase;
use Wikimedia\ObjectFactory;
/**
@ -304,17 +303,12 @@ class ApiParseTest extends ApiTestCase {
$this->db->delete( 'revision', [ 'rev_id' => $status->value['revision-record']->getId() ] );
// Suppress warning in WikiPage::getContentModel
AtEase::suppressWarnings();
try {
$this->doApiRequest( [
'action' => 'parse',
'page' => $name,
'section' => 1,
] );
} finally {
AtEase::restoreWarnings();
}
// Ignore warning from WikiPage::getContentModel
@$this->doApiRequest( [
'action' => 'parse',
'page' => $name,
'section' => 1,
] );
}
public function testNewSectionWithPage() {

View file

@ -4,7 +4,6 @@ use MediaWiki\Cache\CacheKeyHelper;
use MediaWiki\Linker\LinkTarget;
use MediaWiki\Page\PageReference;
use MediaWiki\Page\PageReferenceValue;
use Wikimedia\AtEase\AtEase;
use Wikimedia\Rdbms\ILoadBalancer;
/**
@ -183,9 +182,7 @@ class LinkBatchTest extends MediaWikiIntegrationTestCase {
$batch->add( NS_MAIN, 'X_' );
$batch->add( NS_MAIN, '' );
AtEase::suppressWarnings();
$batch->execute();
AtEase::restoreWarnings();
@$batch->execute();
$this->assertArrayHasKey( $existing1->getTitleValue()->__toString(), $good );
$this->assertArrayHasKey( $existing2->getTitleValue()->__toString(), $good );

View file

@ -8,7 +8,6 @@ use MediaWiki\Permissions\PermissionStatus;
use MediaWiki\Tests\Unit\Permissions\MockAuthorityTrait;
use MediaWiki\User\UserIdentityValue;
use PHPUnit\Framework\MockObject\MockObject;
use Wikimedia\AtEase\AtEase;
/**
* @group Database
@ -178,10 +177,7 @@ class RecentChangeTest extends MediaWikiIntegrationTestCase {
'rc_comment' => 'comment',
'rc_user_text' => $user->getName(), // lookup by name
];
AtEase::suppressWarnings();
$rc = RecentChange::newFromRow( $row );
AtEase::restoreWarnings();
$rc = @RecentChange::newFromRow( $row );
$expected = [
'rc_foo' => 'AAA',

View file

@ -23,7 +23,6 @@
* @copyright © 2013 Wikimedia Foundation Inc.
*/
use Wikimedia\AtEase\AtEase;
use Wikimedia\Rdbms\ChronologyProtector;
use Wikimedia\Rdbms\DatabaseDomain;
use Wikimedia\Rdbms\IDatabase;
@ -596,14 +595,12 @@ class LBFactoryTest extends MediaWikiIntegrationTestCase {
/** @var IDatabase $db */
$db = $lb->getConnection( DB_PRIMARY, [], $lb::DOMAIN_ANY );
AtEase::suppressWarnings();
try {
$this->assertFalse( $db->selectDomain( 'garbagedb' ) );
$this->assertFalse( @$db->selectDomain( 'garbagedb' ) );
$this->fail( "No error thrown." );
} catch ( \Wikimedia\Rdbms\DBQueryError $e ) {
$this->assertRegExp( '/[\'"]garbagedb[\'"]/', $e->getMessage() );
}
AtEase::restoreWarnings();
}
/**

View file

@ -2,7 +2,6 @@
use MediaWiki\Logger\LoggerFactory;
use MediaWiki\MediaWikiServices;
use Wikimedia\AtEase\AtEase;
use Wikimedia\TestingAccessWrapper;
/**
@ -2621,10 +2620,7 @@ class FileBackendIntegrationTest extends MediaWikiIntegrationTestCase {
]
];
AtEase::suppressWarnings();
$actual = $be->sanitizeOpHeaders( $input );
AtEase::restoreWarnings();
$actual = @$be->sanitizeOpHeaders( $input );
$this->assertEquals( $expected, $actual, "Header sanitized properly" );
}

View file

@ -6,7 +6,6 @@ use BadMethodCallException;
use MediaWikiIntegrationTestCase;
use Psr\Log\LogLevel;
use UnexpectedValueException;
use Wikimedia\AtEase\AtEase;
use Wikimedia\TestingAccessWrapper;
/**
@ -131,9 +130,7 @@ class PHPSessionHandlerTest extends MediaWikiIntegrationTestCase {
);
$wrap->setEnableFlags( 'warn' );
AtEase::suppressWarnings();
ini_set( 'session.serialize_handler', $handler );
AtEase::restoreWarnings();
@ini_set( 'session.serialize_handler', $handler );
if ( ini_get( 'session.serialize_handler' ) !== $handler ) {
$this->markTestSkipped( "Cannot set session.serialize_handler to \"$handler\"" );
}

View file

@ -6,7 +6,6 @@ use Config;
use MediaWiki\HookContainer\HookContainer;
use MediaWikiIntegrationTestCase;
use User;
use Wikimedia\AtEase\AtEase;
use Wikimedia\TestingAccessWrapper;
/**
@ -913,7 +912,7 @@ class SessionBackendTest extends MediaWikiIntegrationTestCase {
$manager->globalSessionRequest = $request;
session_id( self::SESSIONID );
AtEase::quietCall( 'session_start' );
@session_start();
$_SESSION['foo'] = __METHOD__;
$backend->resetId();
$this->assertNotEquals( self::SESSIONID, $backend->getId() );
@ -951,7 +950,7 @@ class SessionBackendTest extends MediaWikiIntegrationTestCase {
$manager->globalSessionRequest = $request;
session_id( self::SESSIONID . 'x' );
AtEase::quietCall( 'session_start' );
@session_start();
$backend->unpersist();
$this->assertSame( self::SESSIONID . 'x', session_id() );
session_write_close();

View file

@ -5,7 +5,6 @@ namespace MediaWiki\Session;
use MediaWikiIntegrationTestCase;
use Psr\Log\LogLevel;
use User;
use Wikimedia\AtEase\AtEase;
use Wikimedia\TestingAccessWrapper;
/**
@ -98,9 +97,7 @@ class SessionTest extends MediaWikiIntegrationTestCase {
$hmac = hash_hmac( 'sha256', $sealed, $hmacKey, true );
$encrypted = base64_encode( $hmac ) . '.' . $sealed;
$session->set( 'test', $encrypted );
AtEase::suppressWarnings();
$this->assertEquals( 'defaulted', $session->getSecret( 'test', 'defaulted' ) );
AtEase::restoreWarnings();
$this->assertEquals( 'defaulted', @$session->getSecret( 'test', 'defaulted' ) );
}
/**

View file

@ -9,7 +9,6 @@ use MediaWikiIntegrationTestCase;
use MWException;
use PHPUnit\Framework\ExpectationFailedException;
use Title;
use Wikimedia\AtEase\AtEase;
use WikiPage;
/**
@ -240,15 +239,11 @@ class FetchTextTest extends MediaWikiIntegrationTestCase {
}
public function testNonExisting() {
AtEase::suppressWarnings();
$this->assertFilter( 'tt:77889911', 'tt:77889911' . "\n-1\n" );
AtEase::suppressWarnings( true );
@$this->assertFilter( 'tt:77889911', 'tt:77889911' . "\n-1\n" );
}
public function testNonExistingInteger() {
AtEase::suppressWarnings();
$this->assertFilter( '77889911', 'tt:77889911' . "\n-1\n" );
AtEase::suppressWarnings( true );
@$this->assertFilter( '77889911', 'tt:77889911' . "\n-1\n" );
}
public function testBadBlobAddressWithColon() {
@ -267,10 +262,8 @@ class FetchTextTest extends MediaWikiIntegrationTestCase {
}
public function testFloatingPointNumberNonExisting() {
AtEase::suppressWarnings();
$id = intval( preg_replace( '/^tt:/', '', self::$textId5 ) ) + 3.14159;
$this->assertFilter( $id, 'tt:' . intval( $id ) . "\n-1\n" );
AtEase::suppressWarnings( true );
@$this->assertFilter( $id, 'tt:' . intval( $id ) . "\n-1\n" );
}
public function testCharacters() {

View file

@ -7,7 +7,6 @@
*/
use MediaWiki\MediaWikiServices;
use Wikimedia\AtEase\AtEase;
class PHPUnitMaintClass {
public function setup() {
@ -105,9 +104,7 @@ class PHPUnitMaintClass {
$wgShowExceptionDetails = true;
$wgShowHostnames = true;
AtEase::suppressWarnings();
set_time_limit( 0 );
AtEase::restoreWarnings();
@set_time_limit( 0 );
ini_set( 'memory_limit', -1 );

View file

@ -4,7 +4,6 @@ use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Stmt;
use PhpParser\ParserFactory;
use Wikimedia\AtEase\AtEase;
class AutoLoaderStructureTest extends MediaWikiIntegrationTestCase {
/**
@ -107,10 +106,7 @@ class AutoLoaderStructureTest extends MediaWikiIntegrationTestCase {
continue;
}
AtEase::suppressWarnings();
$contents = file_get_contents( $filePath );
AtEase::restoreWarnings();
$contents = @file_get_contents( $filePath );
if ( $contents === false ) {
$actual[$class] = "[couldn't read file '$filePath']";
continue;

View file

@ -14,7 +14,6 @@ use MediaWikiUnitTestCase;
use Title;
use TitleFactory;
use Wikimedia\Assert\PostconditionException;
use Wikimedia\AtEase\AtEase;
/**
* @covers \MediaWiki\Revision\SlotRoleRegistry
@ -134,11 +133,8 @@ class SlotRoleRegistryTest extends MediaWikiUnitTestCase {
$this->makeNameTableStore( [ 1 => 'foo' ] )
);
AtEase::suppressWarnings();
$handler = $registry->getRoleHandler( 'foo' );
$handler = @$registry->getRoleHandler( 'foo' );
$this->assertSame( 'foo', $handler->getRole() );
AtEase::restoreWarnings();
}
/**

View file

@ -15,13 +15,13 @@ class LCStoreStaticArrayTest extends MediaWikiUnitTestCase {
}
protected function tearDown(): void {
Wikimedia\AtEase\AtEase::quietCall( 'unlink', $this->file );
Wikimedia\AtEase\AtEase::quietCall( 'rmdir', $this->dir );
@unlink( $this->file );
@rmdir( $this->dir );
parent::tearDown();
}
private function prepareDir() {
Wikimedia\AtEase\AtEase::quietCall( 'mkdir', $this->dir );
@mkdir( $this->dir );
return $this->dir;
}

View file

@ -6,7 +6,6 @@ require_once __DIR__ . '/UploadedFileTestBase.php';
use RuntimeException;
use TypeError;
use Wikimedia\AtEase\AtEase;
use Wikimedia\TestingAccessWrapper;
/**
@ -45,7 +44,7 @@ class UploadedFileStreamTest extends UploadedFileTestBase {
unset( $stream );
try {
// PHP 7 raises warnings
$this->assertFalse( AtEase::quietCall( 'fread', $fp, 1 ) );
$this->assertFalse( @fread( $fp, 1 ) );
} catch ( TypeError $ex ) {
// PHP 8 throws
}

View file

@ -4,7 +4,6 @@ namespace Wikimedia\ParamValidator\Util;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use Wikimedia\AtEase\AtEase;
abstract class UploadedFileTestBase extends \PHPUnit\Framework\TestCase {
@ -20,7 +19,7 @@ abstract class UploadedFileTestBase extends \PHPUnit\Framework\TestCase {
'phpunit-ParamValidator-UploadedFileTest-' . time() . '-' . getmypid() . '-';
for ( $i = 0; $i < 10000; $i++ ) {
$dir = $base . sprintf( '%04d', $i );
if ( AtEase::quietCall( 'mkdir', $dir, 0700, false ) === true ) {
if ( @mkdir( $dir, 0700, false ) === true ) {
self::$tmpdir = $dir;
break;
}

View file

@ -1,7 +1,5 @@
<?php
use Wikimedia\AtEase\AtEase;
/**
* Code shared between the unit and integration tests
*/
@ -49,8 +47,6 @@ trait TempFSFileTestTrait {
$file->preserve();
unset( $file );
$this->assertTrue( is_file( $path ) );
AtEase::suppressWarnings();
unlink( $path );
AtEase::restoreWarnings();
@unlink( $path );
}
}