Skip to content
Permalink
Browse files

Add routes.php generation to plugin bake.

Generating a routes.php file for plugins will help guide developers in
the right direction of putting routes in plugins. Also include some
default routes so people get off to a running start.
  • Loading branch information...
markstory committed Jul 3, 2014
1 parent 72ea665 commit c5eab6946f48a240c5c9fa2e8845e9b30c7bcce0
Showing with 27 additions and 5 deletions.
  1. +19 −1 src/Console/Command/Task/PluginTask.php
  2. +8 −4 tests/TestCase/Console/Command/Task/PluginTaskTest.php
@@ -141,6 +141,7 @@ public function bake($plugin) {
$this->createFile($this->path . $plugin . DS . $classBase . DS . 'Controller' . DS . $controllerFileName, $out);
$hasAutoloader = $this->_modifyAutoloader($plugin, $this->path);
$this->_generateRoutes($plugin, $this->path);
$this->_modifyBootstrap($plugin, $hasAutoloader);
$this->_generatePhpunitXml($plugin, $this->path);
$this->_generateTestBootstrap($plugin, $this->path);
@@ -166,7 +167,7 @@ protected function _modifyBootstrap($plugin, $hasAutoloader) {
if (!preg_match("@\n\s*Plugin::loadAll@", $contents)) {
$autoload = $hasAutoloader ? null : "'autoload' => true, ";
$bootstrap->append(sprintf(
"\nPlugin::load('%s', [%s'bootstrap' => false, 'routes' => false]);\n",
"\nPlugin::load('%s', [%s'bootstrap' => false, 'routes' => true]);\n",
$plugin,
$autoload
));
@@ -175,6 +176,23 @@ protected function _modifyBootstrap($plugin, $hasAutoloader) {
}
}
/**
* Generate a routes file for the plugin being baked.
*
* @param string $plugin The plugin to generate routes for.
* @param string $path The path to save the routes.php file in.
* @return void
*/
protected function _generateRoutes($plugin, $path) {
$this->Template->set([
'plugin' => $plugin,
]);
$this->out( __d('cake_console', 'Generating routes.php file...'));
$out = $this->Template->generate('config', 'routes');
$file = $path . $plugin . DS . 'Config' . DS . 'routes.php';
$this->createFile($file, $out);
}
/**
* Generate a phpunit.xml stub for the plugin.
*
@@ -144,13 +144,17 @@ public function testExecuteWithOneArg() {
$this->Task->expects($this->at(1))->method('createFile')
->with($file, $this->stringContains('class AppController extends BaseController {'));
$file = $path . DS . 'phpunit.xml';
$file = $path . DS . 'Config' . DS . 'routes.php';
$this->Task->expects($this->at(2))->method('createFile')
->with($file, new \PHPUnit_Framework_Constraint_IsAnything());
->with($file, $this->stringContains("Router::plugin('BakeTestPlugin', function(\$routes)"));
$file = $path . DS . 'tests' . DS . 'bootstrap.php';
$file = $path . DS . 'phpunit.xml';
$this->Task->expects($this->at(3))->method('createFile')
->with($file, new \PHPUnit_Framework_Constraint_IsAnything());
->with($file, $this->anything());
$file = $path . DS . 'tests' . DS . 'bootstrap.php';
$this->Task->expects($this->at(4))->method('createFile')
->with($file, $this->anything());
$this->Task->main('BakeTestPlugin');

0 comments on commit c5eab69

Please sign in to comment.
You can’t perform that action at this time.