diff --git a/cake/tests/lib/cake_test_loader.php b/cake/tests/lib/cake_test_loader.php index cbc767f0119..bc23615b706 100644 --- a/cake/tests/lib/cake_test_loader.php +++ b/cake/tests/lib/cake_test_loader.php @@ -85,7 +85,7 @@ protected function _resolveTestFile($filePath, $params) { * @param array $params * @return string The base path. */ - protected function _basePath($params) { + protected static function _basePath($params) { $result = null; if (!empty($params['core'])) { $result = CORE_TEST_CASES; @@ -98,4 +98,44 @@ protected function _basePath($params) { return $result; } +/** + * Get the list of files for the test listing. + * + * @return void + */ + public static function generateTestList($params) { + $directory = self::_basePath($params); + $fileList = self::_getRecursiveFileList($directory); + + $testCases = array(); + foreach ($fileList as $testCaseFile) { + $testCases[$testCaseFile] = str_replace($directory . DS, '', $testCaseFile); + } + return $testCases; + } + +/** + * Gets a recursive list of files from a given directory and matches then against + * a given fileTestFunction, like isTestCaseFile() + * + * @param string $directory The directory to scan for files. + * @param mixed $fileTestFunction + */ + protected static function _getRecursiveFileList($directory = '.') { + $fileList = array(); + if (!is_dir($directory)) { + return $fileList; + } + + $files = new RegexIterator( + new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory)), + '/.*\.test.php$/' + ); + + foreach ($files as $file) { + $fileList[] = $file->getPathname(); + } + return $fileList; + } + } diff --git a/cake/tests/lib/reporter/cake_base_reporter.php b/cake/tests/lib/reporter/cake_base_reporter.php index 99a53d062bb..4232e745187 100644 --- a/cake/tests/lib/reporter/cake_base_reporter.php +++ b/cake/tests/lib/reporter/cake_base_reporter.php @@ -101,125 +101,10 @@ function __construct($charset = 'utf-8', $params = array()) { * @return mixed */ public function testCaseList() { - $testList = $this->_generateTestList($this->params); + $testList = CakeTestLoader::generateTestList($this->params); return $testList; } -/** - * Get the list of files for the test listing. - * - * @return void - */ - protected function _generateTestList($params) { - $directory = self::_getTestsPath($params); - $fileList = self::_getTestFileList($directory); - - $testCases = array(); - foreach ($fileList as $testCaseFile) { - $testCases[$testCaseFile] = str_replace($directory . DS, '', $testCaseFile); - } - return $testCases; - } - -/** - * Returns a list of test files from a given directory - * - * @param string $directory Directory to get test case files from. - * @static - */ - protected static function &_getTestFileList($directory = '.') { - $return = self::_getRecursiveFileList($directory, array('self', '_isTestCaseFile')); - return $return; - } - -/** - * Gets a recursive list of files from a given directory and matches then against - * a given fileTestFunction, like isTestCaseFile() - * - * @param string $directory The directory to scan for files. - * @param mixed $fileTestFunction - * @static - */ - protected static function &_getRecursiveFileList($directory = '.', $fileTestFunction) { - $fileList = array(); - if (!is_dir($directory)) { - return $fileList; - } - - $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory)); - - foreach ($files as $file) { - if (!$file->isFile()) { - continue; - } - $file = $file->getRealPath(); - - if (call_user_func_array($fileTestFunction, array($file))) { - $fileList[] = $file; - } - } - return $fileList; - } -/** - * Extension suffix for test case files. - * - * @var string - */ - protected static $_testExtension = '.test.php'; -/** - * Tests if a file has the correct test case extension - * - * @param string $file - * @return boolean Whether $file is a test case. - * @static - */ - protected static function _isTestCaseFile($file) { - return self::_hasExpectedExtension($file, self::$_testExtension); - } - -/** - * Check if a file has a specific extension - * - * @param string $file - * @param string $extension - * @return void - * @static - */ - protected static function _hasExpectedExtension($file, $extension) { - return $extension == strtolower(substr($file, (0 - strlen($extension)))); - } - -/** - * Returns the given path to the test files depending on a given type of tests (core, app, plugin) - * - * @param array $params Array of parameters for getting test paths. - * Can contain app, type, and plugin params. - * @return string The path tests are located on - * @static - */ - protected static function _getTestsPath($params) { - $result = null; - if (!empty($params['app'])) { - $result = APP_TEST_CASES; - } else if (!empty($params['plugin'])) { - $pluginPath = App::pluginPath($params['plugin']); - $result = $pluginPath . 'tests' . DS . 'cases'; - } else { - $result = CORE_TEST_CASES; - } - return $result; - } - -/** - * Get the extension for either 'group' or 'test' types. - * - * @param string $type Type of test to get, either 'test' or 'group' - * @return string Extension suffix for test. - */ - public static function getExtension($type = 'test') { - return self::$_testExtension; - } - /** * Paints the start of the response from the test suite. * Used to paint things like head elements in an html page.