From: Tim Otten Date: Fri, 29 Jan 2016 06:14:07 +0000 (-0800) Subject: CiviTest - Configure autoloader for test classes X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=649d6dd08539215332dc943a749af302a42f76ef;p=civicrm-core.git CiviTest - Configure autoloader for test classes --- diff --git a/CRM/Core/ClassLoader.php b/CRM/Core/ClassLoader.php index 3002716fbe..fb91ca0791 100644 --- a/CRM/Core/ClassLoader.php +++ b/CRM/Core/ClassLoader.php @@ -42,6 +42,14 @@ class CRM_Core_ClassLoader { */ private static $_singleton = NULL; + /** + * The classes in CiviTest have ucky, non-standard naming. + * + * @var array + * Array(string $className => string $filePath). + */ + private $civiTestClasses; + /** * @param bool $force * @@ -63,6 +71,23 @@ class CRM_Core_ClassLoader { */ protected function __construct() { $this->_registered = FALSE; + $this->civiTestClasses = array( + 'CiviCaseTestCase', + 'CiviDBAssert', + 'CiviMailUtils', + 'CiviReportTestCase', + 'CiviSeleniumTestCase', + 'CiviTestPdoUtils', + 'CiviTestSuite', + 'CiviUnitTestCase', + 'Contact', + 'ContributionPage', + 'Custom', + 'Event', + 'Membership', + 'Participant', + 'PaypalPro', + ); } /** @@ -170,6 +195,20 @@ class CRM_Core_ClassLoader { require_once $file; } } + elseif (in_array($class, $this->civiTestClasses)) { + $file = "tests/phpunit/CiviTest/{$class}.php"; + if (FALSE != stream_resolve_include_path($file)) { + require_once $file; + } + } + elseif ($class === 'CiviSeleniumSettings') { + if (!empty($GLOBALS['_CV'])) { + require_once 'tests/phpunit/CiviTest/CiviSeleniumSettings.auto.php'; + } + elseif (CRM_Utils_File::isIncludable('tests/phpunit/CiviTest/CiviSeleniumSettings.php')) { + require_once 'tests/phpunit/CiviTest/CiviSeleniumSettings.php'; + } + } } } diff --git a/tests/phpunit/CiviTest/CiviSeleniumTestCase.php b/tests/phpunit/CiviTest/CiviSeleniumTestCase.php index 98f32c1669..10fc2ca044 100644 --- a/tests/phpunit/CiviTest/CiviSeleniumTestCase.php +++ b/tests/phpunit/CiviTest/CiviSeleniumTestCase.php @@ -59,15 +59,6 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase { parent::__construct($name, $data, $dataName, $browser); $this->loggedInAs = NULL; - if (!empty($GLOBALS['_CV'])) { - require_once 'CiviSeleniumSettings.auto.php'; - } - elseif (CRM_Utils_File::isIncludable('CiviSeleniumSettings.php')) { - require_once 'CiviSeleniumSettings.php'; - } - else { - throw new RuntimeException("Cannot initialize Selenium test. Please setup CiviSeleniumSettings.php or configure \"cv\"."); - } $this->settings = new CiviSeleniumSettings(); if (property_exists($this->settings, 'serverStartupTimeOut') && $this->settings->serverStartupTimeOut) { global $CiviSeleniumTestCase_polled; diff --git a/tests/phpunit/Utils.php b/tests/phpunit/CiviTest/CiviTestPdoUtils.php similarity index 99% rename from tests/phpunit/Utils.php rename to tests/phpunit/CiviTest/CiviTestPdoUtils.php index 30e1def8a8..eaccb7a8d5 100644 --- a/tests/phpunit/Utils.php +++ b/tests/phpunit/CiviTest/CiviTestPdoUtils.php @@ -34,7 +34,7 @@ * Utility functions * @package CiviCRM */ -class Utils { +class CiviTestPdoUtils { /** * PDO for the database. diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index 8016a45a17..b6e06ff0da 100755 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -31,7 +31,6 @@ use Civi\Payment\System; /** * Include class definitions */ -require_once 'tests/phpunit/Utils.php'; require_once 'api/api.php'; require_once 'CRM/Financial/BAO/FinancialType.php'; define('API_LATEST_VERSION', 3); @@ -162,7 +161,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { self::$_dbName = self::getDBName(); // create test database - self::$utils = new Utils(CIVICRM_DSN); + self::$utils = new CiviTestPdoUtils(CIVICRM_DSN); // also load the class loader require_once 'CRM/Core/ClassLoader.php'; @@ -202,7 +201,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { */ public static function getDBName() { static $dbName = NULL; - if ($dbName === NULL ) { + if ($dbName === NULL) { require_once "DB.php"; $dsninfo = DB::parseDSN(CIVICRM_DSN); $dbName = $dsninfo['database']; @@ -2755,7 +2754,6 @@ AND ( TABLE_NAME LIKE 'civicrm_value_%' ) * 'template_path' Set to TRUE to use the default, FALSE or "" to disable support, or a string path to use another path */ public function customDirectories($customDirs) { - require_once 'CRM/Core/Config.php'; $config = CRM_Core_Config::singleton(); if (empty($customDirs['php_path']) || $customDirs['php_path'] === FALSE) { @@ -3419,8 +3417,6 @@ AND ( TABLE_NAME LIKE 'civicrm_value_%' ) */ protected function createParticipantWithContribution() { // creating price set, price field - require_once 'CiviTest/Event.php'; - require_once 'CiviTest/Contact.php'; $this->_contactId = Contact::createIndividual(); $this->_eventId = Event::create($this->_contactId); $eventParams = array(