File: make_compatible_with_phpunit12.php

package info (click to toggle)
php-phpseclib3 3.0.46-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 5,528 kB
  • sloc: php: 30,756; xml: 392; makefile: 21
file content (27 lines) | stat: -rw-r--r-- 1,245 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?php

/** @var iterable<SplFileInfo> $files */
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(__DIR__));
foreach ($files as $file) {
    if ($file->getExtension() === 'php' && $file->getPathname() !== __FILE__) {
        $fileContents = file_get_contents($file->getPathname());
        if ($fileContents === false) {
            throw new RuntimeException('file_get_contents() failed: ' . $file->getPathname());
        }
        $patternToReplacementMap = [
            '~ /\*\* @dataProvider ([a-zA-Z0-9]+) \*/~' => ' #[\PHPUnit\Framework\Attributes\DataProvider("$1")]',
            '~ /\*\* @depends ([a-zA-Z0-9m]+) \*/~' => ' #[\PHPUnit\Framework\Attributes\Depends("$1")]',
            //'~ ->setMethods\(\[~' => ' ->onlyMethods([',
        ];
        $updatedFileContents = preg_replace(
            array_keys($patternToReplacementMap),
            array_values($patternToReplacementMap),
            $fileContents
        );
        if (file_put_contents($file->getPathname(), $updatedFileContents) === false) {
            throw new RuntimeException('file_put_contents() failed: ' . $file->getPathname());
        }
    }
}
unlink('tests/Functional/Net/SSH2Test.php');
unlink('tests/Unit/Net/SSH2UnitTest.php');