4 use Symfony\Component\Finder\Finder
;
7 * Search for PHPUnit test cases
11 * @return array<string> class names
13 public static function _findTestClasses($path) {
15 // 'loading' => $path,
16 // get_included_files()
19 $origClasses = get_declared_classes();
21 $newClasses = get_declared_classes();
23 return preg_grep('/Test$/', array_diff(
31 * (string $file => string $class)
33 public static function findTestClasses($paths) {
34 $testClasses = array();
35 $finder = new Finder();
37 foreach ($paths as $path) {
39 foreach ($finder->files()->in($paths)->name('*Test.php') as $file) {
40 $testClass = self
::_findTestClasses((string) $file);
41 if (count($testClass) == 1) {
42 $testClasses[(string) $file] = array_shift($testClass);
44 elseif (count($testClass) > 1) {
45 throw new \
Exception("Too many classes in $file");
48 throw new \
Exception("Too few classes in $file");
52 elseif (is_file($path)) {
53 $testClass = self
::_findTestClasses($path);
54 if (count($testClass) == 1) {
55 $testClasses[$path] = array_shift($testClass);
57 elseif (count($testClass) > 1) {
58 throw new \
Exception("Too many classes in $path");
61 throw new \
Exception("Too few classes in $path");
73 * each element is an array with keys:
78 public static function findTestsByPath($paths) {
80 $testClasses = self
::findTestClasses($paths);
81 foreach ($testClasses as $testFile => $testClass) {
82 $clazz = new \
ReflectionClass($testClass);
83 foreach ($clazz->getMethods() as $method) {
84 if (preg_match('/^test/', $method->name
)) {
87 'class' => $testClass,
88 'method' => $method->name