Skip to content

Commit

Permalink
Adding tests for plugin shell auto aliasing
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Sep 13, 2014
1 parent e7357f9 commit 8f21eba
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 7 deletions.
41 changes: 34 additions & 7 deletions tests/TestCase/Console/ShellDispatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public function testDispatchShellWithoutMain() {
}

/**
* Verify you can dispatch a plugin's main shell with the plugin name alone
* Verify you can dispatch a plugin's main shell with the shell name alone
*
* @return void
*/
Expand All @@ -182,15 +182,15 @@ public function testDispatchShortPluginAlias() {

$dispatcher->expects($this->at(1))
->method('_shellExists')
->with('TestPlugin.TestPlugin')
->with('TestPlugin.Example')
->will($this->returnValue('TestPlugin\Console\Command\TestPluginShell'));

$dispatcher->expects($this->at(2))
->method('_createShell')
->with('TestPlugin\Console\Command\TestPluginShell', 'TestPlugin.TestPlugin')
->with('TestPlugin\Console\Command\TestPluginShell', 'TestPlugin.Example')
->will($this->returnValue($Shell));

$dispatcher->args = array('test_plugin');
$dispatcher->args = array('example');
$result = $dispatcher->dispatch();
$this->assertEquals(1, $result);
}
Expand All @@ -209,15 +209,42 @@ public function testDispatchShortPluginAliasCamelized() {

$dispatcher->expects($this->at(1))
->method('_shellExists')
->with('TestPlugin.TestPlugin')
->with('TestPlugin.Example')
->will($this->returnValue('TestPlugin\Console\Command\TestPluginShell'));

$dispatcher->expects($this->at(2))
->method('_createShell')
->with('TestPlugin\Console\Command\TestPluginShell', 'TestPlugin.TestPlugin')
->with('TestPlugin\Console\Command\TestPluginShell', 'TestPlugin.Example')
->will($this->returnValue($Shell));

$dispatcher->args = ['TestPlugin'];
$dispatcher->args = ['Example'];
$result = $dispatcher->dispatch();
$this->assertEquals(1, $result);
}

/**
* Verify that in case of conflict, app shells take precedence in alias list
*
* @return void
*/
public function testDispatchShortPluginAliasConflict() {
$dispatcher = $this->getMock(
'Cake\Console\ShellDispatcher',
['_shellExists', '_createShell']
);
$Shell = $this->getMock('Cake\Console\Shell');

$dispatcher->expects($this->at(1))
->method('_shellExists')
->with('Sample')
->will($this->returnValue('App\Shell\SampleShell'));

$dispatcher->expects($this->at(2))
->method('_createShell')
->with('App\Shell\SampleShell', 'Sample')
->will($this->returnValue($Shell));

$dispatcher->args = array('sample');
$result = $dispatcher->dispatch();
$this->assertEquals(1, $result);
}
Expand Down
35 changes: 35 additions & 0 deletions tests/test_app/Plugin/TestPlugin/src/Shell/SampleShell.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?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
*/

/**
* Class SampleShell
*
*/
namespace TestPlugin\Shell;

use Cake\Console\Shell;

class SampleShell extends Shell {

/**
* main method
*
* @return void
*/
public function main() {
$this->out('This is the main method called from SampleShell');
}
}

0 comments on commit 8f21eba

Please sign in to comment.