mirror of
https://github.com/brmlab/brmsklad.git
synced 2025-08-02 14:23:34 +02:00
Backup of current cakephp version
This commit is contained in:
parent
b8f82da6f8
commit
5a580df460
925 changed files with 238041 additions and 1 deletions
123
lib/Cake/TestSuite/CakeTestLoader.php
Normal file
123
lib/Cake/TestSuite/CakeTestLoader.php
Normal file
|
@ -0,0 +1,123 @@
|
|||
<?php
|
||||
/**
|
||||
* TestLoader for CakePHP Test suite.
|
||||
*
|
||||
* Turns partial paths used on the testsuite console and web UI into full file paths.
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @since CakePHP(tm) v 2.0
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @package Cake.TestSuite
|
||||
*/
|
||||
|
||||
/**
|
||||
* TestLoader for CakePHP Test suite.
|
||||
*
|
||||
* Turns partial paths used on the testsuite console and web UI into full file paths.
|
||||
*
|
||||
* @package Cake.TestSuite
|
||||
*/
|
||||
class CakeTestLoader extends PHPUnit_Runner_StandardTestSuiteLoader {
|
||||
|
||||
/**
|
||||
* Load a file and find the first test case / suite in that file.
|
||||
*
|
||||
* @param string $filePath
|
||||
* @param string $params
|
||||
* @return ReflectionClass
|
||||
*/
|
||||
public function load($filePath, $params = '') {
|
||||
$file = $this->_resolveTestFile($filePath, $params);
|
||||
return parent::load('', $file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert path fragments used by Cake's test runner to absolute paths that can be fed to PHPUnit.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _resolveTestFile($filePath, $params) {
|
||||
$basePath = $this->_basePath($params) . DS . $filePath;
|
||||
$ending = 'Test.php';
|
||||
return (strpos($basePath, $ending) === (strlen($basePath) - strlen($ending))) ? $basePath : $basePath . $ending;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the base path to a set of tests based on the parameters.
|
||||
*
|
||||
* @param array $params
|
||||
* @return string The base path.
|
||||
*/
|
||||
protected static function _basePath($params) {
|
||||
$result = null;
|
||||
if (!empty($params['core'])) {
|
||||
$result = CORE_TEST_CASES;
|
||||
} elseif (!empty($params['plugin'])) {
|
||||
if (!CakePlugin::loaded($params['plugin'])) {
|
||||
try {
|
||||
CakePlugin::load($params['plugin']);
|
||||
$result = CakePlugin::path($params['plugin']) . 'Test' . DS . 'Case';
|
||||
} catch (MissingPluginException $e) {
|
||||
}
|
||||
} else {
|
||||
$result = CakePlugin::path($params['plugin']) . 'Test' . DS . 'Case';
|
||||
}
|
||||
} elseif (!empty($params['app'])) {
|
||||
$result = APP_TEST_CASES;
|
||||
}
|
||||
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) {
|
||||
$case = str_replace($directory . DS, '', $testCaseFile);
|
||||
$case = str_replace('Test.php', '', $case);
|
||||
$testCases[$testCaseFile] = $case;
|
||||
}
|
||||
sort($testCases);
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue