Permalink
Browse files

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

  • Loading branch information...
1 parent f625742 commit 541314317897e24cddecdb7e83c56cf4f09c5339 @markstory markstory committed Jun 13, 2012
@@ -35,12 +35,20 @@ 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);
@@ -164,6 +166,21 @@ public function bake($plugin) {
}
/**
+ * 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'));
@jrbasso
jrbasso Jun 18, 2012 Member

Shouldn't use $this->bootstrap here?

@markstory
markstory Jun 18, 2012 Member

Yeah it probably should. I'll fix that.

+ }
+ }
+
+/**
* find and change $this->path to the user selection
*
* @param array $pathOptions
@@ -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) {
@@ -62,6 +64,18 @@ public function setUp() {
}
/**
+ * tearDown()
+ *
+ * @return void
+ */
+ public function tearDown() {
+ if (file_exists($this->Task->bootstrap)) {
+ unlink($this->Task->bootstrap);
+ }
+ parent::tearDown();
+ }
+
+/**
* test bake()
*
* @return void

0 comments on commit 5413143

Please sign in to comment.