6

I'm starting with PHPUnit, and it works fine so far. I just got one problem: Eclipse (Oxygen.3) is telling me in this line:

use PHPUnit\Framework\TestCase;

"The import PHPUnit\Framework\TestCase cannot be resolved"

I went to Window -> Preferences -> PHP -> Tools -> PHPUnit and added the path to my phpunit.phar. But this didn't help.

I went to Window -> Preferences -> PHP -> Source Paths -> Libraries and tried to import my phpunit.phar. But this results in an error "The selected file is not a valid user library data file".

Any other ideas how to get rid of this error?

2 Answers 2

8

I was having the same problem and this solution worked for me:

  1. Going into Project > Properties
  2. Under PHP > Include Path, pick the "Libraries" tab.
  3. On "Add External PHARs..." select the PHPUnit framework file on your system (phpunit.phar).
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks worked for me : Eclipse Version: Oxygen.2 Release (4.7.2) Build id: 20171218-0600
Eclipse for PHP Developers Version: Oxygen.3a Release (4.7.3a) Build id: 20180405-1200 having so many problems with project creation wizard and phpunit
Thanks a lot! It fixed reported problems after upgrading PHPTools in Eclipse for PHP Developers Version: Neon.3 Release (4.6.3) Build id: 20170314-1500
Hi all why doesn't usr/local/bin phar file moved from mv phpunit.phar /usr/local/bin/phpunit this command changes file extenstions .phar renamed
1

In my case I was not able to Add External PHARs... as it ends up with error Build path entry is invalid: org.ecl...nt/C:/xampp/php/phpunit-11.0.3.phar.

What worked was to Add External Source Folder with the PHPUnit source code in /xampp/php/pear/PHPUnit folder.

Steps to create the external folder with PHPUnit:

  • download the ZIP from PHPUnit Github repository
  • Extract that .zip to folder into my PEAR/PHPUnit folder
    • folder will contain schema/ src/ etc.
  • In Eclipse go to Project > Properties
  • PHP > Source Paths > Include Path > Libraries tab
  • [Add External Source Folder...] browse to the PHPUnit folder created earlier
  • [Apply and Close]

After project refresh F5 the PHPUnit methods were available.

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.