Using Folder class in CakeTestSuite, this fixes issues where

hidden directories from VCS would be added as test cases.
Fixes #1933
This commit is contained in:
mark_story 2011-08-27 10:34:08 -04:00
parent 682dc5e24b
commit 02a6883b22
3 changed files with 14 additions and 21 deletions

View file

@ -36,8 +36,7 @@ class AllComponentsTest extends PHPUnit_Framework_TestSuite {
$suite->addTestFile(CORE_TEST_CASES . DS . 'Controller' . DS . 'ComponentTest.php');
$suite->addTestFile(CORE_TEST_CASES . DS . 'Controller' . DS . 'ComponentCollectionTest.php');
$suite->addTestDirectory(CORE_TEST_CASES . DS . 'Controller' . DS . 'Component');
$suite->addTestDirectory(CORE_TEST_CASES . DS . 'Controller' . DS . 'Component' . DS . 'Auth');
$suite->addTestDirectoryRecursive(CORE_TEST_CASES . DS . 'Controller' . DS . 'Component');
return $suite;
}
}

View file

@ -18,6 +18,8 @@
*/
PHP_CodeCoverage_Filter::getInstance()->addFileToBlacklist(__FILE__, 'DEFAULT');
App::uses('Folder', 'Utility');
class CakeTestSuite extends PHPUnit_Framework_TestSuite {
/**
@ -27,13 +29,10 @@ class CakeTestSuite extends PHPUnit_Framework_TestSuite {
* @return void
*/
public function addTestDirectory($directory = '.') {
$files = new DirectoryIterator($directory);
$folder = new Folder($directory);
list($dirs, $files) = $folder->read(true, false, true);
foreach ($files as $file) {
if (!$file->isFile()) {
continue;
}
$file = $file->getRealPath();
$this->addTestFile($file);
}
}
@ -45,15 +44,12 @@ class CakeTestSuite extends PHPUnit_Framework_TestSuite {
* @return void
*/
public function addTestDirectoryRecursive($directory = '.') {
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory));
$folder = new Folder($directory);
$files = $folder->tree(null, false, 'files');
foreach ($files as $file) {
if (!$file->isFile()) {
continue;
}
$file = $file->getRealPath();
$this->addTestFile($file);
}
}
}
}

View file

@ -384,14 +384,9 @@ class Folder {
* @param string $type either file or dir. null returns both files and directories
* @return mixed array of nested directories and files in each directory
*/
public function tree($path, $exceptions = true, $type = null) {
$original = $this->path;
$path = rtrim($path, DS);
if (!$this->cd($path)) {
if ($type === null) {
return array(array(), array());
}
return array();
public function tree($path = null, $exceptions = true, $type = null) {
if ($path == null) {
$path = $this->path;
}
$files = array();
$directories = array($path);
@ -408,6 +403,9 @@ class Folder {
$directory = new RecursiveDirectoryIterator($path);
$iterator = new RecursiveIteratorIterator($directory, RecursiveIteratorIterator::SELF_FIRST);
} catch (UnexpectedValueException $e) {
if ($type === null) {
return array(array(), array());
}
return array();
}
foreach ($iterator as $item) {