Home » Php » php – Fatal error: Class "PHPUnit_Extensions_Database_TestCase" not found

php – Fatal error: Class "PHPUnit_Extensions_Database_TestCase" not found

Posted by: admin July 12, 2020 Leave a comment


I’m following the documentation of PHPUnit; I’m trying the following example; but it keeps giving me the following error:

“Fatal error: Class “PHPUnit_Extensions_Database_TestCase” not found!

It is working fine for PHPUnit_Framework_TestCase! I also added

require_once 'PHPUnit/Autoload.php';

but still the same error!

class MyGuestbookTest extends PHPUnit_Extensions_Database_TestCase
     * @return PHPUnit_Extensions_Database_DB_IDatabaseConnection
    public function getConnection()
        $pdo = new PDO('sqlite::memory:');
        return $this->createDefaultDBConnection($pdo, ':memory:');

     * @return PHPUnit_Extensions_Database_DataSet_IDataSet
    public function getDataSet()
        return $this->createFlatXMLDataSet(dirname(__FILE__).'/_files/guestbook-seed.xml');


Actually I’m very new to PHPUnit test:

I used Slim framework of PHP: I have not started testing; just trying to understand the logic by going through the documentation; I do have a composer.json file which is the following: (now I added “phpunit/dbunit”: “>=1.2” in require / require-dev, but none of them solved the problem!):

    "name": "slim/slim",
    "type": "library",
    "description": "Slim Framework, a PHP micro framework",
    "keywords": ["microframework","rest","router"],
    "homepage": "http://github.com/codeguy/Slim",
    "license": "MIT",
    "authors": [
            "name": "Josh Lockhart",
            "email": "[email protected]",
            "homepage": "http://www.joshlockhart.com/"
    "require": {        
        "php": ">=5.3.0"
    ,"require-dev": {        
        "phpunit/dbunit": ">=1.2"
    "suggest": {
        "ext-mcrypt": "Required for HTTP cookie encryption"
    "autoload": {
        "psr-0": { "Slim": "." }

If you need more clarification, please let me know and thank you in advance.

How to&Answers:

If you are using Composer, make sure you add the DBUnit optional package.

All credit goes to Phil’s comment!