Skip to content

Commit

Permalink
CakeTestSuite::addTestDirectory() ignore non-php
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
pixelistik authored and markstory committed Apr 23, 2012
1 parent 8a64175 commit 3f7e2f5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
23 changes: 23 additions & 0 deletions lib/Cake/Test/Case/TestSuite/CakeTestSuiteTest.php
Expand Up @@ -76,6 +76,29 @@ public function testAddTestDirectoryRecursiveWithHidden() {

$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();
}
}
8 changes: 6 additions & 2 deletions lib/Cake/TestSuite/CakeTestSuite.php
Expand Up @@ -37,7 +37,9 @@ public function addTestDirectory($directory = '.') {
list($dirs, $files) = $Folder->read(true, true, true);

foreach ($files as $file) {
$this->addTestFile($file);
if (substr($file, -4) === '.php') {
$this->addTestFile($file);
}
}
}

Expand All @@ -52,7 +54,9 @@ public function addTestDirectoryRecursive($directory = '.') {
$files = $Folder->tree(null, true, 'files');

foreach ($files as $file) {
$this->addTestFile($file);
if (substr($file, -4) === '.php') {
$this->addTestFile($file);
}
}
}

Expand Down

0 comments on commit 3f7e2f5

Please sign in to comment.