2

I've got a problem with PhpStorm, composer and PHPUnit.

  • Windows 8.1 Pro (64 bit)
  • PhpStorm is up to date: 2018.2.2
  • Tried different PHP interpreters like XAMPP and a clean PHP for win
  • PHPUnit is required by composer with: "phpunit/phpunit": "^7.3.3".
  • PHPUnit is successfully installed via composer to the vendor directory as well.
  • PHPUnit is recognized from PhpStorm:

enter image description here

My test class extends the PhpUnit\Framework\TestCase class and when you run the test, the following happens:

enter image description here

First it seems like PhpStorm loads the old PHPUnit (3.7.21) from XAMPP's PHP and not the recognized PHPUnit (7.3.3) as setup in the PhpStorm settings / installed to the vendor folder.

But I don't think so.

I think PhpStorm tries to load the PhpUnit\Framework\TestCase class by the autoloader, but I don't know why it doesn't find the PHPUnit...

Thanks in advance!


The whole project could be minimized to this simple test class:

enter image description here

The composer.json looks like the following:

"autoload": {
  "psr-4": {
    "Flo\\Newsletter\\": "src/"
  }
},
"require": {
  "php": "^7.1"
},
"require-dev": {
  "phpunit/phpunit": "^7.3.3"
}
2
  • 2
    Please note that PhpStorm doesn't load anything. It just forms a command that is executed later. Please check what would C:\xampp\php\php.exe C:/Users/flb/dev/composer/newsletter/vendor/phpunit/phpunit/phpunit --version return. If it's 7.3.3, then there's a problem in the code, and we need the project to understand what's wrong. Commented Sep 4, 2018 at 7:40
  • Thanks Eugene Morozov, I've just edited the question above. Commented Sep 4, 2018 at 8:22

1 Answer 1

3

Namespaces are case-sensitive. Please change PhpUnit to PHPUnit in the import.

Although PhpStorm could really detect that. Here's a feature request for that: https://youtrack.jetbrains.com/issue/WI-38140

Sign up to request clarification or add additional context in comments.

1 Comment

Oh my! use PHPUnit\Framework\TestCase; solves the problem! I don't know why it was PhpUnit... I always use PhpStorm's suggests... Thanks man.

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.