Browse files

Add tests for CakeTestSuite and dont include hidden folders when recu…

…rsively addTestFile
  • Loading branch information...
1 parent c3f17c2 commit 7fa1984a43f6d1c921a1b58dcea3b2295fdfc9d0 @shama shama committed Dec 9, 2011
Showing with 102 additions and 0 deletions.
  1. +99 −0 lib/Cake/Test/Case/TestSuite/CakeTestSuiteTest.php
  2. +3 −0 lib/Cake/TestSuite/CakeTestSuite.php
View
99 lib/Cake/Test/Case/TestSuite/CakeTestSuiteTest.php
@@ -0,0 +1,99 @@
+<?php
+/**
+ * CakePHP : Rapid Development Framework (http://cakephp.org)
+ * Copyright 2005-2011, Cake Software Foundation, Inc.
+ *
+ * Licensed under The MIT License
+ * Redistributions of files must retain the above copyright notice.
+ *
+ * @copyright Copyright 2005-2011, Cake Software Foundation, Inc.
+ * @link http://cakephp.org CakePHP Project
+ * @package Cake.Test.Case.TestSuite
+ * @since CakePHP v 1.2.0.4487
+ * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
+ */
+
+/**
+ * CakeTestSuiteTest
+ *
+ * @package Cake.Test.Case.TestSuite
+ */
+class CakeTestSuiteTest extends CakeTestCase {
+
+/**
+ * setUp
+ *
+ * @return void
+ */
+ public function setUp() {
+ parent::setUp();
+ }
+
+/**
+ * tearDown
+ *
+ * @return void
+ */
+ public function tearDown() {
+ parent::tearDown();
+ }
+
+/**
+ * testAddTestDirectory
+ *
+ * @return void
+ */
+ public function testAddTestDirectory() {
+ $testFolder = CORE_TEST_CASES . DS . 'TestSuite';
+ $count = count(glob($testFolder . DS . '*Test.php'));
+
+ $suite = $this->getMock('CakeTestSuite', array('addTestFile'));
+ $suite
+ ->expects($this->exactly($count))
+ ->method('addTestFile');
+
+ $suite->addTestDirectory($testFolder);
+ }
+
+/**
+ * testAddTestDirectoryRecursive
+ *
+ * @return void
+ */
+ public function testAddTestDirectoryRecursive() {return;
+ $testFolder = CORE_TEST_CASES . DS . 'Cache';
+ $count = count(glob($testFolder . DS . '*Test.php'));
+ $count += count(glob($testFolder . DS . 'Engine' . DS . '*Test.php'));
+
+ $suite = $this->getMock('CakeTestSuite', array('addTestFile'));
+ $suite
+ ->expects($this->exactly($count))
+ ->method('addTestFile');
+
+ $suite->addTestDirectoryRecursive($testFolder);
+ }
+
+/**
+ * testAddTestDirectoryRecursiveWithHidden
+ *
+ * @return void
+ */
+ public function testAddTestDirectoryRecursiveWithHidden() {
+ $this->skipIf(!is_writeable(TMP), 'Cant addTestDirectoryRecursiveWithHidden unless the tmp folder is writable.');
+
+ $Folder = new Folder(TMP . 'MyTestFolder', true, 0777);
+ mkdir($Folder->path . DS . '.svn', 0777, true);
+ touch($Folder->path . DS . '.svn' . DS . 'InHiddenFolderTest.php');
+ touch($Folder->path . DS . 'NotHiddenTest.php');
+ touch($Folder->path . DS . '.HiddenTest.php');
+
+ $suite = $this->getMock('CakeTestSuite', array('addTestFile'));
+ $suite
+ ->expects($this->exactly(1))
+ ->method('addTestFile');
+
+ $suite->addTestDirectoryRecursive($Folder->pwd());
+
+ $Folder->delete();
+ }
+}
View
3 lib/Cake/TestSuite/CakeTestSuite.php
@@ -52,6 +52,9 @@ public function addTestDirectoryRecursive($directory = '.') {
$files = $Folder->tree(null, false, 'files');
foreach ($files as $file) {
+ if (strpos($file, DS.'.') !== false) {
+ continue;
+ }
$this->addTestFile($file);
}
}

0 comments on commit 7fa1984

Please sign in to comment.