Skip to content

Commit

Permalink
Using Folder class in CakeTestSuite, this fixes issues where
Browse files Browse the repository at this point in the history
hidden directories from VCS would be added as test cases.
Fixes #1933
  • Loading branch information
markstory committed Aug 27, 2011
1 parent 682dc5e commit 02a6883
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 21 deletions.
3 changes: 1 addition & 2 deletions lib/Cake/Test/Case/AllComponentsTest.php
Expand Up @@ -36,8 +36,7 @@ public static function suite() {

$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;
}
}
18 changes: 7 additions & 11 deletions lib/Cake/TestSuite/CakeTestSuite.php
Expand Up @@ -18,6 +18,8 @@
*/
PHP_CodeCoverage_Filter::getInstance()->addFileToBlacklist(__FILE__, 'DEFAULT');

App::uses('Folder', 'Utility');

class CakeTestSuite extends PHPUnit_Framework_TestSuite {

/**
Expand All @@ -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);
}
}
Expand All @@ -45,15 +44,12 @@ public function addTestDirectory($directory = '.') {
* @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);
}
}

}
}
14 changes: 6 additions & 8 deletions lib/Cake/Utility/Folder.php
Expand Up @@ -384,14 +384,9 @@ public function chmod($path, $mode = false, $recursive = true, $exceptions = arr
* @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);
Expand All @@ -408,6 +403,9 @@ public function tree($path, $exceptions = true, $type = null) {
$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) {
Expand Down

0 comments on commit 02a6883

Please sign in to comment.