diff --git a/tests/TestCase/Shell/Task/UnloadTaskTest.php b/tests/TestCase/Shell/Task/UnloadTaskTest.php index adee9991770..70bcdf719e7 100644 --- a/tests/TestCase/Shell/Task/UnloadTaskTest.php +++ b/tests/TestCase/Shell/Task/UnloadTaskTest.php @@ -13,19 +13,25 @@ */ namespace Cake\Test\TestCase\Shell\Task; +use Cake\Console\Shell; use Cake\Core\Plugin; use Cake\Filesystem\File; -use Cake\TestSuite\TestCase; +use Cake\TestSuite\ConsoleIntegrationTestCase; /** * UnloadTaskTest class */ -class UnloadTaskTest extends TestCase +class UnloadTaskTest extends ConsoleIntegrationTestCase { /** - * @var \Cake\Shell\Task\UnloadTask|\PHPUnit_Framework_MockObject_MockObject + * @var string */ - protected $Task; + protected $bootstrap; + + /** + * @var string + */ + protected $originalBootstrapContent; /** * setUp method @@ -35,20 +41,9 @@ class UnloadTaskTest extends TestCase public function setUp() { parent::setUp(); - - $this->io = $this->getMockBuilder('Cake\Console\ConsoleIo') - ->disableOriginalConstructor() - ->getMock(); - - $this->Task = $this->getMockBuilder('Cake\Shell\Task\UnloadTask') - ->setMethods(['in', 'out', 'err', '_stop']) - ->setConstructorArgs([$this->io]) - ->getMock(); - $this->bootstrap = ROOT . DS . 'config' . DS . 'bootstrap.php'; $bootstrap = new File($this->bootstrap, false); - $this->originalBootstrapContent = $bootstrap->read(); } @@ -63,9 +58,7 @@ public function tearDown() unset($this->shell); Plugin::unload(); - $bootstrap = new File($this->bootstrap, false); - - $bootstrap->write($this->originalBootstrapContent); + file_put_contents($this->bootstrap, $this->originalBootstrapContent); } /** @@ -75,110 +68,100 @@ public function tearDown() */ public function testUnload() { - $bootstrap = new File($this->bootstrap, false); - $this->_addPluginToBootstrap('TestPlugin'); - $this->_addPluginToBootstrap('TestPluginSecond'); + $contents = file_get_contents($this->bootstrap); $expected = "Plugin::load('TestPlugin', ['autoload' => true, 'bootstrap' => false, 'routes' => false]);"; - $this->assertContains($expected, $bootstrap->read()); + $this->assertContains($expected, $contents); - $this->Task->params = [ - 'cli' => false - ]; + $this->exec('plugin unload TestPlugin'); - $action = $this->Task->main('TestPlugin'); + $this->assertExitCode(Shell::CODE_SUCCESS); + $contents = file_get_contents($this->bootstrap); - $this->assertTrue($action); $expected = "Plugin::load('TestPlugin', ['autoload' => true, 'bootstrap' => false, 'routes' => false]);"; - $this->assertNotContains($expected, $bootstrap->read()); + + $this->assertNotContains($expected, $contents); $expected = "Plugin::load('TestPluginSecond', ['autoload' => true, 'bootstrap' => false, 'routes' => false]);"; - $this->assertContains($expected, $bootstrap->read()); + $this->assertContains($expected, $contents); + } + + /** + * Data provider for various forms. + * + * @return array + */ + public function variantProvider() + { + return [ + // Plugin::load('TestPlugin', [ + // 'bootstrap' => false + // ]); + ["\nPlugin::load('TestPlugin', [\n\t'bootstrap' => false\n]);\n"], + + // Plugin::load( + // 'TestPlugin', + // [ 'bootstrap' => false] + // ); + ["\nPlugin::load(\n\t'TestPlugin',\n\t[ 'bootstrap' => false]\n);\n"], + + // Plugin::load( + // 'Foo', + // [ + // 'bootstrap' => false + // ] + // ); + ["\nPlugin::load(\n\t'TestPlugin',\n\t[\n\t\t'bootstrap' => false\n\t]\n);\n"], + + // Plugin::load('Test', [ + // 'autoload' => false, + // 'bootstrap' => true, + // 'routes' => true + // ]); + ["\nPlugin::load('TestPlugin', [\n\t'autoload' => false,\n\t'bootstrap' => true,\n\t'routes' => true\n]);\n"], + + // Plugin::load('Test', + // [ + // 'bootstrap' => true, + // 'routes' => true + // ] + // ); + ["\nPlugin::load('TestPlugin',\n\t[\n\t\t'bootstrap' => true,\n\t\t'routes' => true\n\t]\n);\n"], + + // Plugin::load('Test', + // [ + // + // ] + // ); + ["\nPlugin::load('TestPlugin',\n\t[\n\t\n\t]\n);\n"], + + // Plugin::load('Test'); + ["\nPlugin::load('TestPlugin');\n"], + + // Plugin::load('Test', ['bootstrap' => true, 'route' => false]); + ["\nPlugin::load('TestPlugin', ['bootstrap' => true, 'route' => false]);\n"], + ]; } /** * testRegularExpressions * * This method will tests multiple notations of plugin loading. + * + * @dataProvider variantProvider + * @return void */ - public function testRegularExpressions() + public function testRegularExpressions($content) { $bootstrap = new File($this->bootstrap, false); + $bootstrap->append($content); - $this->Task->params = [ - 'cli' => false - ]; + $this->exec('plugin unload TestPlugin'); + $this->assertExitCode(Shell::CODE_SUCCESS); - // Plugin::load('TestPlugin', [ - // 'bootstrap' => false - // ]); - $bootstrap->append("\nPlugin::load('TestPlugin', [\n\t'bootstrap' => false\n]);\n"); - $this->Task->main('TestPlugin'); - $this->assertNotContains("Plugin::load('TestPlugin', [\n\t'bootstrap' => false\n]);", $bootstrap->read()); - $this->_clearBootstrap(); - - // Plugin::load( - // 'TestPlugin', - // [ 'bootstrap' => false] - // ); - $bootstrap->append("\nPlugin::load(\n\t'TestPlugin',\n\t[ 'bootstrap' => false]\n);\n"); - $this->Task->main('TestPlugin'); - $this->assertNotContains("Plugin::load(\n\t'TestPlugin',\n\t[ 'bootstrap' => false]\n);", $bootstrap->read()); - $this->_clearBootstrap(); - - // Plugin::load( - // 'Foo', - // [ - // 'bootstrap' => false - // ] - // ); - $bootstrap->append("\nPlugin::load(\n\t'TestPlugin',\n\t[\n\t\t'bootstrap' => false\n\t]\n);\n"); - $this->Task->main('TestPlugin'); - $this->assertNotContains("Plugin::load(\n\t'TestPlugin',\n\t[\n\t\t'bootstrap' => false\n\t]\n);", $bootstrap->read()); - $this->_clearBootstrap(); - - // Plugin::load('Test', [ - // 'autoload' => false, - // 'bootstrap' => true, - // 'routes' => true - // ]); - $bootstrap->append("\nPlugin::load('TestPlugin', [\n\t'autoload' => false,\n\t'bootstrap' => true,\n\t'routes' => true\n]);\n"); - $this->Task->main('TestPlugin'); - $this->assertNotContains("Plugin::load('TestPlugin', [\n\t'autoload' => false,\n\t'bootstrap' => true,\n\t'routes' => true\n]);", $bootstrap->read()); - $this->_clearBootstrap(); - - // Plugin::load('Test', - // [ - // 'bootstrap' => true, - // 'routes' => true - // ] - // ); - $bootstrap->append("\nPlugin::load('TestPlugin',\n\t[\n\t\t'bootstrap' => true,\n\t\t'routes' => true\n\t]\n);\n"); - $this->Task->main('TestPlugin'); - $this->assertNotContains("Plugin::load('TestPlugin',\n\t[\n\t\t'bootstrap' => true,\n\t\t'routes' => true\n\t]\n);", $bootstrap->read()); - $this->_clearBootstrap(); - - // Plugin::load('Test', - // [ - // - // ] - // ); - $bootstrap->append("\nPlugin::load('TestPlugin',\n\t[\n\t\n\t]\n);\n"); - $this->Task->main('TestPlugin'); - $this->assertNotContains("Plugin::load('TestPlugin',\n\t[\n\t\n\t]\n);", $bootstrap->read()); - $this->_clearBootstrap(); - - // Plugin::load('Test'); - $bootstrap->append("\nPlugin::load('TestPlugin');\n"); - $this->Task->main('TestPlugin'); - $this->assertNotContains("Plugin::load('TestPlugin');", $bootstrap->read()); - $this->_clearBootstrap(); - - // Plugin::load('Test', ['bootstrap' => true, 'route' => false]); - $bootstrap->append("\nPlugin::load('TestPlugin', ['bootstrap' => true, 'route' => false]);\n"); - $this->Task->main('TestPlugin'); - $this->assertNotContains("Plugin::load('TestPlugin', ['bootstrap' => true, 'route' => false]);", $bootstrap->read()); + $result = $bootstrap->read(); + $this->assertNotRegexp("/Plugin\:\:load\([\'\"]TestPlugin'[\'\"][^\)]*\)\;/mi", $result); } /** @@ -194,18 +177,4 @@ protected function _addPluginToBootstrap($name) $bootstrap = new File($this->bootstrap, false); $bootstrap->append("\n\nPlugin::load('$name', ['autoload' => true, 'bootstrap' => false, 'routes' => false]);\n"); } - - /** - * clearBootstrap - * - * Helper to clear the bootstrap file. - * - * @return void - */ - protected function _clearBootstrap() - { - $bootstrap = new File($this->bootstrap, false); - - $bootstrap->write($this->originalBootstrapContent); - } }