Merge pull request #4969 from lynxlynxlynx/master
[civicrm-core.git] / tests / phpunit / EnvTests.php
CommitLineData
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 */
13class EnvTests extends \PHPUnit_Framework_TestSuite {
f0be539a
EM
14 /**
15 * @return \EnvTests
16 */
52bd16c5
TO
17 public static function suite() {
18 require_once 'CRM/Core/ClassLoader.php';
19 CRM_Core_ClassLoader::singleton()->register();
20
21 $suite = new EnvTests();
22 $tests = getenv('PHPUNIT_TESTS');
23 foreach (explode(' ', $tests) as $test) {
24 if (strpos($test, '::') !== FALSE) {
25 list ($class, $method) = explode('::', $test);
26 $clazz = new \ReflectionClass($class);
27 $suite->addTestMethod($clazz, $clazz->getMethod($method));
0db6c3e1
TO
28 }
29 else {
52bd16c5
TO
30 $suite->addTestSuite($test);
31 }
32 }
33 return $suite;
34 }
ef10e0b5 35}