Commit | Line | Data |
---|---|---|
52bd16c5 TO |
1 | <?php |
2 | ||
3 | /** | |
4 | * The EnvTests suite allows you to specify an arbitrary mix of tests | |
5 | * using an environment variable. For example: | |
6 | * | |
7 | * env PHPUNIT_TESTS="MyFirstTest MySecondTest" phpunit EnvTests | |
8 | * | |
9 | * The PHPUNIT_TESTS variable contains a space-delimited list of test | |
10 | * names. Each name may be a class (eg "MyFirstTest") or a method | |
11 | * (eg "MyFirstTest::testFoo"). | |
12 | */ | |
13 | class EnvTests extends \PHPUnit_Framework_TestSuite { | |
14 | public static function suite() { | |
15 | require_once 'CRM/Core/ClassLoader.php'; | |
16 | CRM_Core_ClassLoader::singleton()->register(); | |
17 | ||
18 | $suite = new EnvTests(); | |
19 | $tests = getenv('PHPUNIT_TESTS'); | |
20 | foreach (explode(' ', $tests) as $test) { | |
21 | if (strpos($test, '::') !== FALSE) { | |
22 | list ($class, $method) = explode('::', $test); | |
23 | $clazz = new \ReflectionClass($class); | |
24 | $suite->addTestMethod($clazz, $clazz->getMethod($method)); | |
25 | } else { | |
26 | $suite->addTestSuite($test); | |
27 | } | |
28 | } | |
29 | return $suite; | |
30 | } | |
31 | } |