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/"
}
}
}
composer install? Does your testMyClass.php file is in the same directory of your vendor directory (where you also run thecomposer install)?use PHPUnit_Framework_TestCase as TestCase;if you want to, otherwise just extend the full class name.