Permalink
Browse files

make it possible to test for files that don't exist

  • Loading branch information...
1 parent d492c86 commit 6ab5f1f2a2f900451202b0a4166bd41a9a38fbfe @AD7six AD7six committed Oct 18, 2011
Showing with 60 additions and 9 deletions.
  1. +9 −8 lib/Cake/Console/Command/TestShell.php
  2. +51 −1 lib/Cake/Test/Case/Console/Command/TestShellTest.php
@@ -337,10 +337,13 @@ public function available() {
* Find the test case for the passed file. The file could itself be a test.
*
* @param mixed $file
+ * @param mixed $category
+ * @param mixed $throwOnMissingFile
* @access protected
* @return array(type, case)
+ * @throws Exception
*/
- protected function _mapFileToCase($file, $category) {
+ protected function _mapFileToCase($file, $category, $throwOnMissingFile = true) {
if (!$category || (substr($file, -4) !== '.php')) {
return false;
}
@@ -381,12 +384,11 @@ protected function _mapFileToCase($file, $category) {
$testCase[0] = strtoupper($testCase[0]);
$testFile = CAKE . 'Test/Case/' . $testCase . 'Test.php';
- if (file_exists($testFile)) {
- return $testCase;
+ if (!file_exists($testFile) && $throwOnMissingFile) {
+ throw new Exception(__d('cake_dev', 'Test case %s not found', $testFile));
}
-
- throw new Exception(__d('cake_dev', 'Test case %s not found', $testFile));
- return false;
+
+ return $testCase;
}
if ($category === 'app') {
@@ -399,9 +401,8 @@ protected function _mapFileToCase($file, $category) {
);
}
- if (!file_exists($testFile)) {
+ if (!file_exists($testFile) && $throwOnMissingFile) {
throw new Exception(__d('cake_dev', 'Test case %s not found', $testFile));
- return false;
}
$testCase = substr($file, 0, -8);
@@ -20,6 +20,17 @@
App::uses('ShellDispatcher', 'Console');
App::uses('TestShell', 'Console/Command');
+class TestTestShell extends TestShell {
+
+ public function mapFileToCase($file, $category, $throwOnMissingFile = true) {
+ return $this->_mapFileToCase($file, $category, $throwOnMissingFile);
+ }
+
+ public function mapFileToCategory($file) {
+ return $this->_mapFileToCategory($file);
+ }
+}
+
class TestShellTest extends CakeTestCase {
@@ -33,7 +44,7 @@ public function setUp() {
$in = $this->getMock('ConsoleInput', array(), array(), '', false);
$this->Shell = $this->getMock(
- 'TestShell',
+ 'TestTestShell',
array('in', 'out', 'hr', 'help', 'error', 'err', '_stop', 'initialize', '_run', 'clear'),
array($out, $out, $in)
);
@@ -49,6 +60,45 @@ public function tearDown() {
unset($this->Dispatch, $this->Shell);
}
+/**
+ * testMapCoreFileToCategory
+ *
+ *
+ * @return void
+ */
+ public function testMapCoreFileToCategory() {
+ $this->Shell->startup();
+
+ $return = $this->Shell->mapFileToCategory('lib/Cake/basics.php');
+ $this->assertSame('core', $return);
+
+ $return = $this->Shell->mapFileToCategory('lib/Cake/Core/App.php');
+ $this->assertSame('core', $return);
+
+ $return = $this->Shell->mapFileToCategory('lib/Cake/Some/Deeply/Nested/Structure.php');
+ $this->assertSame('core', $return);
+ }
+
+/**
+ * testMapCoreFileToCase
+ *
+ * basics.php is a slightly special case - it's the only file in the core with a test that isn't Capitalized
+ *
+ * @return void
+ */
+ public function testMapCoreFileToCase() {
+ $this->Shell->startup();
+
+ $return = $this->Shell->mapFileToCase('lib/Cake/basics.php', 'core');
+ $this->assertSame('Basics', $return);
+
+ $return = $this->Shell->mapFileToCase('lib/Cake/Core/App.php', 'core');
+ $this->assertSame('Core/App', $return);
+
+ $return = $this->Shell->mapFileToCase('lib/Cake/Some/Deeply/Nested/Structure.php', 'core', false);
+ $this->assertSame('Some/Deeply/Nested/Structure', $return);
+ }
+
/**
* test available list of test cases for an empty category
*

0 comments on commit 6ab5f1f

Please sign in to comment.