Refer1
Refer2
Refer3
Refer4
Refer5
phpunit-9
phpunit
Error
Fatal error: Class 'PHPUnit\Framework\TestCase' not found in C:\xampp\htdocs\daily-news\EasyRSA\test\KeyPairTest.php on line 6
I am working on creating a PHP library and want to start writing tests. I am getting an error Fatal error: Class 'PHPUnit\Framework\TestCase' not found.
My project structure is: in my main directory I have composer.json, a src/ directory with all my classes, a tests/ directory with unit/ and acceptance/ subdirectories. The tests I am trying to run are in the the unit/ directory. I am using the command line interface to run the test so the error happens when running phpunit tests/unit/testMyClass.php
testMyClass.php looks like:
<?php
require 'vendor/autoload.php';
use PHPUnit\Framework\TestCase;
class MyClassTest extends TestCase {
public function testCreateMyClass() {
// Tests are written here
}
}
?>
My composer.json is:
{
"require-dev": {
"phpunit/phpunit": "4.8.*"
}
"autoload": {
"classmap": [
"src/"
}
}
}
Solution
case 1:run composer install
case 2:
I solved the problem with newer version of PHPUnit:
wget https://phar.phpunit.de/phpunit-6.0.phar
php phpunit-6.0.phar -c app/
case 3:
I solve my problem with:
extends PHPUnit\Framework\TestCase
class MyClassTest extends PHPUnit\Framework\TestCase {
public function testCreateMyClass() {
// Tests are written here
}
}
or
class MyClassTest extends PHPUnit_Framework_TestCase {
public function testCreateMyClass() {
// Tests are written here
}
}
case 4:
You appear to have one, or both of two problems.
Not using Composer, This will also provide a vendor/autoload.php file, that will automatically pull in any files that have been included via the composer.json file.
The latest version of PHPunit (v>6.0) no longer uses the long class names. the still-supported v5+ does though.
The recommended mechanism to install PHPunit 5.7 is:
composer require --dev phpunit/phpunit:^5.7
Alternatively, it can be downloaded as a single phpunit.phar that can be run much as any other PHP script.
case 5:
php-fatal-error-class-phpunit-framework-testcase-not-found-with-phpunit-6-and
Just in case you are facing PHPUnit\Framework\TestCase not found in PhpStorm,
run php bin/phpunit at root of project
, it will download all needed classes and PhpStorm error should gone
case 6:
case 7:
Top comments (0)