[ticket/17176] Remove no longer needed backward compatible phpunit code

PHPBB3-17176
This commit is contained in:
Marc Alexander 2023-09-07 20:49:59 +02:00
parent 5d6218dcba
commit 4078ed7e20
No known key found for this signature in database
GPG key ID: 50E0D2423696F995
15 changed files with 27 additions and 181 deletions

View file

@ -38,6 +38,6 @@ class phpbb_functional_acp_smilies_test extends phpbb_functional_test_case
$crawler = self::submit($form); $crawler = self::submit($form);
$html = $crawler->filter('#preview')->html(); $html = $crawler->filter('#preview')->html();
$this->assertRegexp('(<img [^>]+ alt=">:D" title=">:D"[^>]*>)', $html); $this->assertMatchesRegularExpression('(<img [^>]+ alt=">:D" title=">:D"[^>]*>)', $html);
} }
} }

View file

@ -30,9 +30,9 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case
{ {
parent::__construct($name, $data, $dataName); parent::__construct($name, $data, $dataName);
$this->excludeBackupStaticAttributes([ $this->backupStaticAttributesExcludeList += [
'phpbb_functional_feed_test' => ['init_values'], 'phpbb_functional_feed_test' => ['init_values'],
]); ];
$this->purge_cache(); $this->purge_cache();
} }

View file

@ -78,7 +78,7 @@ class phpbb_functional_posting_test extends phpbb_functional_test_case
$crawler = self::request('GET', "posting.php?mode=quote&p={$post['post_id']}&sid={$this->sid}"); $crawler = self::request('GET', "posting.php?mode=quote&p={$post['post_id']}&sid={$this->sid}");
$this->assertRegexp($expected, $crawler->filter('textarea#message')->text()); $this->assertMatchesRegularExpression($expected, $crawler->filter('textarea#message')->text());
} }
/** /**
@ -122,7 +122,7 @@ class phpbb_functional_posting_test extends phpbb_functional_test_case
{ {
$this->set_quote_depth($quote_depth); $this->set_quote_depth($quote_depth);
$crawler = self::request('GET', $quote_url); $crawler = self::request('GET', $quote_url);
$this->assertRegexp( $this->assertMatchesRegularExpression(
"(\[quote=admin[^\]]*\]\s?" . preg_quote($expected_text) . "\s?\[\/quote\])", "(\[quote=admin[^\]]*\]\s?" . preg_quote($expected_text) . "\s?\[\/quote\])",
$crawler->filter('textarea#message')->text() $crawler->filter('textarea#message')->text()
); );

View file

@ -79,7 +79,7 @@ class phpbb_functional_private_messages_test extends phpbb_functional_test_case
$crawler = self::request('GET', 'ucp.php?i=pm&mode=compose&action=quotepost&p=' . $post['post_id'] . '&sid=' . $this->sid); $crawler = self::request('GET', 'ucp.php?i=pm&mode=compose&action=quotepost&p=' . $post['post_id'] . '&sid=' . $this->sid);
$this->assertRegexp($expected, $crawler->filter('textarea#message')->text()); $this->assertMatchesRegularExpression($expected, $crawler->filter('textarea#message')->text());
} }
public function test_quote_pm() public function test_quote_pm()
@ -92,7 +92,7 @@ class phpbb_functional_private_messages_test extends phpbb_functional_test_case
$crawler = self::request('GET', 'ucp.php?i=pm&mode=compose&action=quote&p=' . $message_id . '&sid=' . $this->sid); $crawler = self::request('GET', 'ucp.php?i=pm&mode=compose&action=quote&p=' . $message_id . '&sid=' . $this->sid);
$this->assertRegexp($expected, $crawler->filter('textarea#message')->text()); $this->assertMatchesRegularExpression($expected, $crawler->filter('textarea#message')->text());
} }
public function test_quote_forward() public function test_quote_forward()
@ -105,6 +105,6 @@ class phpbb_functional_private_messages_test extends phpbb_functional_test_case
$crawler = self::request('GET', 'ucp.php?i=pm&mode=compose&action=forward&f=0&p=' . $message_id . '&sid=' . $this->sid); $crawler = self::request('GET', 'ucp.php?i=pm&mode=compose&action=forward&f=0&p=' . $message_id . '&sid=' . $this->sid);
$this->assertRegexp($expected, $crawler->filter('textarea#message')->text()); $this->assertMatchesRegularExpression($expected, $crawler->filter('textarea#message')->text());
} }
} }

View file

@ -22,9 +22,9 @@ class phpbb_functional_ucp_allow_pm_test extends phpbb_functional_test_case
{ {
parent::__construct(); parent::__construct();
$this->excludeBackupStaticAttributes([ $this->backupStaticAttributesExcludeList += [
'phpbb_functional_ucp_allow_pm_test' => ['data'], 'phpbb_functional_ucp_allow_pm_test' => ['data'],
]); ];
} }
// user A sends a PM to user B where B accepts PM // user A sends a PM to user B where B accepts PM

View file

@ -44,7 +44,7 @@ class phpbb_random_gen_rand_string_test extends phpbb_test_case
$random_string_length == $num_chars, $random_string_length == $num_chars,
sprintf('Failed asserting that random string length matches expected length. Expected %1$u, Actual %2$u', $num_chars, $random_string_length) sprintf('Failed asserting that random string length matches expected length. Expected %1$u, Actual %2$u', $num_chars, $random_string_length)
); );
$this->assertRegExp('#^[A-Z0-9]+$#', $random_string); $this->assertMatchesRegularExpression('#^[A-Z0-9]+$#', $random_string);
} }
} }
} }
@ -63,7 +63,7 @@ class phpbb_random_gen_rand_string_test extends phpbb_test_case
$random_string_length == $num_chars, $random_string_length == $num_chars,
sprintf('Failed asserting that random string length matches expected length. Expected %1$u, Actual %2$u', $num_chars, $random_string_length) sprintf('Failed asserting that random string length matches expected length. Expected %1$u, Actual %2$u', $num_chars, $random_string_length)
); );
$this->assertRegExp('#^[A-NP-Z1-9]+$#', $random_string); $this->assertMatchesRegularExpression('#^[A-NP-Z1-9]+$#', $random_string);
} }
} }
} }

View file

@ -37,6 +37,6 @@ class phpbb_regex_censor_test extends phpbb_test_case
{ {
$regex = get_censor_preg_expression($pattern); $regex = get_censor_preg_expression($pattern);
$this->assertRegExp($regex, $subject); $this->assertMatchesRegularExpression($regex, $subject);
} }
} }

View file

@ -88,8 +88,8 @@ class phpbb_storage_adapter_local_subfolders_test extends phpbb_local_test_case
$this->adapter->delete('file.txt'); $this->adapter->delete('file.txt');
// Then // Then
$this->assertFileNotExists($this->path . '3d/8e/file.txt'); $this->assertFileDoesNotExist($this->path . '3d/8e/file.txt');
$this->assertFileNotExists($this->path . '3d'); $this->assertFileDoesNotExist($this->path . '3d');
} }
public function test_rename(): void public function test_rename(): void
@ -102,9 +102,9 @@ class phpbb_storage_adapter_local_subfolders_test extends phpbb_local_test_case
$this->adapter->rename('file.txt', 'file2.txt'); $this->adapter->rename('file.txt', 'file2.txt');
// Then // Then
$this->assertFileNotExists($this->path . '3d/8e/file.txt'); $this->assertFileDoesNotExist($this->path . '3d/8e/file.txt');
$this->assertFileExists($this->path . '27/36/file2.txt'); $this->assertFileExists($this->path . '27/36/file2.txt');
$this->assertFileNotExists($this->path . '3d'); $this->assertFileDoesNotExist($this->path . '3d');
// Clean test // Clean test
unlink($this->path . '27/36/file2.txt'); unlink($this->path . '27/36/file2.txt');

View file

@ -77,7 +77,7 @@ class phpbb_storage_adapter_local_test extends phpbb_local_test_case
$this->adapter->delete('file.txt'); $this->adapter->delete('file.txt');
// Then // Then
$this->assertFileNotExists($this->path . 'file.txt'); $this->assertFileDoesNotExist($this->path . 'file.txt');
} }
public function test_rename(): void public function test_rename(): void
@ -85,13 +85,13 @@ class phpbb_storage_adapter_local_test extends phpbb_local_test_case
// Given // Given
touch($this->path . 'file.txt'); touch($this->path . 'file.txt');
$this->assertFileExists($this->path . 'file.txt'); $this->assertFileExists($this->path . 'file.txt');
$this->assertFileNotExists($this->path . 'file2.txt'); $this->assertFileDoesNotExist($this->path . 'file2.txt');
// When // When
$this->adapter->rename('file.txt', 'file2.txt'); $this->adapter->rename('file.txt', 'file2.txt');
// Then // Then
$this->assertFileNotExists($this->path . 'file.txt'); $this->assertFileDoesNotExist($this->path . 'file.txt');
$this->assertFileExists($this->path . 'file2.txt'); $this->assertFileExists($this->path . 'file2.txt');
// Clean test // Clean test

View file

@ -528,7 +528,7 @@ class phpbb_template_template_test extends phpbb_template_template_test_case
$filename = 'file_not_found.html'; $filename = 'file_not_found.html';
$this->template->set_filenames(array('test' => $filename)); $this->template->set_filenames(array('test' => $filename));
$this->assertFileNotExists($this->template_path . '/' . $filename, 'Testing missing file, file cannot exist'); $this->assertFileDoesNotExist($this->template_path . '/' . $filename, 'Testing missing file, file cannot exist');
$this->expectException(\Twig\Error\LoaderError::class); $this->expectException(\Twig\Error\LoaderError::class);

View file

@ -29,8 +29,6 @@ abstract class phpbb_database_test_case extends TestCase
protected static $install_schema_file; protected static $install_schema_file;
protected static $phpunit_version;
/** /**
* @var \Doctrine\DBAL\Connection[] * @var \Doctrine\DBAL\Connection[]
*/ */
@ -40,9 +38,7 @@ abstract class phpbb_database_test_case extends TestCase
{ {
parent::__construct($name, $data, $dataName); parent::__construct($name, $data, $dataName);
self::$phpunit_version = PHPUnit\Runner\Version::id(); $this->backupStaticAttributesExcludeList += [
$backupStaticAttributesBlacklist = [
'SebastianBergmann\CodeCoverage\CodeCoverage' => ['instance'], 'SebastianBergmann\CodeCoverage\CodeCoverage' => ['instance'],
'SebastianBergmann\CodeCoverage\Filter' => ['instance'], 'SebastianBergmann\CodeCoverage\Filter' => ['instance'],
'SebastianBergmann\CodeCoverage\Util' => ['ignoredLines', 'templateMethods'], 'SebastianBergmann\CodeCoverage\Util' => ['ignoredLines', 'templateMethods'],
@ -53,15 +49,6 @@ abstract class phpbb_database_test_case extends TestCase
'phpbb_database_test_case' => ['already_connected'], 'phpbb_database_test_case' => ['already_connected'],
]; ];
if (version_compare(self::$phpunit_version, '9.0', '>='))
{
$this->backupStaticAttributesExcludeList += $backupStaticAttributesBlacklist;
}
else
{
$this->backupStaticAttributesBlacklist += $backupStaticAttributesBlacklist;
}
$this->db_connections = []; $this->db_connections = [];
$this->db_connections_doctrine = []; $this->db_connections_doctrine = [];
} }
@ -411,56 +398,4 @@ abstract class phpbb_database_test_case extends TestCase
return $core_tables; return $core_tables;
} }
/**
* 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);
}
}
} }

View file

@ -208,10 +208,9 @@ class phpbb_functional_test_case extends phpbb_test_case
{ {
parent::__construct($name, $data, $dataName); parent::__construct($name, $data, $dataName);
$backupStaticAttributesBlacklist = [ $this->backupStaticAttributesExcludeList += [
'phpbb_functional_test_case' => ['config', 'already_installed'], 'phpbb_functional_test_case' => ['config', 'already_installed'],
]; ];
$this->excludeBackupStaticAttributes($backupStaticAttributesBlacklist);
} }
protected function get_db() protected function get_db()

View file

@ -16,15 +16,12 @@ use PHPUnit\Framework\TestCase;
class phpbb_test_case extends TestCase class phpbb_test_case extends TestCase
{ {
protected $test_case_helpers; protected $test_case_helpers;
protected static $phpunit_version;
public function __construct($name = NULL, array $data = array(), $dataName = '') public function __construct($name = NULL, array $data = array(), $dataName = '')
{ {
parent::__construct($name, $data, $dataName); parent::__construct($name, $data, $dataName);
self::$phpunit_version = PHPUnit\Runner\Version::id(); $this->backupStaticAttributesExcludeList += [
$backupStaticAttributesBlacklist = [
'SebastianBergmann\CodeCoverage\CodeCoverage' => ['instance'], 'SebastianBergmann\CodeCoverage\CodeCoverage' => ['instance'],
'SebastianBergmann\CodeCoverage\Filter' => ['instance'], 'SebastianBergmann\CodeCoverage\Filter' => ['instance'],
'SebastianBergmann\CodeCoverage\Util' => ['ignoredLines', 'templateMethods'], 'SebastianBergmann\CodeCoverage\Util' => ['ignoredLines', 'templateMethods'],
@ -34,7 +31,6 @@ class phpbb_test_case extends TestCase
'phpbb_database_test_case' => ['already_connected', 'last_post_timestamp'], 'phpbb_database_test_case' => ['already_connected', 'last_post_timestamp'],
]; ];
$this->excludeBackupStaticAttributes($backupStaticAttributesBlacklist);
} }
public function get_test_case_helpers() public function get_test_case_helpers()
@ -51,88 +47,4 @@ class phpbb_test_case extends TestCase
{ {
$this->get_test_case_helpers()->setExpectedTriggerError($errno, $message); $this->get_test_case_helpers()->setExpectedTriggerError($errno, $message);
} }
/**
* PHPUnit deprecates several methods and properties in its recent versions
* Provide BC layer to be able to test in multiple environment settings
*/
public function excludeBackupStaticAttributes($attributes_array)
{
if (version_compare(self::$phpunit_version, '9.0', '>='))
{
$this->backupStaticAttributesExcludeList += $attributes_array;
}
else
{
$this->backupStaticAttributesBlacklist += $attributes_array;
}
}
/**
* 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 assertRegExp(string $pattern, string $string, string $message = ''): void
{
if (version_compare(self::$phpunit_version, '9.0', '>='))
{
parent::assertMatchesRegularExpression($pattern, $string, $message);
}
else
{
parent::assertRegExp($pattern, $string, $message);
}
}
/**
* 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);
}
}
} }

View file

@ -156,7 +156,7 @@ class phpbb_textformatter_s9e_factory_test extends phpbb_database_test_case
$factory->tidy(); $factory->tidy();
$this->assertFileExists($new_file, 'The current renderer has been deleted'); $this->assertFileExists($new_file, 'The current renderer has been deleted');
$this->assertFileNotExists($old_file, 'The old renderer has not been deleted'); $this->assertFileDoesNotExist($old_file, 'The old renderer has not been deleted');
unlink($new_file); unlink($new_file);
} }

View file

@ -230,7 +230,7 @@ class phpbb_filespec_test extends phpbb_test_case
$name = $filespec->get('realname'); $name = $filespec->get('realname');
$this->assertEquals(strlen($name), 32 + strlen(self::PREFIX)); $this->assertEquals(strlen($name), 32 + strlen(self::PREFIX));
$this->assertRegExp('#^[A-Za-z0-9]+$#', substr($name, strlen(self::PREFIX))); $this->assertMatchesRegularExpression('#^[A-Za-z0-9]+$#', substr($name, strlen(self::PREFIX)));
$this->assertFalse(isset($filenames[$name])); $this->assertFalse(isset($filenames[$name]));
$filenames[$name] = true; $filenames[$name] = true;
} }
@ -246,7 +246,7 @@ class phpbb_filespec_test extends phpbb_test_case
$name = $filespec->get('realname'); $name = $filespec->get('realname');
$this->assertEquals(strlen($name), 32 + strlen(self::PREFIX) + strlen('.jpg')); $this->assertEquals(strlen($name), 32 + strlen(self::PREFIX) + strlen('.jpg'));
$this->assertRegExp('#^[A-Za-z0-9]+\.jpg$#', substr($name, strlen(self::PREFIX))); $this->assertMatchesRegularExpression('#^[A-Za-z0-9]+\.jpg$#', substr($name, strlen(self::PREFIX)));
$this->assertFalse(isset($filenames[$name])); $this->assertFalse(isset($filenames[$name]));
$filenames[$name] = true; $filenames[$name] = true;
} }