PayPal - The safer, easier way to pay online!

[ Previous | TOC | Next ]

Eclipse integration

Preamble

We assume that you have read the previous tutorials because we do not explain php-maven or maven itself at this point. However you should at least prepared your computer for use of php-maven (add repositories to settings.xml). You need at least Eclipse 3.7 (indigo) with m2e (Maven integration) and pdt (PHP Development).

Installation

  • Within eclipse go to the menu "Help -> Install New Software".
  • Hit the "Add" button at the top left.
  • Enter name "PHPMaven update site" and url "http://www.php-maven.org/eclipse/update"
  • The update site is automatically selected and you are know able to enable the checkbox for phpmaven.
  • Hit next/finish to install the eclipse plugins.

Notice: If you get errors saying "bundle ch.qos.logback.classic is missing" you need to install m2e plugins first. Go to the M2E download site and drag&drop the small "install m2e" icon directly into your eclipse.

Plugin execution not covered by lifecycle....

This is a well known error in eclipse. One day the maven plugin developers decided to complain for every maven build plugin that eclipse does not know of. As soon as you see this error have a look if this is a plugin that you know of. If you do not know of this plugin simply ignore this error or use the quickfix feature to hide the error. However: If eclipse complains that it does not know how to handle phpmaven you have an installation problem or the eclipse plugin is too old. For details see the section "ignore plugin goal" or "execute plugin goal" at the eclipse wiki.

Create a project

There is a new wizard you can use to create a new php-maven project. This project will be configured as a standard project. Of course you may use your own archetype for project creation.

  • Enter the new project wizard (right click on navigator and menu "New -> Project").
  • Choose PHP-Maven project.
  • Select the archetype you want to use.
  • Enter the group id, artifact id and version for your new project.
  • Hit finish.
choose php-maven project choose the archetype enter the maven project info

The project is created and is well configured. Eclipse will respect the maven lifecycle as well as the dependencies. Notice that some pdt versions contain bugs that may lead into problems seeing the php classpath.

Convert existing project

If you already created projects and may want to convert them right-click on them. Within the menu there is a php-maven category. There you will find a menu entry called "Convert to PHP-Maven project". You can enable php-maven support on m2e projects that are marked for packaging "php" or for pdt projects that do not yet have maven support. After enabling php-maven support for a pdt project you may need to rework the sources because php-maven does not do any rework or copy action for you. The sources must be located in src/min/php and src/test/php.

We recommend to first create the directory structure needed for php-maven:

prepare php project

Screenshot: Prepared PDT project with source folders already set.





After creating this structure you are ready to enable the PHP-Maven support:

convert project

Screenshot: Enabled PHP-Maven support.





Converting the project enables the maven support and the m2e support within eclipse. However it already did some important things in background. You will know see a small "m" at the upper left corner of the project icon. This is indicating a maven project within eclipse. And you will know see the target directory:

converted project

Screenshot: Converted project.





However do not wonder about the error in pom.xml saying "Plugin execution not covered" for the maven-plugin-plugin. The m2e guys currently complain about every unknown plugin that is used by your eclipse project. That is not really an error and everything will work fine. PHP-Maven for eclipse already told eclipse what to do with php-maven build plugin itself. So it will know what to do for our project. However if you see errors related to really important plugins that may causing problems within eclipse.

Using PHP-Maven for eclipse

Let us first write down a small class that does some useful things:

sample class

Screenshot: A sample class.





As you see this class is automatically copied to the target classes folder. Now let us write a test class. But wait. Do we have a phpunit dependency? No, we don't. So let us add it. Open the pom.xml in pom editor, go to the dependencies tab and add a new dependency. Do not wonder about the next screenshot. In my local repository there are multiple variants of phpunit, patched and not patched. As you are using only the official repository you may only find the one and only phpunit from "org.phpunit" (Do not forget to select scope "test" instead of "compile"):

add phpunit dependency

Screenshot: Add the phpunit dependency.





Now let us test it by writing a phpunit test case and by testing it with code coverage. As you see PHP-Maven automatically configured Eclipse so that the dependency is respected:

phpunit code completion

Screenshot: Code completion and class information example.





The test class will test some meaningful things and verify that our class will work the expected way:

phpunit testcase

Screenshot: Example testcase for phpunit.

PHPUnit invocation

Now right click on the project and have a look at the PHP-Maven menu. You will now find a small action to invoke the tests on your project (or when clicking on folders or files to test only the elected ones):

invoke phpunit

Screenshot: Invoke the phpunit testcases.





PHP-Maven will now open a new small view to display the test results once they are finished. You can know browse f.e. the coverage infos:

result code coverage

Screenshot: Result view and code coverage display.





But there is smarter way than browsing the tree. Open the FooClass file once again. You will know see a line marker indicating the code coverage. Green markers means: Line covered by the tests from last run. Red marker means: Line not covered. And a yellow marker means: Line not completely covered:

result code coverage in eclipse editor

Screenshot: Code covered directly visible in the source editor.

[ Previous | TOC | Next ]