CRM-15011, INFRA-124, CRM-13899 - Add EnvTests
authorTim Otten <totten@civicrm.org>
Fri, 8 Aug 2014 01:59:09 +0000 (18:59 -0700)
committerTim Otten <totten@civicrm.org>
Fri, 8 Aug 2014 01:59:09 +0000 (18:59 -0700)
tests/phpunit/EnvTests.php [new file with mode: 0644]

diff --git a/tests/phpunit/EnvTests.php b/tests/phpunit/EnvTests.php
new file mode 100644 (file)
index 0000000..cd44c65
--- /dev/null
@@ -0,0 +1,31 @@
+<?php
+
+/**
+ * The EnvTests suite allows you to specify an arbitrary mix of tests
+ * using an environment variable. For example:
+ *
+ * env PHPUNIT_TESTS="MyFirstTest MySecondTest" phpunit EnvTests
+ *
+ * The PHPUNIT_TESTS variable contains a space-delimited list of test
+ * names. Each name may be a class (eg "MyFirstTest") or a method
+ * (eg "MyFirstTest::testFoo").
+ */
+class EnvTests extends \PHPUnit_Framework_TestSuite {
+  public static function suite() {
+    require_once 'CRM/Core/ClassLoader.php';
+    CRM_Core_ClassLoader::singleton()->register();
+
+    $suite = new EnvTests();
+    $tests = getenv('PHPUNIT_TESTS');
+    foreach (explode(' ', $tests) as $test) {
+      if (strpos($test, '::') !== FALSE) {
+        list ($class, $method) = explode('::', $test);
+        $clazz = new \ReflectionClass($class);
+        $suite->addTestMethod($clazz, $clazz->getMethod($method));
+      } else {
+        $suite->addTestSuite($test);
+      }
+    }
+    return $suite;
+  }
+}
\ No newline at end of file