Skip to content

Commit

Permalink
Correct plugin generation for vendored plugins.
Browse files Browse the repository at this point in the history
Add additional template variables and templates to handle
vendor plugins correctly.

Refs cakephp/cakephp#7062
  • Loading branch information
markstory committed Jul 25, 2015
1 parent 2645348 commit 810d0e6
Show file tree
Hide file tree
Showing 12 changed files with 150 additions and 6 deletions.
13 changes: 12 additions & 1 deletion src/Shell/Task/PluginTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Template/Bake/Plugin/README.md.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>
```
7 changes: 4 additions & 3 deletions src/Template/Bake/Plugin/composer.json.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
%>
<?php

namespace <%= $plugin %>\Controller;
namespace <%= $namespace %>\Controller;

use App\Controller\AppController as BaseController;

Expand Down
15 changes: 15 additions & 0 deletions tests/TestCase/Shell/Task/PluginTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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();
Expand Down
11 changes: 11 additions & 0 deletions tests/comparisons/Plugin/Company/Example/README.md
Original file line number Diff line number Diff line change
@@ -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
```
23 changes: 23 additions & 0 deletions tests/comparisons/Plugin/Company/Example/composer.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
6 changes: 6 additions & 0 deletions tests/comparisons/Plugin/Company/Example/config/routes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php
use Cake\Routing\Router;

Router::plugin('Company/Example', function ($routes) {
$routes->fallbacks('InflectedRoute');
});
43 changes: 43 additions & 0 deletions tests/comparisons/Plugin/Company/Example/phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
colors="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="./tests/bootstrap.php"
>
<php>
<ini name="memory_limit" value="-1"/>
<ini name="apc.enable_cli" value="1"/>
</php>

<!-- Add any additional test suites you want to run here -->
<testsuites>
<testsuite name="Company/Example Test Suite">
<directory>./tests/TestCase</directory>
</testsuite>
</testsuites>

<!-- Setup a listener for fixtures -->
<listeners>
<listener
class="\Cake\TestSuite\Fixture\FixtureInjector"
file="./vendor/cakephp/cakephp/src/TestSuite/Fixture/FixtureInjector.php">
<arguments>
<object class="\Cake\TestSuite\Fixture\FixtureManager" />
</arguments>
</listener>
</listeners>

<!-- Prevent coverage reports from looking in tests and vendors -->
<filter>
<blacklist>
<directory suffix=".php">./vendor/</directory>
<directory suffix=".ctp">./vendor/</directory>

<directory suffix=".php">./tests/</directory>
<directory suffix=".ctp">./tests/</directory>
</blacklist>
</filter>

</phpunit>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Company\Example\Controller;

use App\Controller\AppController as BaseController;

class AppController extends BaseController
{

}
24 changes: 24 additions & 0 deletions tests/comparisons/Plugin/Company/Example/tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
/**
* Test suite bootstrap for Company/Example.
*
* This function is used to find the location of CakePHP whether CakePHP
* has been installed as a dependency of the plugin, or the plugin is itself
* installed as a dependency of an application.
*/
$findRoot = function ($root) {
do {
$lastRoot = $root;
$root = dirname($root);
if (is_dir($root . '/vendor/cakephp/cakephp')) {
return $root;
}
} while ($root !== $lastRoot);

throw new Exception("Cannot find the root of the application, unable to run tests");
};
$root = $findRoot(__FILE__);
unset($findRoot);

chdir($root);
require $root . '/config/bootstrap.php';
Empty file.

0 comments on commit 810d0e6

Please sign in to comment.