Skip to content

Commit

Permalink
Don't modify app/Config/bootstrap when running tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Jun 13, 2012
1 parent f625742 commit 5413143
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
31 changes: 24 additions & 7 deletions lib/Cake/Console/Command/Task/PluginTask.php
Expand Up @@ -34,13 +34,21 @@ class PluginTask extends AppShell {
*/
public $path = null;

/**
* Path to the bootstrap file. Changed in tests.
*
* @var string
*/
public $bootstrap = null;

/**
* initialize
*
* @return void
*/
public function initialize() {
$this->path = current(App::path('plugins'));
$this->bootstrap = APP . 'Config' . DS . 'bootstrap.php';
}

/**
Expand Down Expand Up @@ -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', '<success>Created:</success> %s in %s', $plugin, $this->path . $plugin), 2);
Expand All @@ -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 comment has been minimized.

Copy link
@jrbasso

jrbasso Jun 18, 2012

Member

Shouldn't use $this->bootstrap here?

This comment has been minimized.

Copy link
@markstory

markstory Jun 18, 2012

Author Member

Yeah it probably should. I'll fix that.

$this->out('');
$this->out(__d('cake_dev', '%s modified', APP . 'Config' . DS . 'bootstrap.php'));
}
}

/**
* find and change $this->path to the user selection
*
Expand Down
14 changes: 14 additions & 0 deletions lib/Cake/Test/Case/Console/Command/Task/PluginTaskTest.php
Expand Up @@ -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) {
Expand All @@ -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()
*
Expand Down

0 comments on commit 5413143

Please sign in to comment.