Permalink
Browse files

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>
  • Loading branch information...
1 parent 8a64175 commit 3f7e2f536f3f7aa25f20e87e5370b26952e85c10 @pixelistik pixelistik committed with markstory Apr 23, 2012
Showing with 29 additions and 2 deletions.
  1. +23 −0 lib/Cake/Test/Case/TestSuite/CakeTestSuiteTest.php
  2. +6 −2 lib/Cake/TestSuite/CakeTestSuite.php
@@ -78,4 +78,27 @@ public function testAddTestDirectoryRecursiveWithHidden() {
$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();
+ }
}
@@ -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);
+ }
}
}
@@ -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);
+ }
}
}

0 comments on commit 3f7e2f5

Please sign in to comment.