0

I'm trying to get phpunit to work inside phpstorm and I'm getting the following error

Fatal error: Class 'PHPUnit_Framework_TestCase' not found

I'm using version 7.1.12 of php and phpunit version 7.1.5.

I've searched for solutions to this but can't find anything that's been able to help me.

Any ideas on how to fix this?

The Test Configuration

The Test Configuration.

2 Answers 2

1

There is no PHPUnit_Framework_TestCase class in PHPUnit 6. Since version 6 PHPUnit uses namespaces, so you should use PHPUnit\Framework\TestCase instead. If you cant do this, you should downgrade to PHPUnit 5 or create aliases for missing classes:

if (!class_exists('PHPUnit_Framework_Assert')) {
    class_alias('PHPUnit\Framework\Assert', 'PHPUnit_Framework_Assert');
}

if (!class_exists('PHPUnit_Framework_TestCase')) {
    class_alias('PHPUnit\Framework\TestCase', 'PHPUnit_Framework_TestCase');
}
Sign up to request clarification or add additional context in comments.

Comments

0

PHPStorm needs to be able to locate and run PHPUnit. If your project uses composer you can configure it to load it from there. If not, PHPStorm can download it for you. Setting up PHPUnit in PHP Storm

8 Comments

Thanks of the reply. I tried that and got the same error. The version of PHPUnit I have is 6.2.4. Should I downgrade to 5.7.27 and try that?
What PHP Storm are you running?
I'm using version 2018.1.2
You could downgrade to PHP Unit 5.x and it will probably work. I find strange that PHP Storm did not detect the correct version to use. Maybe you are not using composer to get PhpUnit as I've shown in the posted image.
Can you get phpunit to run from the command line first? That may be a better idea!
|

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.