Skip to content

Commit

Permalink
Merge pull request #6043 from cakephp/3.0-plugin-shell
Browse files Browse the repository at this point in the history
3.0 plugin shell
  • Loading branch information
ADmad committed Mar 10, 2015
2 parents fe728d7 + c2a6f42 commit 7ecd991
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 19 deletions.
51 changes: 51 additions & 0 deletions src/Shell/PluginShell.php
@@ -0,0 +1,51 @@
<?php
/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @since 3.0.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace Cake\Shell;

use Cake\Console\Shell;

/**
* Shell for tasks related to plugins.
*
*/
class PluginShell extends Shell
{

/**
* Contains tasks to load and instantiate
*
* @var array
*/
public $tasks = ['Assets'];

/**
* Gets the option parser instance and configures it.
*
* @return \Cake\Console\ConsoleOptionParser
*/
public function getOptionParser()
{
$parser = parent::getOptionParser();

$parser->description(
'Plugin Shell perform various tasks related to plugin.'
)->addSubcommand('assets', [
'help' => 'Symlink / copy plugin assets to app\'s webroot',
'parser' => $this->Assets->getOptionParser()
]);

return $parser;
}
}
Expand Up @@ -12,18 +12,18 @@
* @since 3.0.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace Cake\Shell;
namespace Cake\Shell\Task;

use Cake\Console\Shell;
use Cake\Core\Plugin;
use Cake\Filesystem\Folder;
use Cake\Utility\Inflector;

/**
* Shell for symlinking / copying plugin assets to app's webroot.
* Task for symlinking / copying plugin assets to app's webroot.
*
*/
class PluginAssetsShell extends Shell
class AssetsTask extends Shell
{

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Shell/CommandListShellTest.php
Expand Up @@ -99,7 +99,7 @@ public function testMain()
$expected = "/\[.*TestPluginTwo.*\] example, welcome/";
$this->assertRegExp($expected, $output);

$expected = "/\[.*CORE.*\] i18n, orm_cache, plugin_assets, server/";
$expected = "/\[.*CORE.*\] i18n, orm_cache, plugin, server/";
$this->assertRegExp($expected, $output);

$expected = "/\[.*app.*\] sample/";
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Shell/CompletionShellTest.php
Expand Up @@ -120,7 +120,7 @@ public function testCommands()
$output = $this->out->output;

$expected = "TestPlugin.example TestPlugin.sample " .
"TestPluginTwo.example TestPluginTwo.welcome i18n orm_cache plugin_assets server sample\n";
"TestPluginTwo.example TestPluginTwo.welcome i18n orm_cache plugin server sample\n";
$this->assertTextEquals($expected, $output);
}

Expand Down
Expand Up @@ -12,20 +12,20 @@
* @since 3.0.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace Cake\Test\TestCase\Shell;
namespace Cake\Test\TestCase\Shell\Task;

use Cake\Core\App;
use Cake\Core\Configure;
use Cake\Core\Plugin;
use Cake\Filesystem\Folder;
use Cake\Shell\PluginAssetsTask;
use Cake\Shell\Task\AssetsTask;
use Cake\TestSuite\TestCase;

/**
* PluginAssetsShellTest class
* AssetsTaskTest class
*
*/
class PluginAssetsShellTest extends TestCase
class AssetsTaskTest extends TestCase
{

/**
Expand All @@ -39,13 +39,13 @@ public function setUp()

$this->skipIf(
DS === '\\',
'Skip PluginAssetsShell tests on windows to prevent side effects for UrlHelper tests on AppVeyor.'
'Skip AssetsTask tests on windows to prevent side effects for UrlHelper tests on AppVeyor.'
);

$this->io = $this->getMock('Cake\Console\ConsoleIo', [], [], '', false);

$this->shell = $this->getMock(
'Cake\Shell\PluginAssetsShell',
$this->Task = $this->getMock(
'Cake\Shell\Task\AssetsTask',
['in', 'out', 'err', '_stop'],
[$this->io]
);
Expand All @@ -59,7 +59,7 @@ public function setUp()
public function tearDown()
{
parent::tearDown();
unset($this->shell);
unset($this->Task);
Plugin::unload();
}

Expand All @@ -73,7 +73,7 @@ public function testSymlink()
Plugin::load('TestPlugin');
Plugin::load('Company/TestPluginThree');

$this->shell->symlink();
$this->Task->symlink();

$path = WWW_ROOT . 'test_plugin';
$link = new \SplFileInfo($path);
Expand Down Expand Up @@ -109,7 +109,7 @@ public function testSymlinkWhenVendorDirectoryExits()

mkdir(WWW_ROOT . 'company');

$this->shell->symlink();
$this->Task->symlink();
$path = WWW_ROOT . 'company' . DS . 'test_plugin_three';
$link = new \SplFileInfo($path);
if (DS === '\\') {
Expand All @@ -132,7 +132,7 @@ public function testSymlinkWhenTargetAlreadyExits()
Plugin::load('TestTheme');

$shell = $this->getMock(
'Cake\Shell\PluginAssetsShell',
'Cake\Shell\Task\AssetsTask',
['in', 'out', 'err', '_stop', '_createSymlink', '_copyDirectory'],
[$this->io]
);
Expand All @@ -153,7 +153,7 @@ public function testForPluginWithoutWebroot()
{
Plugin::load('TestPluginTwo');

$this->shell->symlink();
$this->Task->symlink();
$this->assertFalse(file_exists(WWW_ROOT . 'test_plugin_two'));
}

Expand All @@ -167,7 +167,7 @@ public function testSymlinkingSpecifiedPlugin()
Plugin::load('TestPlugin');
Plugin::load('Company/TestPluginThree');

$this->shell->symlink('TestPlugin');
$this->Task->symlink('TestPlugin');

$path = WWW_ROOT . 'test_plugin';
$link = new \SplFileInfo($path);
Expand All @@ -190,7 +190,7 @@ public function testCopy()
Plugin::load('TestPlugin');
Plugin::load('Company/TestPluginThree');

$this->shell->copy();
$this->Task->copy();

$path = WWW_ROOT . 'test_plugin';
$dir = new \SplFileInfo($path);
Expand Down

0 comments on commit 7ecd991

Please sign in to comment.