Permalink
Browse files

Don't modify app/Config/bootstrap when running tests.

  • Loading branch information...
markstory committed Jun 13, 2012
1 parent f625742 commit 541314317897e24cddecdb7e83c56cf4f09c5339
@@ -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';
}
/**
@@ -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);
@@ -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");
@jrbasso

jrbasso Jun 18, 2012

Member

Shouldn't use $this->bootstrap here?

@markstory

markstory Jun 18, 2012

Owner

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
*
@@ -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()
*

0 comments on commit 5413143

Please sign in to comment.