Skip to content

Commit 2a36e5f

Browse files
committed
Adding Test case for TestTask
Fixing path appending issues caused by continual baking. Fixes #6099 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8027 3807eeeb-6ff5-0310-8944-8be069107fe0
1 parent 440c629 commit 2a36e5f

File tree

2 files changed

+106
-15
lines changed

2 files changed

+106
-15
lines changed

cake/console/libs/tasks/test.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -87,19 +87,19 @@ function __interactive($class = null) {
8787
}
8888

8989
while ($class == null) {
90+
$cases = array();
91+
$this->hr();
92+
$this->out("Select a class:");
93+
$this->hr();
94+
95+
$keys = array();
96+
foreach ($options as $key => $option) {
97+
$this->out(++$key . '. ' . $option);
98+
$keys[] = $key;
99+
}
100+
$keys[] = 'q';
90101

91-
$this->hr();
92-
$this->out("Select a class:");
93-
$this->hr();
94-
95-
$keys = array();
96-
foreach ($options as $key => $option) {
97-
$this->out(++$key . '. ' . $option);
98-
$keys[] = $key;
99-
}
100-
$keys[] = 'q';
101-
102-
$key = $this->in(__("Enter the class to test or (q)uit", true), $keys, 'q');
102+
$key = $this->in(__("Enter the class to test or (q)uit", true), $keys, 'q');
103103

104104
if ($key != 'q') {
105105
if (isset($options[--$key])) {
@@ -143,7 +143,7 @@ function bake($class, $name = null, $cases = array()) {
143143
}
144144

145145
if (strpos($this->path, $class) === false) {
146-
$this->path .= 'cases' . DS . Inflector::tableize($class) . DS;
146+
$this->filePath = $this->path . 'cases' . DS . Inflector::tableize($class) . DS;
147147
}
148148

149149
$class = Inflector::classify($class);
@@ -175,14 +175,14 @@ function bake($class, $name = null, $cases = array()) {
175175

176176
$this->out("Baking unit test for $name...");
177177
$this->out($out);
178-
$ok = $this->in(__('Is this correct?'), array('y', 'n'), 'y');
178+
$ok = $this->in(__('Is this correct?', true), array('y', 'n'), 'y');
179179
if ($ok == 'n') {
180180
return false;
181181
}
182182

183183
$header = '$Id';
184184
$content = "<?php \n/* SVN FILE: $header$ */\n/* ". $name ." Test cases generated on: " . date('Y-m-d H:m:s') . " : ". time() . "*/\n{$out}?>";
185-
return $this->createFile($this->path . Inflector::underscore($name) . '.test.php', $content);
185+
return $this->createFile($this->filePath . Inflector::underscore($name) . '.test.php', $content);
186186
}
187187
/**
188188
* Handles the extra stuff needed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
/* SVN FILE: $Id$ */
3+
/**
4+
* Test Case for test generation shell task
5+
*
6+
*
7+
*
8+
* PHP versions 4 and 5
9+
*
10+
* CakePHP : Rapid Development Framework (http://www.cakephp.org)
11+
* Copyright 2006-2008, Cake Software Foundation, Inc.
12+
*
13+
* Licensed under The MIT License
14+
* Redistributions of files must retain the above copyright notice.
15+
*
16+
* @filesource
17+
* @copyright Copyright 2006-2008, Cake Software Foundation, Inc.
18+
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
19+
* @package cake
20+
* @subpackage cake.cake.libs.
21+
* @since CakePHP v 1.2.0.7726
22+
* @version $Revision$
23+
* @modifiedby $LastChangedBy$
24+
* @lastmodified $Date$
25+
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
26+
*/
27+
App::import('Core', 'Shell');
28+
29+
if (!defined('DISABLE_AUTO_DISPATCH')) {
30+
define('DISABLE_AUTO_DISPATCH', true);
31+
}
32+
33+
if (!class_exists('ShellDispatcher')) {
34+
ob_start();
35+
$argv = false;
36+
require CAKE . 'console' . DS . 'cake.php';
37+
ob_end_clean();
38+
}
39+
40+
if (!class_exists('TestTask')) {
41+
require CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'test.php';
42+
}
43+
44+
class TestTestShellDispatcher extends ShellDispatcher {
45+
46+
function _initEnvironment() {
47+
}
48+
49+
function stdout($string, $newline = true) {
50+
}
51+
52+
function stderr($string) {
53+
}
54+
55+
function getInput($prompt, $options, $default) {
56+
}
57+
58+
function _stop($status = 0) {
59+
$this->stopped = 'Stopped with status: ' . $status;
60+
}
61+
}
62+
63+
Mock::generatePartial('TestTask', 'MockTestTask', array('createFile', 'out', 'in'));
64+
65+
class TestTaskTest extends CakeTestCase {
66+
67+
function setUp() {
68+
$this->dispatcher = new TestTestShellDispatcher();
69+
$this->task = new MockTestTask($this->dispatcher);
70+
}
71+
/**
72+
* Test that file path generation doesn't continuously append paths.
73+
*
74+
* @access public
75+
* @return void
76+
*/
77+
function testFilePathGeneration () {
78+
$this->task->setReturnValue('in', 'y');
79+
$this->task->expectAt(0, 'createFile', array(TESTS . 'cases' . DS . 'models' . DS . 'my_class.test.php', '*'));
80+
$this->task->bake('Model', 'MyClass');
81+
82+
$this->task->expectAt(1, 'createFile', array(TESTS . 'cases' . DS . 'models' . DS . 'my_class.test.php', '*'));
83+
$this->task->bake('Model', 'MyClass');
84+
}
85+
86+
function tearDown() {
87+
unset($this->task, $this->dispatcher);
88+
}
89+
}
90+
91+
?>

0 commit comments

Comments
 (0)