Skip to content

Commit

Permalink
Fixing path generation in BakeTask.
Browse files Browse the repository at this point in the history
Removing name properties as they were causing troubles.
All BakeTasks are now interactive = false by default.  This makes interfaces more consistent when working with bake.  Refs #423
Tests updated.
  • Loading branch information
markstory committed Mar 5, 2010
1 parent 01ea34f commit d4393e9
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 36 deletions.
16 changes: 9 additions & 7 deletions cake/console/libs/tasks/bake.php
Expand Up @@ -18,12 +18,6 @@
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
class BakeTask extends Shell {
/**
* Name attribute, used in path generation.
*
* @var string
*/
var $name = null;

/**
* Name of plugin
Expand All @@ -41,6 +35,13 @@ class BakeTask extends Shell {
*/
var $connection = null;

/**
* Flag for interactive mode
*
* @var boolean
*/
var $interactive = false;

/**
* Gets the path for output. Checks the plugin property
* and returns the correct path.
Expand All @@ -51,7 +52,8 @@ class BakeTask extends Shell {
function getPath() {
$path = $this->path;
if (isset($this->plugin)) {
$path = $this->_pluginPath($this->plugin) . Inflector::pluralize(Inflector::underscore($this->name)) . DS;
$name = substr($this->name, 0, strlen($this->name) - 4);
$path = $this->_pluginPath($this->plugin) . Inflector::pluralize(Inflector::underscore($name)) . DS;
}
return $path;
}
Expand Down
2 changes: 0 additions & 2 deletions cake/console/libs/tasks/controller.php
Expand Up @@ -28,8 +28,6 @@
*/
class ControllerTask extends BakeTask {

var $name = 'Controller';

/**
* Tasks to be loaded by this Task
*
Expand Down
18 changes: 14 additions & 4 deletions cake/console/libs/tasks/fixture.php
Expand Up @@ -222,10 +222,7 @@ function generateFixtureFile($model, $otherVars) {
$defaults = array('table' => null, 'schema' => null, 'records' => null, 'import' => null, 'fields' => null);
$vars = array_merge($defaults, $otherVars);

$path = $this->path;
if (isset($this->plugin)) {
$path = $this->_pluginPath($this->plugin) . 'tests' . DS . 'fixtures' . DS;
}
$path = $this->getPath();
$filename = Inflector::underscore($model) . '_fixture.php';

$this->Template->set('model', $model);
Expand All @@ -237,6 +234,19 @@ function generateFixtureFile($model, $otherVars) {
return $content;
}

/**
* Get the path to the fixtures.
*
* @return void
*/
function getPath() {
$path = $this->path;
if (isset($this->plugin)) {
$path = $this->_pluginPath($this->plugin) . 'tests' . DS . 'fixtures' . DS;
}
return $path;
}

/**
* Generates a string representation of a schema.
*
Expand Down
2 changes: 0 additions & 2 deletions cake/console/libs/tasks/model.php
Expand Up @@ -28,8 +28,6 @@
*/
class ModelTask extends BakeTask {

var $name = 'Model';

/**
* path to MODELS directory
*
Expand Down
23 changes: 4 additions & 19 deletions cake/console/libs/tasks/test.php
Expand Up @@ -18,21 +18,15 @@
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/

include_once dirname(__FILE__) . DS . 'bake.php';

/**
* Task class for creating and updating test files.
*
* @package cake
* @subpackage cake.cake.console.libs.tasks
*/
class TestTask extends Shell {

/**
* Name of plugin
*
* @var string
* @access public
*/
var $plugin = null;
class TestTask extends BakeTask {

/**
* path to TESTS directory
Expand Down Expand Up @@ -66,12 +60,6 @@ class TestTask extends Shell {
*/
var $_fixtures = array();

/**
* Flag for interactive mode
*
* @var boolean
*/
var $interactive = false;

/**
* Execution method always used for tasks
Expand Down Expand Up @@ -434,10 +422,7 @@ function generateConstructor($type, $fullClassName) {
* @access public
*/
function testCaseFileName($type, $className) {
$path = $this->path;
if (isset($this->plugin)) {
$path = $this->_pluginPath($this->plugin) . 'tests' . DS;
}
$path = $this->getPath();;
$path .= 'cases' . DS . Inflector::tableize($type) . DS;
if (strtolower($type) == 'controller') {
$className = $this->getRealClassName($type, $className);
Expand Down
2 changes: 0 additions & 2 deletions cake/console/libs/tasks/view.php
Expand Up @@ -28,8 +28,6 @@
*/
class ViewTask extends BakeTask {

var $name = 'View';

/**
* Tasks to be loaded by this Task
*
Expand Down
2 changes: 2 additions & 0 deletions cake/tests/cases/console/libs/tasks/controller.test.php
Expand Up @@ -101,6 +101,7 @@ class ControllerTaskTest extends CakeTestCase {
function startTest() {
$this->Dispatcher =& new TestControllerTaskMockShellDispatcher();
$this->Task =& new MockControllerTask($this->Dispatcher);
$this->Task->name = 'ControllerTask';
$this->Task->Dispatch =& $this->Dispatcher;
$this->Task->Dispatch->shellPaths = App::path('shells');
$this->Task->Template =& new TemplateTask($this->Task->Dispatch);
Expand Down Expand Up @@ -158,6 +159,7 @@ function testListAll() {
* @access public
*/
function testGetName() {
$this->Task->interactive = true;
$this->Task->setReturnValue('in', 1);

$this->Task->setReturnValueAt(0, 'in', 'q');
Expand Down
1 change: 1 addition & 0 deletions cake/tests/cases/console/libs/tasks/fixture.test.php
Expand Up @@ -142,6 +142,7 @@ function testImportOptions() {
* @access public
*/
function testImportRecordsFromDatabaseWithConditions() {
$this->Task->interactive = true;
$this->Task->setReturnValueAt(0, 'in', 'WHERE 1=1 LIMIT 10');
$this->Task->connection = 'test_suite';
$this->Task->path = '/my/path/';
Expand Down
2 changes: 2 additions & 0 deletions cake/tests/cases/console/libs/tasks/model.test.php
Expand Up @@ -78,6 +78,8 @@ class ModelTaskTest extends CakeTestCase {
function startTest() {
$this->Dispatcher =& new TestModelTaskMockShellDispatcher();
$this->Task =& new MockModelTask($this->Dispatcher);
$this->Task->name = 'ModelTask';
$this->Task->interactive = true;
$this->Task->Dispatch =& $this->Dispatcher;
$this->Task->Dispatch->shellPaths = App::path('shells');
$this->Task->Template =& new TemplateTask($this->Task->Dispatch);
Expand Down
1 change: 1 addition & 0 deletions cake/tests/cases/console/libs/tasks/test.test.php
Expand Up @@ -265,6 +265,7 @@ function startTest() {
$this->Dispatcher =& new TestTestTaskMockShellDispatcher();
$this->Dispatcher->shellPaths = App::path('shells');
$this->Task =& new MockTestTask($this->Dispatcher);
$this->Task->name = 'TestTask';
$this->Task->Dispatch =& $this->Dispatcher;
$this->Task->Template =& new TemplateTask($this->Dispatcher);
}
Expand Down
1 change: 1 addition & 0 deletions cake/tests/cases/console/libs/tasks/view.test.php
Expand Up @@ -255,6 +255,7 @@ function startTest() {
$this->Dispatcher =& new TestViewTaskMockShellDispatcher();
$this->Dispatcher->shellPaths = App::path('shells');
$this->Task =& new MockViewTask($this->Dispatcher);
$this->Task->name = 'ViewTask';
$this->Task->Dispatch =& $this->Dispatcher;
$this->Task->Template =& new TemplateTask($this->Dispatcher);
$this->Task->Controller =& new ViewTaskMockControllerTask();
Expand Down

0 comments on commit d4393e9

Please sign in to comment.