mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Don't modify app/Config/bootstrap when running tests.
This commit is contained in:
parent
f625742a12
commit
5413143178
2 changed files with 38 additions and 7 deletions
|
@ -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 @@ class PluginTask extends AppShell {
|
|||
$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 @@ class PluginTask extends AppShell {
|
|||
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
|
||||
*
|
||||
|
|
|
@ -50,6 +50,8 @@ class PluginTaskTest extends CakeTestCase {
|
|||
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 @@ class PluginTaskTest extends CakeTestCase {
|
|||
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()
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue