io = $this->getMock('Cake\Console\ConsoleIo', [], [], '', false); $this->Task = $this->getMock('Cake\Shell\Task\UnloadTask', ['in', 'out', 'err', '_stop'], [$this->io]); $this->bootstrap = ROOT . DS . 'config' . DS . 'bootstrap.php'; $bootstrap = new File($this->bootstrap, false); $this->originalBootstrapContent = $bootstrap->read(); } /** * tearDown method * * @return void */ public function tearDown() { parent::tearDown(); unset($this->shell); Plugin::unload(); $bootstrap = new File($this->bootstrap, false); $bootstrap->write($this->originalBootstrapContent); } /** * testUnload * * @return void */ public function testUnload() { $bootstrap = new File($this->bootstrap, false); $this->_addPluginToBootstrap("TestPlugin"); $this->_addPluginToBootstrap("TestPluginSecond"); $expected = "Plugin::load('TestPlugin', ['autoload' => true, 'bootstrap' => false, 'routes' => false]);"; $this->assertContains($expected, $bootstrap->read()); $action = $this->Task->main('TestPlugin'); $this->assertTrue($action); $expected = "Plugin::load('TestPlugin', ['autoload' => true, 'bootstrap' => false, 'routes' => false]);"; $this->assertNotContains($expected, $bootstrap->read()); $expected = "Plugin::load('TestPluginSecond', ['autoload' => true, 'bootstrap' => false, 'routes' => false]);"; $this->assertContains($expected, $bootstrap->read()); } /** * _addPluginToBootstrap * * Quick method to add a plugin to the bootstrap file. * This is useful for the tests * * @param string $name */ protected function _addPluginToBootstrap($name) { $bootstrap = new File($this->bootstrap, false); $bootstrap->append("\nPlugin::load('$name', ['autoload' => true, 'bootstrap' => false, 'routes' => false]);"); } }