12

How can I get NetBeans to provide code-completion for PHPUnit classes and methods?

I have already tried downloading from the PHPUnit GitHub project, but I didn't understand why the directory is different from what's mentioned on the Selenium documentation. I am looking example for the /test/PHPUnit/Extensions/SeleniumTestCase.php file.

I have already installed PHPUnit from PEAR, but what I need now is the complete PHPUnit file so I can include it in my IDE (in this case NetBeans).

2 Answers 2

36

Add the PHPUnit directory to NetBeans's PHP global include path. This will provide code completion in NetBeans for all projects.

  1. Open Tools : Options
  2. Switch to the PHP tab
  3. Click Add Folder... next to the Global Include Path box
  4. Enter /usr/share/php/PHPUnit or navigate to where PEAR installed PHPUnit's source files
  5. Click Open
  6. Click OK

Update: The file defining PHPUnit_Extensions_SeleniumTestCase is placed in the same directory as PHPUnit when you install PHPUnit Selenium.

For example, PHPUnit_Framework_TestCase is stored in

/usr/share/php/PHPUnit/Framework/TestCase.php

The Selenium test case is stored in

/usr/share/php/PHPUnit/Extensions/SeleniumTestCase.php

So by placing /usr/share/php/PHPUnit into the NetBeans include path, you pick up both. You have to install the extension first, of course.

pear install phpunit/PHPUnit_Selenium
Sign up to request clarification or add additional context in comments.

3 Comments

I Know how to include PATH PHP Unit, but what i didn't know is where is the PHPUnit/Extensions/SeleniumTestCase.php (the file is not included in GitHub file i downloaded) or class named PHPUnit_Extensions_SeleniumTestCase which in this case i download the file from GITHUB.
ty Sir. There is no problem doing this on Windows without pear. Just download the files somewhere and add the Dir to NB include Paths.
DAAAAAAAAAAAAAMN...This has been bugging me for YEARS but not enough for me to look it up. I accidentally stumbled upon this :)
2

Moving away from PEAR...(I'd even uninstall the PEAR version to avoid conflicts first).

  1. Download PHPUnit with sources https://github.com/sebastianbergmann/phpunit and extract somewhere semi-permanent /your-install-path
  2. Add /your-install-path/phpunit to your PATHs
  3. In Netbeans options (Tools > Options on Windows, Netbeans > Preferences on OS X), go to PHP tab..

    a. Under the General tab, Add Folder... and select the /your-install-path/src/ folder - this will make the auto complete work

    b. Go to Frameworks & Tools tab, PHPUnit, select the /your-install-path/phpunit and /your-install-path/phpunit-skelgen respectively - this will make PHPUnit tool work within Netbeans

  4. In your project settings, right click project name > Settings, Testing category, enable PHPUnit. Optionally go to the Testing > PHPUnit settings panel and make adjustments for your project.

Edit:
When I followed the instructions above, the output window told me I needed to install dependencies using "composer install." These additional steps were needed on my machine (running Netbeans 8.2 on Windows 7).

  1. Download Composer and install: https://getcomposer.org/doc/00-intro.md

  2. Modify your-install-path/composer.json by adding the version number between the "description" and "type" keywords like so:

    "description": "The PHP Unit Testing framework.",
    "version": "5.7.8",
    "type": "library",
    
  3. Using the command line, type the following (this is a windows machine, for mac or lunix, it should be a little different):

    cd your-install-path
    composer install
    

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.