| 1 |
<?php |
| 2 |
|
| 3 |
declare( strict_types = 1 ); |
| 4 |
|
| 5 |
namespace MediaWiki\Composer\PhpUnitSplitter; |
| 6 |
|
| 7 |
use RecursiveDirectoryIterator; |
| 8 |
use RecursiveIteratorIterator; |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
class PhpUnitTestFileScanner { |
| 14 |
|
| 15 |
private string $rootDir; |
| 16 |
|
| 17 |
public function __construct( string $rootDir ) { |
| 18 |
$this->rootDir = $rootDir; |
| 19 |
} |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
public function scanForFiles(): array { |
| 29 |
$phpFiles = []; |
| 30 |
$iterator = new RecursiveIteratorIterator( |
| 31 |
new PhpUnitTestFileScannerFilter( |
| 32 |
new RecursiveDirectoryIterator( $this->rootDir ) |
| 33 |
) |
| 34 |
); |
| 35 |
foreach ( $iterator as $file ) { |
| 36 |
if ( $file->isFile() && $file->getExtension() === 'php' ) { |
| 37 |
$filename = $file->getFilename(); |
| 38 |
if ( !array_key_exists( $filename, $phpFiles ) ) { |
| 39 |
$phpFiles[$filename] = []; |
| 40 |
} |
| 41 |
$phpFiles[$filename][] = $file->getPathname(); |
| 42 |
} |
| 43 |
} |
| 44 |
return $phpFiles; |
| 45 |
} |
| 46 |
} |