Skip to content

Commit

Permalink
Adding Test case for TestTask
Browse files Browse the repository at this point in the history
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
  • Loading branch information
markstory committed Feb 13, 2009
1 parent 440c629 commit 2a36e5f
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 15 deletions.
30 changes: 15 additions & 15 deletions cake/console/libs/tasks/test.php
Expand Up @@ -87,19 +87,19 @@ function __interactive($class = null) {
}

while ($class == null) {
$cases = array();
$this->hr();
$this->out("Select a class:");
$this->hr();

$keys = array();
foreach ($options as $key => $option) {
$this->out(++$key . '. ' . $option);
$keys[] = $key;
}
$keys[] = 'q';

$this->hr();
$this->out("Select a class:");
$this->hr();

$keys = array();
foreach ($options as $key => $option) {
$this->out(++$key . '. ' . $option);
$keys[] = $key;
}
$keys[] = 'q';

$key = $this->in(__("Enter the class to test or (q)uit", true), $keys, 'q');
$key = $this->in(__("Enter the class to test or (q)uit", true), $keys, 'q');

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

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

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

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

$header = '$Id';
$content = "<?php \n/* SVN FILE: $header$ */\n/* ". $name ." Test cases generated on: " . date('Y-m-d H:m:s') . " : ". time() . "*/\n{$out}?>";
return $this->createFile($this->path . Inflector::underscore($name) . '.test.php', $content);
return $this->createFile($this->filePath . Inflector::underscore($name) . '.test.php', $content);
}
/**
* Handles the extra stuff needed
Expand Down
91 changes: 91 additions & 0 deletions cake/tests/cases/console/libs/tasks/test.test.php
@@ -0,0 +1,91 @@
<?php
/* SVN FILE: $Id$ */
/**
* Test Case for test generation shell task
*
*
*
* PHP versions 4 and 5
*
* CakePHP : Rapid Development Framework (http://www.cakephp.org)
* Copyright 2006-2008, Cake Software Foundation, Inc.
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @filesource
* @copyright Copyright 2006-2008, Cake Software Foundation, Inc.
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
* @package cake
* @subpackage cake.cake.libs.
* @since CakePHP v 1.2.0.7726
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
App::import('Core', 'Shell');

if (!defined('DISABLE_AUTO_DISPATCH')) {
define('DISABLE_AUTO_DISPATCH', true);
}

if (!class_exists('ShellDispatcher')) {
ob_start();
$argv = false;
require CAKE . 'console' . DS . 'cake.php';
ob_end_clean();
}

if (!class_exists('TestTask')) {
require CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'test.php';
}

class TestTestShellDispatcher extends ShellDispatcher {

function _initEnvironment() {
}

function stdout($string, $newline = true) {
}

function stderr($string) {
}

function getInput($prompt, $options, $default) {
}

function _stop($status = 0) {
$this->stopped = 'Stopped with status: ' . $status;
}
}

Mock::generatePartial('TestTask', 'MockTestTask', array('createFile', 'out', 'in'));

class TestTaskTest extends CakeTestCase {

function setUp() {
$this->dispatcher = new TestTestShellDispatcher();
$this->task = new MockTestTask($this->dispatcher);
}
/**
* Test that file path generation doesn't continuously append paths.
*
* @access public
* @return void
*/
function testFilePathGeneration () {
$this->task->setReturnValue('in', 'y');
$this->task->expectAt(0, 'createFile', array(TESTS . 'cases' . DS . 'models' . DS . 'my_class.test.php', '*'));
$this->task->bake('Model', 'MyClass');

$this->task->expectAt(1, 'createFile', array(TESTS . 'cases' . DS . 'models' . DS . 'my_class.test.php', '*'));
$this->task->bake('Model', 'MyClass');
}

function tearDown() {
unset($this->task, $this->dispatcher);
}
}

?>

0 comments on commit 2a36e5f

Please sign in to comment.