CakeTestSuite::addTestDirectory() ignore non-php

CakeTestSuite::addTestDirectory() and addTestDirectoryRecursive()
now ignore any files that do not end in .php

This avoids any stray non-php files being parsed, especially
tilde-style backup files that end in .php~

Improves #2031

Signed-off-by: mark_story <mark@mark-story.com>
This commit is contained in:
Till Claassen 2012-04-23 12:49:28 +02:00 committed by mark_story
parent 8a6417521f
commit 3f7e2f536f
2 changed files with 29 additions and 2 deletions

View file

@ -76,6 +76,29 @@ class CakeTestSuiteTest extends CakeTestCase {
$suite->addTestDirectoryRecursive($Folder->pwd()); $suite->addTestDirectoryRecursive($Folder->pwd());
$Folder->delete();
}
/**
* testAddTestDirectoryRecursiveWithNonPhp
*
* @return void
*/
public function testAddTestDirectoryRecursiveWithNonPhp() {
$this->skipIf(!is_writeable(TMP), 'Cant addTestDirectoryRecursiveWithNonPhp unless the tmp folder is writable.');
$Folder = new Folder(TMP . 'MyTestFolder', true, 0777);
touch($Folder->path . DS . 'BackupTest.php~');
touch($Folder->path . DS . 'SomeNotesTest.txt');
touch($Folder->path . DS . 'NotHiddenTest.php');
$suite = $this->getMock('CakeTestSuite', array('addTestFile'));
$suite
->expects($this->exactly(1))
->method('addTestFile');
$suite->addTestDirectoryRecursive($Folder->pwd());
$Folder->delete(); $Folder->delete();
} }
} }

View file

@ -37,9 +37,11 @@ class CakeTestSuite extends PHPUnit_Framework_TestSuite {
list($dirs, $files) = $Folder->read(true, true, true); list($dirs, $files) = $Folder->read(true, true, true);
foreach ($files as $file) { foreach ($files as $file) {
if (substr($file, -4) === '.php') {
$this->addTestFile($file); $this->addTestFile($file);
} }
} }
}
/** /**
* Recursively adds all the files in a directory to the test suite. * Recursively adds all the files in a directory to the test suite.
@ -52,8 +54,10 @@ class CakeTestSuite extends PHPUnit_Framework_TestSuite {
$files = $Folder->tree(null, true, 'files'); $files = $Folder->tree(null, true, 'files');
foreach ($files as $file) { foreach ($files as $file) {
if (substr($file, -4) === '.php') {
$this->addTestFile($file); $this->addTestFile($file);
} }
} }
}
} }