diff --git a/src/Shell/Task/PluginTask.php b/src/Shell/Task/PluginTask.php index 44d0509bf..e3617a7bb 100644 --- a/src/Shell/Task/PluginTask.php +++ b/src/Shell/Task/PluginTask.php @@ -152,10 +152,21 @@ protected function _modifyBootstrap($plugin, $hasAutoloader) */ protected function _generateFiles($pluginName, $path) { + $namespace = str_replace('/', '\\', $pluginName); + + $name = $pluginName; + $vendor = 'your-name-here'; + if (strpos($pluginName, '/') !== false) { + list($vendor, $name) = explode('/', $pluginName); + } + $package = $vendor . '/' . $name; + $this->BakeTemplate->set([ + 'package' => $package, + 'namespace' => $namespace, 'plugin' => $pluginName, 'path' => $path, - 'root' => ROOT + 'root' => ROOT, ]); $root = $path . $pluginName . DS; diff --git a/src/Template/Bake/Plugin/README.md.ctp b/src/Template/Bake/Plugin/README.md.ctp index e24fb7a7a..cb4c73fbe 100644 --- a/src/Template/Bake/Plugin/README.md.ctp +++ b/src/Template/Bake/Plugin/README.md.ctp @@ -22,5 +22,5 @@ You can install this plugin into your CakePHP application using [composer](http: The recommended way to install composer packages is: ``` -composer require your-name-here/<%= $plugin %> +composer require <%= $package %> ``` diff --git a/src/Template/Bake/Plugin/composer.json.ctp b/src/Template/Bake/Plugin/composer.json.ctp index 6dda204d8..37357ea9a 100644 --- a/src/Template/Bake/Plugin/composer.json.ctp +++ b/src/Template/Bake/Plugin/composer.json.ctp @@ -12,9 +12,10 @@ * @since 0.1.0 * @license http://www.opensource.org/licenses/mit-license.php MIT License */ +$namespace = str_replace('\\', '\\\\', $namespace); %> { - "name": "your-name-here/<%= $plugin %>", + "name": "<%= $package %>", "description": "<%= $plugin %> plugin for CakePHP", "type": "cakephp-plugin", "require": { @@ -26,12 +27,12 @@ }, "autoload": { "psr-4": { - "<%= $plugin %>\\": "src" + "<%= $namespace %>\\": "src" } }, "autoload-dev": { "psr-4": { - "<%= $plugin %>\\Test\\": "tests", + "<%= $namespace %>\\Test\\": "tests", "Cake\\Test\\": "./vendor/cakephp/cakephp/tests" } } diff --git a/src/Template/Bake/Plugin/src/Controller/AppController.php.ctp b/src/Template/Bake/Plugin/src/Controller/AppController.php.ctp index 46f9219f8..9ed675f2b 100644 --- a/src/Template/Bake/Plugin/src/Controller/AppController.php.ctp +++ b/src/Template/Bake/Plugin/src/Controller/AppController.php.ctp @@ -15,7 +15,7 @@ %> \Controller; +namespace <%= $namespace %>\Controller; use App\Controller\AppController as BaseController; diff --git a/tests/TestCase/Shell/Task/PluginTaskTest.php b/tests/TestCase/Shell/Task/PluginTaskTest.php index a8e2c906b..ed1f7af02 100644 --- a/tests/TestCase/Shell/Task/PluginTaskTest.php +++ b/tests/TestCase/Shell/Task/PluginTaskTest.php @@ -86,6 +86,20 @@ public function testBake() $this->assertPluginContents('SimpleExample'); } + /** + * test bake with vendor plugin + * + * @return void + */ + public function testBakeVendorName() + { + $this->Task->expects($this->at(0))->method('in') + ->will($this->returnValue('y')); + + $this->Task->bake('Company/Example'); + $this->assertPluginContents('Company/Example'); + } + /** * Test the main method * @@ -215,6 +229,7 @@ public function testFindPathEmpty() */ public function assertPluginContents($pluginName) { + $pluginName = str_replace('/', DS, $pluginName); $comparisonRoot = $this->_compareBasePath . $pluginName . DS; $comparisonDir = new Folder($comparisonRoot); $comparisonFiles = $comparisonDir->findRecursive(); diff --git a/tests/comparisons/Plugin/Company/Example/README.md b/tests/comparisons/Plugin/Company/Example/README.md new file mode 100644 index 000000000..4b3c2a04a --- /dev/null +++ b/tests/comparisons/Plugin/Company/Example/README.md @@ -0,0 +1,11 @@ +# Company/Example plugin for CakePHP + +## Installation + +You can install this plugin into your CakePHP application using [composer](http://getcomposer.org). + +The recommended way to install composer packages is: + +``` +composer require Company/Example +``` diff --git a/tests/comparisons/Plugin/Company/Example/composer.json b/tests/comparisons/Plugin/Company/Example/composer.json new file mode 100644 index 000000000..31d2a2350 --- /dev/null +++ b/tests/comparisons/Plugin/Company/Example/composer.json @@ -0,0 +1,23 @@ +{ + "name": "Company/Example", + "description": "Company/Example plugin for CakePHP", + "type": "cakephp-plugin", + "require": { + "php": ">=5.4.16", + "cakephp/cakephp": "~3.0" + }, + "require-dev": { + "phpunit/phpunit": "*" + }, + "autoload": { + "psr-4": { + "Company\\Example\\": "src" + } + }, + "autoload-dev": { + "psr-4": { + "Company\\Example\\Test\\": "tests", + "Cake\\Test\\": "./vendor/cakephp/cakephp/tests" + } + } +} diff --git a/tests/comparisons/Plugin/Company/Example/config/routes.php b/tests/comparisons/Plugin/Company/Example/config/routes.php new file mode 100644 index 000000000..0c3efef70 --- /dev/null +++ b/tests/comparisons/Plugin/Company/Example/config/routes.php @@ -0,0 +1,6 @@ +fallbacks('InflectedRoute'); +}); diff --git a/tests/comparisons/Plugin/Company/Example/phpunit.xml.dist b/tests/comparisons/Plugin/Company/Example/phpunit.xml.dist new file mode 100644 index 000000000..d5d8482e4 --- /dev/null +++ b/tests/comparisons/Plugin/Company/Example/phpunit.xml.dist @@ -0,0 +1,43 @@ + + + + + + + + + + + ./tests/TestCase + + + + + + + + + + + + + + + + ./vendor/ + ./vendor/ + + ./tests/ + ./tests/ + + + + diff --git a/tests/comparisons/Plugin/Company/Example/src/Controller/AppController.php b/tests/comparisons/Plugin/Company/Example/src/Controller/AppController.php new file mode 100644 index 000000000..9edf27900 --- /dev/null +++ b/tests/comparisons/Plugin/Company/Example/src/Controller/AppController.php @@ -0,0 +1,10 @@ +