DokuWiki

It's better when it's simple

User Tools

Site Tools


Sidebar

Translations of this page?:

Learn about DokuWiki

Advanced Use

Corporate Use

Our Community


Follow us on Facebook, Twitter and other social networks.

devel:intellij_idea

IntelliJ Idea

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 andiAndreas Gohr
andi

.

Setup Idea Plugins

After installing, you should make sure you have at least the following plugins enabled:

  • CSS Support
  • Git Integration
  • HTML Tools
  • JavaScript Support
  • PHP
  • PHPUnit code coverage

Plugins can be installed via FileSettings…PluginsBrowse repositories…. Click the checkbox to install a deselected plugin. 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.

Create an Idea Project for DokuWiki

Do a git checkout of DokuWiki. Then start Idea and select FileNew 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.

New Project Dialog

Configure Idea

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:

~/.IntelliJIdea13/config/codestyles/DokuWiki.xml
<?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="&#10;" />
  <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 FileSettings…Code Style and select DokuWiki from the drop down.

Additionally you may want to configure the following inspections at FileSettings…Inspections:

  • PHP
    • General
      • Unresolved include : false (Idea isn't able to resolve our includes even though they are completely correct)
    • PHPDoc
      • Missing PHPDoc comment: true
  • Spelling: false

Integrate Unit Tests

Our unit tests can be integrated directly into Idea. To do so go to RunEdit Configurations….

First set default configuration, then you don't have to do that in next steps

Under Defaults find PHPUnit and check Use alternative configuration file, fill <path to>/_test/phpunit.xml, leave everything as is and press Apply.

Click the Add button and choose PHPUnit. Then fill in these values:

  • Name: All Tests
  • Test Runner
    • Test Scope: Defined in the configuration file
    • Use alternative configuration file: <path to>/_test/phpunit.xml
  • Command Line
    • Interpreter options: -d output_buffering=On

Repeat to add another config with these values:

  • Name: Fast Tests
  • Test Runner
    • Test Scope: Defined in the configuration file
    • Use alternative configuration file: <path to>/_test/phpunit.xml
    • Test Runner options: --exclude-group slow,internet
  • Command Line
    • Interpreter options: -d output_buffering=On

Run Configuration

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.

Individual/plugin test cases

In order to run individual test cases you need to add a few more settings. Go to FileSettings…PHPPHPUnit, here you need to enable Use 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 AsTest 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.

PHPUnit autocompletion

To use all the favor of Idea you have to add the PHPUnit source to your project. To add this you have to:

  1. Open your project
  2. Click on File → Project Structure
  3. Select “Libraries” tab
  4. Click on the “+” → Java
  5. Select your PHPUnit folder (eg. /usr/share/pear/PHPUnit)
  6. In the following dialog choose “source”
  7. Click “Ok”
  8. Click “Ok”
  9. And your done

Idea will now index the PHPUnit source and can provide auto completion inside of unit tests.

Tips and Tricks

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.

devel/intellij_idea.txt · Last modified: 2014-06-15 10:05 by andi