IntelliJ Idea and it's smaller sister PHPStorm are commercial IDEs with excellent PHP coding support. Idea has support for a wide range of programming languages, while PHPStorm is aimed at PHP only.
The DokuWiki project has been provided with a free, unlimited user license for Idea by JetBrains. Regular DokuWiki contributors can apply for the free license key by sending a simple mail to andi.
After installing, you should make sure you have at least the following plugins enabled:
Plugins can be installed via File
→ Settings…
→ Plugins
. Some are already installed, see “Installed”. The missing plugins can be found via Marketplace. The plugin manager will ask you to install any needed dependencies.
Note: not all of the plugins above might be available (or needed) in PHPStorm.
Do a git checkout of DokuWiki. Then start Idea and select File
→ New Project…
. In the next dialog select Create project from scratch
. In the final dialog, browse to your checkout and select “Web Module”. Click finish and you're done.
To setup Idea for DokuWiki's coding style, download the following file and place it into your .IntelliJIdea13/config/codestyles
(Win/*nix) ~/Library/Preferences/IntelliJIdea13/codestyles
(OSX) folder:
<?xml version="1.0" encoding="UTF-8"?> <!-- Shell code to update: wget -O dokuwiki-codestyle.xml \ https://www.dokuwiki.org/_export/code/devel:intellij_idea?codeblock=0 --> <code_scheme name="DokuWiki"> <option name="LINE_SEPARATOR" value=" " /> <JSCodeStyleSettings> <option name="ALIGN_OBJECT_PROPERTIES" value="1" /> </JSCodeStyleSettings> <PHPCodeStyleSettings> <option name="ALIGN_KEY_VALUE_PAIRS" value="true" /> <option name="ALIGN_PHPDOC_PARAM_NAMES" value="true" /> <option name="ALIGN_PHPDOC_COMMENTS" value="true" /> <option name="ALIGN_ASSIGNMENTS" value="true" /> <option name="LOWER_CASE_BOOLEAN_CONST" value="true" /> <option name="LOWER_CASE_NULL_CONST" value="true" /> </PHPCodeStyleSettings> <XML> <option name="XML_LEGACY_SETTINGS_IMPORTED" value="true" /> </XML> <codeStyleSettings language="JavaScript"> <option name="KEEP_FIRST_COLUMN_COMMENT" value="false" /> </codeStyleSettings> <codeStyleSettings language="LESS"> <indentOptions> <option name="INDENT_SIZE" value="4" /> </indentOptions> </codeStyleSettings> <codeStyleSettings language="PHP"> <option name="KEEP_BLANK_LINES_IN_DECLARATIONS" value="1" /> <option name="KEEP_BLANK_LINES_IN_CODE" value="1" /> <option name="KEEP_BLANK_LINES_BEFORE_RBRACE" value="1" /> <option name="CLASS_BRACE_STYLE" value="1" /> <option name="METHOD_BRACE_STYLE" value="1" /> <option name="ALIGN_MULTILINE_CHAINED_METHODS" value="true" /> <option name="ALIGN_MULTILINE_PARAMETERS_IN_CALLS" value="true" /> <option name="ALIGN_MULTILINE_EXTENDS_LIST" value="true" /> <option name="ALIGN_MULTILINE_ARRAY_INITIALIZER_EXPRESSION" value="true" /> <option name="SPACE_AFTER_TYPE_CAST" value="true" /> <option name="SPACE_BEFORE_IF_PARENTHESES" value="false" /> <option name="SPACE_BEFORE_WHILE_PARENTHESES" value="false" /> <option name="SPACE_BEFORE_FOR_PARENTHESES" value="false" /> <option name="SPACE_BEFORE_CATCH_PARENTHESES" value="false" /> <option name="SPACE_BEFORE_SWITCH_PARENTHESES" value="false" /> <option name="CALL_PARAMETERS_LPAREN_ON_NEXT_LINE" value="true" /> <option name="CALL_PARAMETERS_RPAREN_ON_NEXT_LINE" value="true" /> <option name="ARRAY_INITIALIZER_LBRACE_ON_NEXT_LINE" value="true" /> <option name="ARRAY_INITIALIZER_RBRACE_ON_NEXT_LINE" value="true" /> </codeStyleSettings> <codeStyleSettings language="SCSS"> <indentOptions> <option name="INDENT_SIZE" value="4" /> <option name="CONTINUATION_INDENT_SIZE" value="4" /> </indentOptions> </codeStyleSettings> </code_scheme>
Command to download from this wiki (relative to IntelliJIdea/config
dir):
wget https://www.dokuwiki.org/_export/code/devel:intellij_idea?codeblock=0 \ -O codestyles/dokuwiki-codestyle.xml
Then go to File
→ Settings…
→ Editor
→ Code Style
and select DokuWiki
from the drop down. (Maybe you have to restart first before scheme is shown)
Additionally you may want to configure the following inspections at File
→ Settings…
→ Editor
→ Inspections
:
IDEA can make more intelligent suggestions when it knows where which parts are located where. To do so you should add some directory markings.
Directory | Mark as | Namespace |
---|---|---|
_test/tests | Tests | dokuwiki\test |
inc | Sources | dokuwiki |
_test/mock | Sources | dokuwiki\test\mock |
data | Excluded | |
vendor | Excluded |
IDEA will automatically keep track of git changes for the main DokuWiki checkout. But usually plugins and templates will have their own .git directory. Telling IDEA about it is a good idea.
Our unit tests can be integrated directly into Idea. To do so go to Run
→ Edit Configurations…
.
First set default configuration, then you don't have to do that in next steps
Under Templates
find PHPUnit
and check Use alternative configuration file
, fill <path to>/_test/phpunit.xml
, leave everything as is and press Apply
.
Click the +
button (i.e. top left button with on hover 'Add New Configuration') and choose PHPUnit
. Then fill in these values:
All Tests
<path to>/_test/phpunit.xml
-d output_buffering=On
Repeat to add another config with these values:
Fast Tests
<path to>/_test/phpunit.xml
--exclude-group slow,internet
-d output_buffering=On
You now can run all or only the fast tests directly from the Run
menu or the dropdown in the toolbar.
Note: the -d output_buffering=On
option is needed until this bug is fixed.
In order to run individual test cases you need to add a few more settings. Go to File
→ Settings…
→ Languages & Frameworks
→ PHP
→ Test Frameworks
,
Use +
button to add a configuration. Here you need to enable Default configuration file
and specify the <path to>/_test/phpunit.xml
.
Then you need to mark either under Directories
in the project settings or directly in the project tree the _test/tests
via context menu option Mark directory As
→ Test Source Root
and do the same for any plugin test directories. After that you can run or debug individual test cases by choosing run or debug in the context menu of the file in the project tree.
Note: only needed for older versions of IDEA intellij. Is today automatically retrieve from the phpunit.phar
.
To use all the favor of Idea you have to add the PHPUnit source to your project. To add this you have to:
/usr/share/pear/PHPUnit
, /usr/share/php/PHPUnit
, etc)Idea will now index the PHPUnit source and can provide auto completion inside of unit tests.
Press CTRL-ALT-L
to reformat the current file according to the code style settings. Be sure to check in such cleanups as separate commits from any logic changes.
If Idea fails to understand the class type of a (global) variable, annotate it with a type hint:
function foo(){ /* @var Input $INPUT */ global $INPUT; // thanks to the type hint Idea now knows this is valid: echo $INPUT->str('foo'); }
Hit ALT-Enter
to “autofix” problems detected by Idea. Works very well to insert missing doc blocks for example.