Help:Development tool/Eclipse

What Links Here
= Seeing is believing = The following video shows where you get after going thru this documentation:
 * http://profiwiki.bitplan.com/index.php/SMW_PHPUnit_Test_Debugging

Example Environment (s)
This description has been tried out on two environments a) MAMP b) LAMP

MAMP environment
Environment: MacOSX 10.11.2 El Capitan MacPorts MAMP see https://trac.macports.org/wiki/howto/MAMP
 * MacOSX: Darwin neso.bitplan.com 15.2.0 Darwin Kernel Version 15.2.0: Fri Nov 13 19:56:56 PST 2015; root:xnu-3248.20.55~2/RELEASE_X86_64 x86_64
 * Apache/2.2.31 (Unix) mod_ssl/2.2.31 OpenSSL/1.0.2e DAV/2 PHP/5.6.16
 * mysql Ver 14.14 Distrib 5.6.28, for osx10.11 (x86_64) using  EditLine wrapper
 * PHP 5.6.16 (cli) (built: Dec 26 2015 14:55:14)

LAMP environment

 * Linux: Description:	Ubuntu 14.04.3 LTS/Release:	14.04/ Codename:	trusty
 * Apache/2.4.7 (Ubuntu)
 * mysql Ver 14.14 Distrib 5.5.46, for debian-linux-gnu (x86_64) using readline 6.3
 * PHP 5.5.9-1ubuntu4.14 (cli) (built: Oct 28 2015 01:34:46)

SMW Installation
The SMW installation has been done using composer.

Installing XDebug
add to php.ini:

Installing Eclipse for PHP
Download and unpack Eclipse for PHP developers.
 * https://eclipse.org/downloads/packages/

As of 2015-12 the latest Release is Version: Mars.1 Release 4.5.1 Build id: 20150924-1200

Linux
see http://ubuntuhandbook.org/index.php/2014/06/install-latest-eclipse-ubuntu-14-04/

Welcome Screen
If you see the following welcome screen then you successfully installed Eclipse for PHP Developers:

Creating the Mediawiki project
Select File/New/PHP Project from the menu. Select "Create project at existing location (from existing source) and Browse to your mediawiki folder. Then click "Finish".

Using the PHP Explorer
The PHP Explorer works in the usual Explorer style that presents a tree structure of the folders and files in the mediawiki main folder. Let's e.g. look at tests/phpunit/phpunit.php:

This is the "entry point" for PHPUnit Testcase in Mediawiki. This entry point is also used by the SMW PHPUnit Testcases.

Running some code
open "index.php" from the main mediawiki folder. Right click "Run as/PHP Web Application" A browser window should open next to the source code window and your wiki should be available for use in this browser window.

Configuring the debugger
On the server side needs to be installed and configured. You might want to check it using a phpinfo page. The xdebug section should look like this:

On the client / eclipse side you might want to configure the debug settings for your project. Right click on the project/Properties.
 * Enable project specific settings (or click Configure Workspace Settings if you'd like to make global changes)
 * Click on "PHP Servers"
 * Select the Default PHP Web Server and click "Edit"
 * Select the "Debugger" Tab
 * Select the XDebug Debugger and click "Finish"

Testing to debug
= Testing = There are few thousand PHPUnit Tests which are checking that the SMW implementation conforms to it's expected behavior. If all is well theses tests should succeed in your development environment.
 * open "index.php" in one tab and includes/specialpage/SpecialPage in another tab
 * set a breakpoint in the function "getTitleFor" at the return statement (as of 2015-12-29 this is line 78)
 * click on index.php and right click debug as "PHP Web Application"
 * there will be dialog to confirm the perspective switch to debug for the first time - acknowledge it
 * the debugger will start and stop at the first active line of index.php
 * You can now step thru your code with commands like Run Step Into (F5) and Run Step Over (F6)
 * if you click the green "run" button the session will run until it hits the breakpoint
 * Here you can now inspect the variables e.g. in this case "$name" is "Hochladen" which is the german Special Page "Upload"
 * If you click the run button a few more times the names of other special pages will show and you can see where "you are" in the stacktrace displayed

Running tests from commandline
The commands below show the result with a single error. All is well if there is no significant error left. There are a few testcases that are marked as "skip" or "risky". You might want to ignore these.

Running tests from eclipse
Its convenient to use the MakeGood Plugin for running tests in eclipse

Some Links for MakeGood

 * https://github.com/piece/makegood
 * https://github.com/piece/makegood/wiki
 * https://github.com/piece/makegood/issues
 * http://stackoverflow.com/questions/tagged/makegood
 * http://web.archive.org/web/20140817181801/http://piece-framework.com/projects/makegood/wiki/MakeGood_User_Guide_1_7_0
 * https://github.com/piece/makegood/issues/85
 * http://stackoverflow.com/a/34483373/1497139

Installing MakeGood from the Marketplace
Go to "Help/Eclipse Marketplace" Enter "MakeGood" in the search dialog and click "Go"
 * Then click "Install", "Confirm" and accept the license terms and "Finish".
 * Trust KUBO Atushiro;;Piece Project's certificate
 * Restart your Eclipse

Setting up an example
Basically follow the instructions of http://stackoverflow.com/a/34483373/1497139 cd to it on the command line
 * Create a project "MakeGoodTest"

Install a local PHPUnit
Install a local composer based PHPUnit

Create an example Testcase
Create test/MakeGoodTest.php with the following content: This file is based on an Example by Sebastian Bergmann.

Configuring MakeGood for the MakeGoodTest example project
Right-Click / Refresh your MakeGoodTest project in Eclipse so that the command-line changes get visible.

Create the phpunit.xml file
This file is in the same directory as the composer.* files.

Configure MakeGood for the MakeGoodTest Project

 * Right Click / Properties on the MakeGoodTest Project
 * Select MakeGood
 * 1) Add "test" as a test folder
 * 2) Browse "MakeGoodPreload.php" as the Preload Script
 * 1) in the PHPUnit tab browse to the "phpunit.xml" accordingly

Trying out running tests with MakeGood
available as options. Try e.g. The result should be As of 2015-12-30 the right click option does not work in Linux. I have filed a bug report at https://github.com/piece/makegood/issues/88 for this. Please comment on the bug report and here what your experience with Linux is.
 * Open "MakeGoodTest.php"
 * Right click - there should be
 * 1) "Run Tests In"
 * 2) "Run Tests Related to This File"
 * 3) "Run All Tests"
 * "Run All Tests"
 * "Run All Tests in Class"

Configuring MakeGood for SMW
Right click / Properties on your Mediawiki/SMW project select "MakeGood" SMW already has a mediawiki/extensions/SemanticMediaWiki/phpunit.xml.dist file to be used - select this We need a MakeGoodPreload.php for this environment (which needs globals.inc).
 * add mediawiki/extensions/SemanticMediaWiki/tests as your Test Folder

about globals.inc
Using the above globals.inc is a "hacky" approach as of 2015-12-30. It would be nice to have a better approach than trying to list all possible globals. See https://www.semantic-mediawiki.org/wiki/User:WolfgangFahl/Workdocumentation_2015-12-27#tab=globals how this file was initially created. With this file most of the tests work - unfortunately not all yet.

Running Tests for SMW

 * Now you can open a test from the SemanticMediaWiki/tests/phpunit directory and run it.
 * You can also try to run all tests.
 * What's more: you can even debug the testing. In the MakeGood-Tab there is a button that enables debugging.
 * See also the video at: http://profiwiki.bitplan.com/index.php/SMW_PHPUnit_Test_Debugging