Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding Fixture task to bake.

  • Loading branch information...
commit b5cc69c37c454e4152c5b93fb4ee40448bea5a8c 1 parent f7a7b07
@markstory markstory authored
Showing with 145 additions and 2 deletions.
  1. +6 −2 cake/console/libs/bake.php
  2. +139 −0 cake/console/libs/tasks/fixture.php
View
8 cake/console/libs/bake.php
@@ -40,7 +40,7 @@ class BakeShell extends Shell {
* @var array
* @access public
*/
- var $tasks = array('Project', 'DbConfig', 'Model', 'Controller', 'View', 'Plugin', 'Test');
+ var $tasks = array('Project', 'DbConfig', 'Model', 'Controller', 'View', 'Plugin', 'Fixture', 'Test');
/**
* Override loadTasks() to handle paths
*
@@ -49,7 +49,7 @@ class BakeShell extends Shell {
function loadTasks() {
parent::loadTasks();
$task = Inflector::classify($this->command);
- if (isset($this->{$task}) && !in_array($task, array('Project', 'DbConfig'))) {
+ if (isset($this->{$task}) && !in_array($task, array('Project', 'DbConfig', 'Fixture'))) {
$path = Inflector::underscore(Inflector::pluralize($this->command));
$this->{$task}->path = $this->params['working'] . DS . $path . DS;
if (!is_dir($this->{$task}->path)) {
@@ -82,6 +82,7 @@ function main() {
$this->out('[V]iew');
$this->out('[C]ontroller');
$this->out('[P]roject');
+ $this->out('[F]ixture');
$this->out('[Q]uit');
$classToBake = strtoupper($this->in(__('What would you like to Bake?', true), array('D', 'M', 'V', 'C', 'P', 'Q')));
@@ -101,6 +102,9 @@ function main() {
case 'P':
$this->Project->execute();
break;
+ case 'F':
+ $this->Fixture->execute();
+ break;
case 'Q':
exit(0);
break;
View
139 cake/console/libs/tasks/fixture.php
@@ -0,0 +1,139 @@
+<?php
+/* SVN FILE: $Id$ */
+/**
+ * The FixtureTest handles creating and updating fixture files.
+ *
+ * PHP versions 4 and 5
+ *
+ * CakePHP(tm) : Rapid Development Framework (http://www.cakephp.org)
+ * Copyright 2005-2008, Cake Software Foundation, Inc.
+ *
+ * Licensed under The MIT License
+ * Redistributions of files must retain the above copyright notice.
+ *
+ * @filesource
+ * @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
+ * @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
+ * @package cake
+ * @subpackage cake.cake.console.libs.tasks
+ * @since CakePHP(tm) v 1.3
+ * @version $Revision$
+ * @modifiedby $LastChangedBy$
+ * @lastmodified $Date$
+ * @license http://www.opensource.org/licenses/mit-license.php The MIT License
+ */
+/**
+ * Task class for creating and updating fixtures files.
+ *
+ * @package cake
+ * @subpackage cake.cake.console.libs.tasks
+ */
+class FixtureTask extends Shell {
+/**
+ * Name of plugin
+ *
+ * @var string
+ * @access public
+ */
+ var $plugin = null;
+/**
+ * Tasks to be loaded by this Task
+ *
+ * @var array
+ * @access public
+ */
+ var $tasks = array('Model');
+/**
+ * path to fixtures directory
+ *
+ * @var string
+ * @access public
+ */
+ var $path = null;
+/**
+ * Override initialize
+ *
+ * @access public
+ */
+ function initialize() {
+ $this->path = $this->params['working'] . DS . 'tests' . DS . 'fixtures' . DS;
+ }
+/**
+ * Execution method always used for tasks
+ *
+ * @access public
+ */
+ function execute() {
+ if (empty($this->args)) {
+ $this->__interactive();
+ }
+
+ if (isset($this->args[0])) {
+ if (strtolower($this->args[0]) == 'all') {
+ return $this->all();
+ }
+ $controller = Inflector::camelize($this->args[0]);
+ $actions = null;
+ if (isset($this->args[1]) && $this->args[1] == 'scaffold') {
+ $this->out('Baking scaffold for ' . $controller);
+ $actions = $this->bakeActions($controller);
+ } else {
+ $actions = 'scaffold';
+ }
+ if ($this->bake($controller, $actions)) {
+ if ($this->_checkUnitTest()) {
+ $this->bakeTest($controller);
+ }
+ }
+ }
+ }
+
+/**
+ * Bake All the Fixtures at once. Will only bake fixtures for models that exist.
+ *
+ * @access public
+ * @return void
+ **/
+ function all() {
+ $ds = 'default';
+ if (isset($this->params['connection'])) {
+ $ds = $this->params['connection'];
+ }
+ }
+
+/**
+ * Interactive baking function
+ *
+ * @access private
+ */
+ function __interactive($modelName = false) {
+
+ }
+
+/**
+ * Assembles and writes a Fixture file
+ *
+ * @return string Baked fixture
+ * @access private
+ */
+ function bake() {
+
+ }
+
+/**
+ * Displays help contents
+ *
+ * @access public
+ */
+ function help() {
+ $this->hr();
+ $this->out("Usage: cake bake fixture <arg1> <arg2>...");
+ $this->hr();
+ $this->out('Commands:');
+ $this->out("\n\fixture <name>\n\t\tbakes fixture with specified name.");
+ $this->out("\n\fixture all\n\t\tbakes all fixtures.");
+ $this->out("");
+ $this->_stop();
+ }
+}
+?>
Please sign in to comment.
Something went wrong with that request. Please try again.