3

I get this error when running trying to run unit tests from PhpStorm:

Fatal error: Class 'TestCase' not found in C:\xampp\htdocs\etestproject\app\tests\ExampleTest.php on line 3

There was a similar posts here, here and here but they didn't really help me.

I can run:

phpunit app/tests/

from my project's root directory but not from PhpStorm

Additional info:

When i add 'Illuminate\Foundation\Testing\TestCase' to my app/confg/app.php and run composer update after that it doesn't pass and if i add/require "phpunit/phpunit" to my composer.json and rum my tests from PhpStorm they still give back the same error.

Community
  • 1
  • 1
Traveller
  • 399
  • 2
  • 20

3 Answers3

9
  1. Go to Settings > Languages & Frameworks > PHPUnit
  2. Select 'Load from include path'
  3. Tick 'Default configuration file' and enter '/you_project_path/phpunit.xml'
MSI
  • 844
  • 9
  • 8
2

Maybe is an old topic but i was looking for the same problem.

For me the solution was to indicate in the phpstorm configuration for "phpunit" the path for the "phpunit.xml" file with the minimal information + path to the Composer autoloader:

<?xml version="1.0" encoding="UTF-8"?>

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/5.5/phpunit.xsd"
     backupGlobals="false"
     colors="true"
     bootstrap="vendor/autoload.php"
>
</phpunit>

phpstorm configuration

Maybe it could help to someone in the future

Regards!

Félix
  • 41
  • 3
1

I ran into a similar situation recently - I found that I was invoking PHPUnit with the wrong PHP interpreter and that caused a Class 'SomeClass' not found error.

In PHPStorm settings, you can navigate to Languages & Frameworks > PHP to check what installation of PHP it's choosing.

enter image description here

In my case, I was running PHPUnit using OSX's default PHP installation, but running my dev site with a PHP installation created by MAMP. When I switched to use MAMP's PHP installation, all the issues disappeared.

HPierce
  • 7,249
  • 7
  • 33
  • 49