Eclipse and PHPUnit: "The import PHPUnit\Framework\TestCase cannot be resolved"
Asked Answered
I

2

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?

Interdigitate answered 3/4, 2018 at 7:55 Comment(0)
O
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).
Orv answered 21/5, 2018 at 2:30 Comment(4)
Thanks worked for me : Eclipse Version: Oxygen.2 Release (4.7.2) Build id: 20171218-0600Grangerize
Eclipse for PHP Developers Version: Oxygen.3a Release (4.7.3a) Build id: 20180405-1200 having so many problems with project creation wizard and phpunitGrangerize
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-1500Luzern
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 renamedEarthstar
L
0

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.

Luzern answered 19/2 at 12:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.