Skip to content

Commit

Permalink
Merge branch 'release/1.6.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
khalwat committed Apr 26, 2020
2 parents 0e05427 + b17fada commit 63d17d2
Show file tree
Hide file tree
Showing 27 changed files with 386 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGLOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# generator-craftplugin Changelog

## 1.6.0 - 2020.04.26
### Added
* Added support for the Codeception testing framework, thanks to a PR from Giel

## 1.5.1 - 2020.04.15
### Changed
* Updated to use the new Twig Extension class namespace to avoid deprecation errors
Expand Down
34 changes: 30 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ This assumes you have `nodejs`, `npm`, and `yeoman` installed already.
4. -OR- do an `npm -g install generator-craftplugin` to install it via npm (and thus skip the `npm link` step)
5. The generator folder should be named `generator-craftplugin`. GitHub recently started appending `-master` (the branch name) to the name of the folder for zip file downloads.

Requires Node version 4.0.0 or later.
Requires Node version 8.0.0 or later.

## Usage

Expand All @@ -34,7 +34,7 @@ generator-craftplugin will ask you a few questions:
* **Plugin author GitHub.com name:** - enter the GitHub.com handle of the author of the plugin. If you don't have one, just leave it blank
* **Select what components your plugin will have:** - select the components you want included in your plugin, using the arrow keys to change the component, and `<space>` to select them.

If you selected `Controllers`, `ElementTypes`, `FieldTypes`, `Models`, `Purchasables`. `Records`, `Services`, `Tasks`, or `Widgets` components, it will also ask you for a name for each one, respectively. If you want multiple components, just separate them with a , in the name input.
If you selected `Controllers`, `ElementTypes`, `FieldTypes`, `Models`, `Purchasables`, `Records`, `Services`, `Tasks`, or `Widgets` components, it will also ask you for a name for each one, respectively. If you want multiple components, just separate them with a , in the name input.

generator-craftplugin will then do the following for you:

Expand All @@ -52,6 +52,7 @@ Here's an example of the output from a `yo craftplugin` generator:
? Select what Craft CMS API to target: (Use arrow keys)
Version 2.5.x
❯ Version 3.0.x
Module Version 3.0.x
[ Prompting ]
? Plugin name: Some Plugin
? Short description of the plugin: Some Description
Expand All @@ -75,6 +76,7 @@ e selection)
◉ Services
◉ Settings
◉ Tasks
◉ Tests
◉ TwigExtensions
◉ Utilities
◉ Variables
Expand Down Expand Up @@ -108,6 +110,7 @@ e selection)
'services',
'settings',
'tasks',
'tests',
'twigextensions',
'utilities',
'variables',
Expand Down Expand Up @@ -155,6 +158,7 @@ e selection)
'services',
'settings',
'tasks',
'tests',
'twigextensions',
'utilities',
'variables',
Expand Down Expand Up @@ -183,6 +187,8 @@ e selection)
pluginChangelogUrl: 'https://raw.githubusercontent.com/SomeGithub/someplugin/master/CHANGELOG.md',
pluginCloneUrl: 'https://github.com/SomeGithub/someplugin.git' }
> Writing template files
+ templates/_codeception.yml wrote to someplugin/codeception.yml
+ templates/tests/ wrote to someplugin/tests/
+ templates/src/_Plugin.php wrote to someplugin/src/SomePlugin.php
+ templates/src/models/_Settings.php wrote to someplugin/src/models/Settings.php
+ templates/_README.md wrote to someplugin/README.md
Expand Down Expand Up @@ -265,6 +271,25 @@ e selection)
+ templates/src/resources/images/plugin.png copied to someplugin/src/resources/images/plugin.png
+ templates/src/resources/screenshots/plugin_logo.png copied to someplugin/src/resources/screenshots/plugin_logo.png
> Sync to file system
create someplugin/codeception.yml
create someplugin/tests/_bootstrap.php
create someplugin/tests/_craft/config/db.php
create someplugin/tests/_craft/config/general.php
create someplugin/tests/_craft/config/routes.php
create someplugin/tests/_craft/config/test.php
create someplugin/tests/_craft/storage/example-file.txt
create someplugin/tests/_craft/templates/example.twig
create someplugin/tests/_support/FunctionalTester.php
create someplugin/tests/_support/Helper/Functional.php
create someplugin/tests/_support/Helper/Unit.php
create someplugin/tests/_support/UnitTester.php
create someplugin/tests/example-env
create someplugin/tests/functional.suite.yml
create someplugin/tests/functional/_bootstrap.php
create someplugin/tests/functional/ExampleFunctionalCest.php
create someplugin/tests/unit.suite.yml
create someplugin/tests/unit/_bootstrap.php
create someplugin/tests/unit/ExampleUnitTest.php
create someplugin/src/SomePlugin.php
create someplugin/src/models/Settings.php
create someplugin/README.md
Expand Down Expand Up @@ -358,7 +383,7 @@ The default LICENSE.txt is the MIT license; feel free to change it as you see fi

The `craftplugin` generator can also be passed arguments via the command line, bypassing the interactive prompts. So it's possible do do something like this:

yo craftplugin --pluginComponents="controllers,consolecommands,elementtypes,fieldtypes,models,records,services,settings,tasks,twigextensions,utilities,variables,widgets" --apiVersion="api_version_3_0" --pluginName="Some Plugin" --pluginDescription="Some Description" --pluginVersion="1.0.0" --pluginVendorName="Some Vendor" --pluginAuthorName="Some Author" --pluginAuthorUrl="https://SomeDomain.com" --pluginAuthorGithub="SomeGithub" --codeComments="yes" --consolecommandName="Een,Twee,Drie" --controllerName="One,Two,Three" --elementName="Neung,Song,Sam" --fieldName="Ichi,Ni,San" --modelName="Uno,Dos,Tres" --purchasableName="" --recordName="Satu,Dua,Tiga" --serviceName="Yi,Er,San" --utilityName="Eins,Zwei,Drei" --taskName="Hana,Dul,Set" --widgetName="Un,Deux,Trois"
yo craftplugin --pluginComponents="controllers,consolecommands,elementtypes,fieldtypes,models,records,services,settings,tasks,tests,twigextensions,utilities,variables,widgets" --apiVersion="api_version_3_0" --pluginName="Some Plugin" --pluginDescription="Some Description" --pluginVersion="1.0.0" --pluginVendorName="Some Vendor" --pluginAuthorName="Some Author" --pluginAuthorUrl="https://SomeDomain.com" --pluginAuthorGithub="SomeGithub" --codeComments="yes" --consolecommandName="Een,Twee,Drie" --controllerName="One,Two,Three" --elementName="Neung,Song,Sam" --fieldName="Ichi,Ni,San" --modelName="Uno,Dos,Tres" --purchasableName="" --recordName="Satu,Dua,Tiga" --serviceName="Yi,Er,San" --utilityName="Eins,Zwei,Drei" --taskName="Hana,Dul,Set" --widgetName="Un,Deux,Trois"

## Adding to an existing plugin

Expand Down Expand Up @@ -387,6 +412,7 @@ Here's a list of the `pluginComponents`; if you want to add more than one, just
services
settings
tasks
tests
twigextensions
utilities
variables
Expand Down Expand Up @@ -418,4 +444,4 @@ Here's a list of meta parameters that you can also pass in, to override what is
--pluginAuthorGithub=""
--codeComments=""

Brought to you by [nystudio107](http://nystudio107.com)
Brought to you by [nystudio107](http://nystudio107.com)
40 changes: 40 additions & 0 deletions app/templates/api_version_3_0/_codeception.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
actor: Tester
paths:
tests: tests
log: tests/_output
data: tests/_data
support: tests/_support
envs: tests/_envs
settings:
bootstrap: _bootstrap.php
coverage:
enabled: true
include:
- src/*
exclude:
- src/etc/*
- src/migrations/*
- src/templates/*
- src/translations/*
- src/web/assets/*
- docs/*
- templates/*
- tests/*
- vendor/*
params:
- tests/.env
modules:
config:
\craft\test\Craft:
configFile: 'tests/_craft/config/test.php'
entryUrl: 'https://test.craftcms.test/index.php'
projectConfig: {}
migrations: []
plugins:
<%= pluginKebabHandle %>:
class: '\<%= pluginVendorName %>\<%= pluginDirName %>\<%= pluginHandle %>'
handle: <%= pluginKebabHandle %>
cleanup: true
transaction: true
dbSetup: {clean: true, setupCraft: true}
fullMock: false
9 changes: 8 additions & 1 deletion app/templates/api_version_3_0/_composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,15 @@
}
],
"require": {
"craftcms/cms": "^3.0.0-RC1"
"craftcms/cms": "^3.0.0"
},
<% if (pluginComponents.indexOf('tests') >= 0){ -%>
"require-dev": {
"craftcms/cms": "^3.2.0",
"codeception/codeception": "^3.0",
"vlucas/phpdotenv": "^3.0"
},
<% } -%>
"autoload": {
"psr-4": {
"<%= pluginVendorName %>\\<%= pluginDirName %>\\": "src/"
Expand Down
1 change: 1 addition & 0 deletions app/templates/api_version_3_0/tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.env
17 changes: 17 additions & 0 deletions app/templates/api_version_3_0/tests/_bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

use craft\test\TestSetup;

ini_set('date.timezone', 'UTC');

// Use the current installation of Craft
define('CRAFT_STORAGE_PATH', __DIR__ . '/_craft/storage');
define('CRAFT_TEMPLATES_PATH', __DIR__ . '/_craft/templates');
define('CRAFT_CONFIG_PATH', __DIR__ . '/_craft/config');
define('CRAFT_MIGRATIONS_PATH', __DIR__ . '/_craft/migrations');
define('CRAFT_TRANSLATIONS_PATH', __DIR__ . '/_craft/translations');
define('CRAFT_VENDOR_PATH', dirname(__DIR__) . '/vendor');

$devMode = true;

TestSetup::configureCraft();
4 changes: 4 additions & 0 deletions app/templates/api_version_3_0/tests/_craft/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
storage/*

!storage/example-file.txt

12 changes: 12 additions & 0 deletions app/templates/api_version_3_0/tests/_craft/config/db.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

return [
'password' => getenv('DB_PASSWORD'),
'user' => getenv('DB_USER'),
'database' => getenv('DB_DATABASE'),
'tablePrefix' => getenv('DB_TABLE_PREFIX'),
'driver' => getenv('DB_DRIVER'),
'port' => getenv('DB_PORT'),
'schema' => getenv('DB_SCHEMA'),
'server' => getenv('DB_SERVER'),
];
5 changes: 5 additions & 0 deletions app/templates/api_version_3_0/tests/_craft/config/general.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

return [
'devMode' => true,
];
5 changes: 5 additions & 0 deletions app/templates/api_version_3_0/tests/_craft/config/routes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

return [

];
5 changes: 5 additions & 0 deletions app/templates/api_version_3_0/tests/_craft/config/test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

use craft\test\TestSetup;

return TestSetup::createTestCraftObjectConfig();
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Im a twig template and here's a random number {{ random() }}
1 change: 1 addition & 0 deletions app/templates/api_version_3_0/tests/_support/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_generated/*
35 changes: 35 additions & 0 deletions app/templates/api_version_3_0/tests/_support/FunctionalTester.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
/**
* <%- pluginName %> plugin for Craft CMS 3.x
*
* <%- pluginDescription %>
*
* @link <%= pluginAuthorUrl %>
* @copyright <%- copyrightNotice %>
*/

use Codeception\Actor;
use Codeception\Lib\Friend;

/**
* Inherited Methods
*
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method Friend haveFriend($name, $actorClass = null)
*
* @SuppressWarnings(PHPMD)
*
*/
class FunctionalTester extends Actor
{
use _generated\FunctionalTesterActions;

}
24 changes: 24 additions & 0 deletions app/templates/api_version_3_0/tests/_support/Helper/Functional.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
/**
* <%- pluginName %> plugin for Craft CMS 3.x
*
* <%- pluginDescription %>
*
* @link <%= pluginAuthorUrl %>
* @copyright <%- copyrightNotice %>
*/

namespace Helper;

use Codeception\Module;

/**
* Class Functional
*
* Here you can define custom actions.
* All public methods declared in helper class will be available in $I
*/
class Functional extends Module
{

}
25 changes: 25 additions & 0 deletions app/templates/api_version_3_0/tests/_support/Helper/Unit.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
/**
* <%- pluginName %> plugin for Craft CMS 3.x
*
* <%- pluginDescription %>
*
* @link <%= pluginAuthorUrl %>
* @copyright <%- copyrightNotice %>
*/

namespace Helper;

use Codeception\Module;

/**
* Class Unit
*
* Here you can define custom actions.
* All public methods declared in helper class will be available in $I
*
*/
class Unit extends Module
{

}
35 changes: 35 additions & 0 deletions app/templates/api_version_3_0/tests/_support/UnitTester.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
/**
* <%- pluginName %> plugin for Craft CMS 3.x
*
* <%- pluginDescription %>
*
* @link <%= pluginAuthorUrl %>
* @copyright <%- copyrightNotice %>
*/

use Codeception\Actor;
use Codeception\Lib\Friend;

/**
* Inherited Methods
*
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method Friend haveFriend($name, $actorClass = null)
*
* @SuppressWarnings(PHPMD)
*
*/
class UnitTester extends Actor
{
use _generated\UnitTesterActions;

}
11 changes: 11 additions & 0 deletions app/templates/api_version_3_0/tests/example-env
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Set in accordance to your environment

DB_DRIVER="mysql"
DB_SERVER="localhost"
DB_USER="root"
DB_PASSWORD=""
DB_DATABASE="craft-test"
DB_SCHEMA=""
DB_TABLE_PREFIX="craft"
DB_PORT="3306"
SECURITY_KEY="abcde12345"
5 changes: 5 additions & 0 deletions app/templates/api_version_3_0/tests/functional.suite.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
actor: FunctionalTester
modules:
enabled:
- \craft\test\Craft
- \Helper\Functional
Loading

0 comments on commit 63d17d2

Please sign in to comment.