====== IntelliJ Idea ====== {{https://www.jetbrains.com/img/logos/logo_intellij_idea.png?nolink&200 }} [[https://www.jetbrains.com/idea/|IntelliJ Idea]] and it's smaller sister [[https://www.jetbrains.com/phpstorm/|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 [[user>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 ''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. ===== Create an Idea Project for DokuWiki ===== 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. {{ :devel:idea-newproject.png?500 |New Project Dialog}} ===== Coding Style ===== 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: 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'': * 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 ===== Path Mappings ===== IDEA can make more intelligent suggestions when it knows where which parts are located where. To do so you should add some directory markings. {{ :devel:ideadirectories.png?300|Pathmapping Example}} * focus the directory tree and press F4 * this should open the Module Settings dialog * select a directory, then click on the appropriate "Mark as" button at the top * click the pen icon on the right to configure an associated namespace ^ Directory ^ Mark as ^ Namespace ^ | ''_test/tests'' | Tests | ''dokuwiki\test'' | | ''inc'' | Sources | ''dokuwiki'' | | ''_test/mock'' | Sources | ''dokuwiki\test\mock'' | | ''data'' | Excluded | | | ''vendor'' | Excluded | | ===== Mapping of (plugin) git repositories ===== 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. - Click on File -> Settings... - Select "Version Control" - Select "Directory Mappings" - At the bottom of the list recognized git repositories are listed. Select to add. ===== Integrate Unit Tests ===== Our [[devel:unittesting|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 ''/_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: * Name: ''All Tests'' * Test Runner * Test Scope: Defined in the configuration file * Use alternative configuration file: ''/_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: ''/_test/phpunit.xml'' * Test Runner options: ''%%--exclude-group slow,internet%%'' * Command Line * Interpreter options: ''-d output_buffering=On'' {{ :devel:idea-runconfig.png?500 |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 [[http://youtrack.jetbrains.com/issue/WI-8994|bug]] is fixed. ====Individual/plugin test cases==== 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 ''/_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. ==== PHPUnit autocompletion ==== **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: - Open your project - Click on File -> Project Structure - Select "Libraries" tab - Click on the "+" -> Java - Select your PHPUnit folder (eg. ''/usr/share/pear/PHPUnit'', ''/usr/share/php/PHPUnit'', etc) - In the following dialog choose "Sources" - Click "Ok" - Click "Ok" - And you're 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.