mirror of
https://github.com/phpbb/phpbb.git
synced 2025-08-07 01:06:48 +02:00
[ticket/16549] Avoid deprecated properties/methods in newer PHPUnit versions
PHPBB3-16549
This commit is contained in:
@@ -29,21 +29,35 @@ abstract class phpbb_database_test_case extends TestCase
|
||||
|
||||
static protected $install_schema_file;
|
||||
|
||||
public function __construct($name = NULL, array $data = array(), $dataName = '')
|
||||
static protected $phpunit_version;
|
||||
|
||||
public function __construct($name = NULL, array $data = [], $dataName = '')
|
||||
{
|
||||
parent::__construct($name, $data, $dataName);
|
||||
$this->backupStaticAttributesBlacklist += array(
|
||||
'SebastianBergmann\CodeCoverage\CodeCoverage' => array('instance'),
|
||||
'SebastianBergmann\CodeCoverage\Filter' => array('instance'),
|
||||
'SebastianBergmann\CodeCoverage\Util' => array('ignoredLines', 'templateMethods'),
|
||||
'SebastianBergmann\Timer\Timer' => array('startTimes',),
|
||||
'PHP_Token_Stream' => array('customTokens'),
|
||||
'PHP_Token_Stream_CachingFactory' => array('cache'),
|
||||
|
||||
'phpbb_database_test_case' => array('already_connected'),
|
||||
);
|
||||
self::$phpunit_version = PHPUnit\Runner\Version::id();
|
||||
|
||||
$this->db_connections = array();
|
||||
$backupStaticAttributesBlacklist = [
|
||||
'SebastianBergmann\CodeCoverage\CodeCoverage' => ['instance'],
|
||||
'SebastianBergmann\CodeCoverage\Filter' => ['instance'],
|
||||
'SebastianBergmann\CodeCoverage\Util' => ['ignoredLines', 'templateMethods'],
|
||||
'SebastianBergmann\Timer\Timer' => ['startTimes'],
|
||||
'PHP_Token_Stream' => ['customTokens'],
|
||||
'PHP_Token_Stream_CachingFactory' => ['cache'],
|
||||
|
||||
'phpbb_database_test_case' => ['already_connected'],
|
||||
];
|
||||
|
||||
if (version_compare(self::$phpunit_version, '9.0', '>='))
|
||||
{
|
||||
$this->backupStaticAttributesExcludeList += $backupStaticAttributesBlacklist;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->backupStaticAttributesBlacklist += $backupStaticAttributesBlacklist;
|
||||
}
|
||||
|
||||
$this->db_connections = [];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -353,4 +367,56 @@ abstract class phpbb_database_test_case extends TestCase
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* PHPUnit deprecates several methods and properties in its recent versions
|
||||
* Provide BC layer to be able to test in multiple environment settings
|
||||
*/
|
||||
public function expectException(string $exception): void
|
||||
{
|
||||
if (version_compare(self::$phpunit_version, '9.0', '>='))
|
||||
{
|
||||
switch ($exception) {
|
||||
case PHPUnit\Framework\Error\Deprecated::class:
|
||||
parent::expectDeprecation();
|
||||
break;
|
||||
|
||||
case PHPUnit\Framework\Error\Error::class:
|
||||
parent::expectError();
|
||||
break;
|
||||
|
||||
case PHPUnit\Framework\Error\Notice::class:
|
||||
parent::expectNotice();
|
||||
break;
|
||||
|
||||
case PHPUnit\Framework\Error\Warning::class:
|
||||
parent::expectWarning();
|
||||
break;
|
||||
|
||||
default:
|
||||
parent::expectException($exception);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
parent::expectException($exception);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* PHPUnit deprecates several methods and properties in its recent versions
|
||||
* Provide BC layer to be able to test in multiple environment settings
|
||||
*/
|
||||
public static function assertFileNotExists(string $filename, string $message = ''): void
|
||||
{
|
||||
if (version_compare(self::$phpunit_version, '9.0', '>='))
|
||||
{
|
||||
parent::assertFileDoesNotExist($filename, $message);
|
||||
}
|
||||
else
|
||||
{
|
||||
parent::assertFileNotExists($filename, $message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user