4 use Symfony\Component\Finder\Finder
;
7 * Search for PHPUnit test cases
13 * @return array <string> class names
15 public static function _findTestClasses($path) {
17 // 'loading' => $path,
18 // get_included_files()
20 $origClasses = get_declared_classes();
22 $newClasses = get_declared_classes();
24 return preg_grep('/Test$/', array_diff(
32 * @return array (string $file => string $class)
35 public static function findTestClasses($paths) {
37 $finder = new Finder();
39 foreach ($paths as $path) {
41 foreach ($finder->files()->in($paths)->name('*Test.php') as $file) {
42 $testClass = self
::_findTestClasses((string) $file);
43 if (count($testClass) == 1) {
44 $testClasses[(string) $file] = array_shift($testClass);
46 elseif (count($testClass) > 1) {
47 throw new \
Exception("Too many classes in $file");
50 throw new \
Exception("Too few classes in $file");
54 elseif (is_file($path)) {
55 $testClass = self
::_findTestClasses($path);
56 if (count($testClass) == 1) {
57 $testClasses[$path] = array_shift($testClass);
59 elseif (count($testClass) > 1) {
60 throw new \
Exception("Too many classes in $path");
63 throw new \
Exception("Too few classes in $path");
75 * each element is an array with keys:
80 public static function findTestsByPath($paths) {
82 $testClasses = self
::findTestClasses($paths);
83 foreach ($testClasses as $testFile => $testClass) {
84 $clazz = new \
ReflectionClass($testClass);
85 foreach ($clazz->getMethods() as $method) {
86 if (preg_match('/^test/', $method->name
)) {
89 'class' => $testClass,
90 'method' => $method->name
,