Debian Codegraph @

includes/composer/PhpUnitSplitter/PhpUnitTestFileScanner.php

raw symbols SCIP
1 <?php
2
3 declare( strict_types = 1 );
4
5 namespace MediaWiki\Composer\PhpUnitSplitter;
6
7 use RecursiveDirectoryIterator;
8 use RecursiveIteratorIterator;
9
10 /**
11 * @license GPL-2.0-or-later
12 */
13 class PhpUnitTestFileScanner {
14
15 private string $rootDir;
16
17 public function __construct( string $rootDir ) {
18 $this->rootDir = $rootDir;
19 }
20
21 /**
22 * @return array Returns an list of `.php` files found on the filesystem
23 * inside `$rootDir`. The array maps file basenames (i.e.
24 * `MyClassTest.php`) to lists of paths where that basename
25 * is found (e.g. `[ 'tests/phpunit/MyClassTest.php',
26 * 'extensions/MyExtension/tests/phpunit/MyClassTest.php' ]`)
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 }