?>

bake updates for 1.3

If you’ve been following the ongoing development of the 1.3 branch over at code.cakephp.org:http://code.cakephp.org. You may have noticed that bake has had a significant overhaul, and a number of features and enhancements have been built in.

  • Two new tasks (FixtureTask and TestTask) are accessible from the main bake menu
  • A third task (TemplateTask) has been added for use in your shells.
  • All the different bake tasks now allow you to use connections other than default for baking.
  • Plugin support has been greatly improved.
  • Questions have been clarified
  • Multiple validations on models has been added.
  • Fixtures and Tests can be baked separately.
  • Baked Tests include as many fixtures as they know about, including plugin detection (plugin detection does not work on PHP4).

So with the laundry list of features, we’ll take some time to look at some of the new commands, new parameters and updated features.

New FixtureTask, TestTask and TemplateTask.

Fixture and test baking were a bit of a pain in the past. You could only generate tests when baking the classes, and fixtures could only be generated when baking models. This made adding tests to your applications later or even regenerating fixtures with new schemas a bit painful. For 1.3 we’ve separated out Fixture and Test making them separate tasks. This allows you to re-run them and regenerate tests and fixtures at any point in your development process.

In addition to being rebuildable at any time, baked tests are now attempt to find as many fixtures as possible. In the past getting into testing often involved fighting through numerous ‘Missing Table’ errors. With more advanced fixture detection we hope to make testing easier and more accessible.

Test cases also generate skeleton test methods for every non-inherited public method in your classes. Saving you one extra step.

TemplateTask is a behind the scenes task, and it handles file generation from templates. In previous versions of CakePHP baked views were template based, but all other code was not. With 1.3 almost all the content in the files generated by bake are controlled by templates and the TemplateTask.

New bake commands.

New commands have been added to make baking easier and faster. Controller, Model, View baking all feature an all subcommand, that builds everything at once and makes speedy rebuilds easy.

Show Plain Text
cake bake model all

Would bake all the models for an application in one shot. Similarly cake bake controller all would bake all controllers and cake bake view all would generate all view files. Parameters on the ControllerTask have changed as well. cake bake controller scaffold is now cake bake controller public. ViewTask has had an -admin flag added, using -admin will allow you to bake views for actions that begin with Routing.admin

As mentioned before cake bake fixture and cake bake test are new, and have several subcommands each. cake bake fixture all will regenerate all the basic fixtures for your application. The -count parameter allows you to set the number of fake records that are created. By running fixture task interactively you can generate fixtures using the data in your live tables. You can use cake bake test <type> <class> to create test cases for already created objects in your app. Type should be one of the standard CakePHP types (‘component’, ‘controller’, ‘model’, ‘helper’, ‘behavior’) but doesn’t have to be. Class should be an existing object of the chosen type.

Templates Galore

New in bake for 1.3 is the addition of more templates. In 1.2 baked views used templates that could be changed to modify the view files bake generated. In 1.3 templates are used to generate all output from bake. There are separate templates for controllers, controller action sets, fixtures, models, test cases, and the view files from 1.2. As well as more templates, you can also have multiple template sets or, bake themes. Bake themes can be provided in your app, or as part of plugins. An example plugin path for bake theme would be app/plugins/bake_theme/vendors/shells/templates/dark_red/ You can look at cake/console/templates/default/ to see what directories and files are required of a bake theme. However, like view files, if your bake theme doesn’t implement a template, other installed themes will be checked until the correct template is found.

Additional plugin support.

New in 1.3 are additional ways to specify plugin names when using bake. In addition to cake bake plugin Todo controller Posts, there are two new forms. cake bake controller Todo.Posts and cake bake controller Posts -plugin Todo. The plugin parameter can be while using interactive bake as well. cake bake controller -plugin Todo, for example will allow you to use interactive bake to add controllers to your Todo plugin. Additional / multiple plugin paths are supported as well. In the past bake required your plugin to be in app/plugins. In 1.3 bake will find which of the pluginPaths the named plugin is located on, and add the files there.

Well I hope you find the enhancements to bake as useful and exciting as I do. I feel they make bake an even more powerful and flexible tool in the rapid development of your applications. Please note that this has also been added to the wiki over at code.cakephp.org as well.

Comments

Nice post, i love cakephp

mupet on 8/17/09

Can templates be stored in ‘cake/console/templates/*’?

Adam on 8/17/09

Thanks for incorporating ‘multiple validation rules per model field’ while baking, https://trac.cakephp.org/ticket/3959

Amit Badkas on 8/18/09

Adam, I am guessing we will be able to provide application templates at ‘app/vendors/shells/templates/’ rather than using the core ‘cake’ directory. Mark’s plugin example applies if you wish to distribute your work to the community.

deizel on 8/18/09

deizel: If by application templates you mean, providing a directory skeleton for baking new projects. Then yes, and this feature is not new to 1.3, in 1.2 you can specify a -skel param when baking projects to use a custom directory for the application skeleton.

mark story on 8/18/09

mark, you rule. what do you think about randomized fixture data? to me, even if it is minor, having randomized fixture data encourages tests to fail faster.

jon adams on 8/19/09

Im new to cake .. just jump over from CodeIgniter ..
i guess i need to read again the docs when the 1.3 is finish
>.<

oDiN on 8/21/09

Excellent!!!
I will hope better integration between the new JS ajax forms and validation.

Celso on 8/25/09

Based on these enhancements, I’m really tempted to start moving my current application development over to 1.3. Would you call it beta stable yet?

Barry on 9/25/09

I would consider 1.3 beta ready when the beta release is announced :) We’re working hard to make that happen as quick as possible. If you would like to help out please check the wiki at http://code.cakephp.org for a list of things that still need to be done.

mark story on 9/28/09

Comments are not open at this time.