Permalink
Browse files

Fixing path generation in BakeTask.

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...
1 parent 01ea34f commit d4393e90580280972baae18a5f9722cdb12fd47a @markstory markstory committed Mar 5, 2010
@@ -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
@@ -42,6 +36,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.
*
@@ -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;
}
@@ -28,8 +28,6 @@
*/
class ControllerTask extends BakeTask {
- var $name = 'Controller';
-
/**
* Tasks to be loaded by this Task
*
@@ -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);
@@ -238,6 +235,19 @@ function generateFixtureFile($model, $otherVars) {
}
/**
+ * 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.
*
* @param array $table Table schema array
@@ -28,8 +28,6 @@
*/
class ModelTask extends BakeTask {
- var $name = 'Model';
-
/**
* path to MODELS directory
*
@@ -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
@@ -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
@@ -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);
@@ -28,8 +28,6 @@
*/
class ViewTask extends BakeTask {
- var $name = 'View';
-
/**
* Tasks to be loaded by this Task
*
@@ -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);
@@ -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');
@@ -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/';
@@ -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);
@@ -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);
}
@@ -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();

0 comments on commit d4393e9

Please sign in to comment.