mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-02-07 12:36:25 +00:00
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:
parent
682dc5e24b
commit
02a6883b22
3 changed files with 14 additions and 21 deletions
|
@ -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 . 'ComponentTest.php');
|
||||||
$suite->addTestFile(CORE_TEST_CASES . DS . 'Controller' . DS . 'ComponentCollectionTest.php');
|
$suite->addTestFile(CORE_TEST_CASES . DS . 'Controller' . DS . 'ComponentCollectionTest.php');
|
||||||
$suite->addTestDirectory(CORE_TEST_CASES . DS . 'Controller' . DS . 'Component');
|
$suite->addTestDirectoryRecursive(CORE_TEST_CASES . DS . 'Controller' . DS . 'Component');
|
||||||
$suite->addTestDirectory(CORE_TEST_CASES . DS . 'Controller' . DS . 'Component' . DS . 'Auth');
|
|
||||||
return $suite;
|
return $suite;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,8 @@
|
||||||
*/
|
*/
|
||||||
PHP_CodeCoverage_Filter::getInstance()->addFileToBlacklist(__FILE__, 'DEFAULT');
|
PHP_CodeCoverage_Filter::getInstance()->addFileToBlacklist(__FILE__, 'DEFAULT');
|
||||||
|
|
||||||
|
App::uses('Folder', 'Utility');
|
||||||
|
|
||||||
class CakeTestSuite extends PHPUnit_Framework_TestSuite {
|
class CakeTestSuite extends PHPUnit_Framework_TestSuite {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -27,13 +29,10 @@ class CakeTestSuite extends PHPUnit_Framework_TestSuite {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function addTestDirectory($directory = '.') {
|
public function addTestDirectory($directory = '.') {
|
||||||
$files = new DirectoryIterator($directory);
|
$folder = new Folder($directory);
|
||||||
|
list($dirs, $files) = $folder->read(true, false, true);
|
||||||
|
|
||||||
foreach ($files as $file) {
|
foreach ($files as $file) {
|
||||||
if (!$file->isFile()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$file = $file->getRealPath();
|
|
||||||
$this->addTestFile($file);
|
$this->addTestFile($file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,15 +44,12 @@ class CakeTestSuite extends PHPUnit_Framework_TestSuite {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function addTestDirectoryRecursive($directory = '.') {
|
public function addTestDirectoryRecursive($directory = '.') {
|
||||||
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory));
|
$folder = new Folder($directory);
|
||||||
|
$files = $folder->tree(null, false, 'files');
|
||||||
|
|
||||||
foreach ($files as $file) {
|
foreach ($files as $file) {
|
||||||
if (!$file->isFile()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$file = $file->getRealPath();
|
|
||||||
$this->addTestFile($file);
|
$this->addTestFile($file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -384,14 +384,9 @@ class Folder {
|
||||||
* @param string $type either file or dir. null returns both files and directories
|
* @param string $type either file or dir. null returns both files and directories
|
||||||
* @return mixed array of nested directories and files in each directory
|
* @return mixed array of nested directories and files in each directory
|
||||||
*/
|
*/
|
||||||
public function tree($path, $exceptions = true, $type = null) {
|
public function tree($path = null, $exceptions = true, $type = null) {
|
||||||
$original = $this->path;
|
if ($path == null) {
|
||||||
$path = rtrim($path, DS);
|
$path = $this->path;
|
||||||
if (!$this->cd($path)) {
|
|
||||||
if ($type === null) {
|
|
||||||
return array(array(), array());
|
|
||||||
}
|
|
||||||
return array();
|
|
||||||
}
|
}
|
||||||
$files = array();
|
$files = array();
|
||||||
$directories = array($path);
|
$directories = array($path);
|
||||||
|
@ -408,6 +403,9 @@ class Folder {
|
||||||
$directory = new RecursiveDirectoryIterator($path);
|
$directory = new RecursiveDirectoryIterator($path);
|
||||||
$iterator = new RecursiveIteratorIterator($directory, RecursiveIteratorIterator::SELF_FIRST);
|
$iterator = new RecursiveIteratorIterator($directory, RecursiveIteratorIterator::SELF_FIRST);
|
||||||
} catch (UnexpectedValueException $e) {
|
} catch (UnexpectedValueException $e) {
|
||||||
|
if ($type === null) {
|
||||||
|
return array(array(), array());
|
||||||
|
}
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
foreach ($iterator as $item) {
|
foreach ($iterator as $item) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue