diff --git a/lib/Cake/Console/Command/Task/PluginTask.php b/lib/Cake/Console/Command/Task/PluginTask.php index 4ca79815a29..90d5474aceb 100644 --- a/lib/Cake/Console/Command/Task/PluginTask.php +++ b/lib/Cake/Console/Command/Task/PluginTask.php @@ -34,6 +34,13 @@ class PluginTask extends AppShell { */ public $path = null; +/** + * Path to the bootstrap file. Changed in tests. + * + * @var string + */ + public $bootstrap = null; + /** * initialize * @@ -41,6 +48,7 @@ class PluginTask extends AppShell { */ public function initialize() { $this->path = current(App::path('plugins')); + $this->bootstrap = APP . 'Config' . DS . 'bootstrap.php'; } /** @@ -148,13 +156,7 @@ public function bake($plugin) { $out .= "}\n\n"; $this->createFile($this->path . $plugin . DS . 'Model' . DS . $modelFileName, $out); - $bootstrap = new File(APP . 'Config' . DS . 'bootstrap.php', false); - $contents = $bootstrap->read(); - if (!preg_match("@\n\s*CakePlugin::loadAll@", $contents)) { - $bootstrap->append("\nCakePlugin::load('$plugin', array('bootstrap' => false, 'routes' => false));\n"); - $this->out(''); - $this->out(__d('cake_dev', '%s modified', APP . 'Config' . DS . 'bootstrap.php')); - } + $this->_modifyBootstrap($plugin); $this->hr(); $this->out(__d('cake_console', 'Created: %s in %s', $plugin, $this->path . $plugin), 2); @@ -163,6 +165,21 @@ public function bake($plugin) { return true; } +/** + * Update the app's bootstrap.php file. + * + * @return void + */ + protected function _modifyBootstrap($plugin) { + $bootstrap = new File($this->bootstrap, false); + $contents = $bootstrap->read(); + if (!preg_match("@\n\s*CakePlugin::loadAll@", $contents)) { + $bootstrap->append("\nCakePlugin::load('$plugin', array('bootstrap' => false, 'routes' => false));\n"); + $this->out(''); + $this->out(__d('cake_dev', '%s modified', APP . 'Config' . DS . 'bootstrap.php')); + } + } + /** * find and change $this->path to the user selection * diff --git a/lib/Cake/Test/Case/Console/Command/Task/PluginTaskTest.php b/lib/Cake/Test/Case/Console/Command/Task/PluginTaskTest.php index 3a02a04792d..28f06cc9c5c 100644 --- a/lib/Cake/Test/Case/Console/Command/Task/PluginTaskTest.php +++ b/lib/Cake/Test/Case/Console/Command/Task/PluginTaskTest.php @@ -50,6 +50,8 @@ public function setUp() { array($this->out, $this->out, $this->in) ); $this->Task->path = TMP . 'tests' . DS; + $this->Task->bootstrap = TMP . 'tests' . DS . 'bootstrap.php'; + touch($this->Task->bootstrap); $this->_paths = $paths = App::path('plugins'); foreach ($paths as $i => $p) { @@ -61,6 +63,18 @@ public function setUp() { App::build(array('plugins' => $paths)); } +/** + * tearDown() + * + * @return void + */ + public function tearDown() { + if (file_exists($this->Task->bootstrap)) { + unlink($this->Task->bootstrap); + } + parent::tearDown(); + } + /** * test bake() *