Browse Source

Adding tests for plugin shell auto aliasing

Jose Lorenzo Rodriguez 11 years ago
parent
commit
8f21eba7d5

+ 34 - 7
tests/TestCase/Console/ShellDispatcherTest.php

@@ -169,7 +169,7 @@ class ShellDispatcherTest extends TestCase {
 	}
 
 /**
- * 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
  */
@@ -182,15 +182,15 @@ class ShellDispatcherTest extends TestCase {
 
 		$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);
 	}
@@ -209,15 +209,42 @@ class ShellDispatcherTest extends TestCase {
 
 		$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);
 	}

+ 35 - 0
tests/test_app/Plugin/TestPlugin/src/Shell/SampleShell.php

@@ -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');
+	}
+}
+