4 use Symfony\Component\Finder\Finder
;
7 * Search for PHPUnit test cases
12 * @return array <string> class names
14 public static function _findTestClasses($path) {
16 // 'loading' => $path,
17 // get_included_files()
19 $origClasses = get_declared_classes();
21 $newClasses = get_declared_classes();
23 return preg_grep('/Test$/', array_diff(
31 * @return array (string $file => string $class)
34 public static function findTestClasses($paths) {
35 $testClasses = array();
36 $finder = new Finder();
38 foreach ($paths as $path) {
40 foreach ($finder->files()->in($paths)->name('*Test.php') as $file) {
41 $testClass = self
::_findTestClasses((string) $file);
42 if (count($testClass) == 1) {
43 $testClasses[(string) $file] = array_shift($testClass);
45 elseif (count($testClass) > 1) {
46 throw new \
Exception("Too many classes in $file");
49 throw new \
Exception("Too few classes in $file");
53 elseif (is_file($path)) {
54 $testClass = self
::_findTestClasses($path);
55 if (count($testClass) == 1) {
56 $testClasses[$path] = array_shift($testClass);
58 elseif (count($testClass) > 1) {
59 throw new \
Exception("Too many classes in $path");
62 throw new \
Exception("Too few classes in $path");
74 * each element is an array with keys:
79 public static function findTestsByPath($paths) {
81 $testClasses = self
::findTestClasses($paths);
82 foreach ($testClasses as $testFile => $testClass) {
83 $clazz = new \
ReflectionClass($testClass);
84 foreach ($clazz->getMethods() as $method) {
85 if (preg_match('/^test/', $method->name
)) {
88 'class' => $testClass,
89 'method' => $method->name
,