wiki.techinc.nl/tests/phpunit/PHPUnit6And8Compat.php
Max Semenik 830548509d Add PHPUnit6And8Compat trait
This is moved out of the main PHPUnit upgrade commit to allow
extensions to silence their warnings beforehand, to avoid breaking
their tests.

Bug: T192167
Change-Id: I60379a933a3a1b018d9f5ef6b51019002389dda3
2019-11-19 00:48:57 -08:00

58 lines
1.6 KiB
PHP

<?php
/**
* Copyright (C) 2019 MediaWiki contributors
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
/**
* Temporary trait to allow migration between PHPUnit versions without breaking tests
*
* @since 1.35
*/
trait PHPUnit6And8Compat {
private static function getAllowedWarningsRegex() {
static $cache = null;
if ( !$cache ) {
$regexes = [
'assertArraySubset\(\)',
'assert(Not)?InternalType\(\)',
'parameter of assertEquals\(\)',
'Using assert(Not)?Contains\(\) with string haystacks',
'(read|getObject)Attribute\(\)',
'parameter of assertEquals\(\)',
];
$cache = '/(' . implode( '|', $regexes ) . ') is deprecated/';
}
return $cache;
}
/**
* Override to silence some deprecation warnings
*
* @param string $warning
*/
public function addWarning( string $warning ) : void {
if ( preg_match( self::getAllowedWarningsRegex(), $warning ) ) {
return;
}
parent::addWarning( $warning );
}
}