phpseclib/tests/make_compatible_with_phpunit7.php

32 lines
2.0 KiB
PHP
Raw Normal View History

2022-02-27 22:35:58 +00:00
<?php
/** @var iterable<SplFileInfo> $files */
2024-08-03 16:11:29 +00:00
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(__DIR__));
2022-02-27 22:35:58 +00:00
foreach ($files as $file) {
if ($file->getExtension() === 'php' && $file->getPathname() !== __FILE__) {
$fileContents = file_get_contents($file->getPathname());
if ($fileContents === false) {
2024-08-03 16:11:29 +00:00
throw new RuntimeException('file_get_contents() failed: ' . $file->getPathname());
2022-02-27 22:35:58 +00:00
}
$patternToReplacementMap = [
'~ function setUpBeforeClass\(\)~' => ' function setUpBeforeClass(): void',
'~ function setUp\(\)~' => ' function setUp(): void',
'~ function tearDown\(\)~' => ' function tearDown(): void',
2023-02-05 23:33:16 +00:00
'~ function assertIsArray\(\$actual, \$message = \'\'\)~' => ' function _assertIsArray($actual, string $message = \'\')',
'~ function assertIsResource\(\$actual, \$message = \'\'\)~' => ' function _assertIsResource($actual, string $message = \'\')',
'~ function assertIsObject\(\$actual, \$message = \'\'\)~' => ' function _assertIsObject($actual, string $message = \'\')',
'~ function assertIsString\(\$actual, \$message = \'\'\)~' => ' function _assertIsString($actual, string $message = \'\')',
'~ function assertStringContainsString\(\$needle, \$haystack, \$message = \'\'\)~' => ' function _assertStringContainsString(string $needle, string $haystack, string $message = \'\')',
'~ function assertStringNotContainsString\(\$needle, \$haystack, \$message = \'\'\)~' => ' function _assertStringNotContainsString(string $needle, string $haystack, string $message = \'\')'
2022-02-27 22:35:58 +00:00
];
$updatedFileContents = preg_replace(
array_keys($patternToReplacementMap),
array_values($patternToReplacementMap),
$fileContents
);
if (file_put_contents($file->getPathname(), $updatedFileContents) === false) {
2024-08-03 16:11:29 +00:00
throw new RuntimeException('file_put_contents() failed: ' . $file->getPathname());
2022-02-27 22:35:58 +00:00
}
}
}