Skip to content

Commit

Permalink
extracting out object type interaction.
Browse files Browse the repository at this point in the history
test case added.
  • Loading branch information
markstory committed May 25, 2009
1 parent 1d6ceff commit eb9f40c
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 25 deletions.
71 changes: 48 additions & 23 deletions cake/console/libs/tasks/test.php
Expand Up @@ -45,6 +45,14 @@ class TestTask extends Shell {
* @access public
*/
var $path = TESTS;

/**
* class types that methods can be generated for
*
* @var array
**/
var $classTypes = array('Model', 'Controller', 'Component', 'Behavior', 'Helper');

/**
* Execution method always used for tasks
*
Expand All @@ -66,40 +74,31 @@ function execute() {
}
}
}

/**
* Handles interactive baking
*
* @access private
*/
function __interactive($class = null) {
function __interactive($type = null) {
$this->hr();
$this->out(sprintf("Bake Tests\nPath: %s", $this->path));
$this->out(__('Bake Tests', true));
$this->out(sprintf(__("Path: %s", true), $this->path));
$this->hr();

$key = null;
$options = array('Behavior', 'Helper', 'Component', 'Model', 'Controller');

if ($class !== null) {
$class = Inflector::camelize($class);
if (in_array($class, $options)) {
$key = array_search($class);
$selection = null;
if ($type) {
$type = Inflector::camelize($type);
if (in_array($type, $this->classTypes)) {
$selection = array_search($type);
}
}
if (!$selection) {
$selection = $this->getObjectType();
}
/*
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';

$key = $this->in(__("Enter the class to test or (q)uit", true), $keys, 'q');
$key = $this->in(__("Enter the class to bake a test for or (q)uit", true), $keys, 'q');
if ($key != 'q') {
if (isset($options[--$key])) {
Expand Down Expand Up @@ -127,7 +126,32 @@ function __interactive($class = null) {
$this->_stop();
}
}
*/
}

/**
* Interact with the user and get their chosen type. Can exit the script.
*
* @return int Index of users chosen object type.
**/
function getObjectType() {
$this->hr();
$this->out(__("Select an object type:", true));
$this->hr();

$keys = array();
foreach ($this->classTypes as $key => $option) {
$this->out(++$key . '. ' . $option);
$keys[] = $key;
}
$keys[] = 'q';
$selection = $this->in(__("Enter the type of object to bake a test for or (q)uit", true), $keys, 'q');
if ($selection == 'q') {
$this->_stop();
}
return $selection;
}

/**
* Writes File
*
Expand Down Expand Up @@ -276,6 +300,7 @@ function _processController(&$subject) {
$this->_processModel($subject->{$model});
}
}

/**
* Add classname to the fixture list.
* Sets the app. or plugin.plugin_name. prefix.
Expand Down
17 changes: 15 additions & 2 deletions cake/tests/cases/console/libs/tasks/test.test.php
Expand Up @@ -48,7 +48,7 @@
);
Mock::generatePartial(
'TestTask', 'MockTestTask',
array('in', 'out', 'createFile')
array('in', '_stop', 'err', 'out', 'createFile')
);

/**
Expand Down Expand Up @@ -192,7 +192,6 @@ function testFixtureArrayGenerationFromModel() {
'app.test_task_article', 'app.test_task_tag');

$this->assertEqual(sort($result), sort($expected));

}

/**
Expand All @@ -207,7 +206,21 @@ function testFixtureArrayGenerationFromController() {
'app.test_task_article', 'app.test_task_tag');

$this->assertEqual(sort($result), sort($expected));
}

/**
* test user interaction to get object type
*
* @return void
**/
function testGetObjectType() {
$this->Task->expectOnce('_stop');
$this->Task->setReturnValueAt(0, 'in', 'q');
$this->Task->getObjectType();

$this->Task->setReturnValueAt(1, 'in', 2);
$result = $this->Task->getObjectType();
$this->assertEqual($result, 2);
}
}
?>

0 comments on commit eb9f40c

Please sign in to comment.