2
votes

I am updating a legacy PHP project to use composer, and implementing PHPUnit. unfortunately I have run into a few issues. When running PHPUnit

Fatal error: Class 'PHPUnit_Framework_TestCase' not found

composer.json

{
    "require": {
        "phpunit/phpunit": "^8.0",
        "phpoffice/phpspreadsheet": "^1.6"
    },
    "autoload": {

        "psr-4": {"Biz\\": "src/php/Classes"}
    }
}

phpunit.xml

<?xml version="1.0" encoding="UTF-8"?>
<phpunit
         bootstrap="vendor/autoload.php"
         verbose="true">
  <testsuites>
  <testsuite name="Random Tests">
    <directory>./src/test/random/*Test.php files</directory>
  </testsuite>
</testsuites>
</phpunit>

Directory structure

directory structure

Command line being executed

$ ./vendor/bin/phpunit ./src/test/random/SampleTest.php

I am running it using git-bash. executing from visual studio code gives the same result. I have read, implemented the issue as described in Autoloading classes in PHPUnit using Composer and autoload.php

Test Case

<?php

class SampleTest extends \PHPUnit_Framework_TestCase {
    public function testUserClassInheritance(){
        global $mysqlConn;
        echo "testing";
        $this->assertTrue(true);

        $user = new Bruger;
    }
}
1
Try extending \PHPUnit\Framework\TestCase instead of PHPUnit_Framework_TestCase. Also, please show your test class code, so we can see how you are defining the test class, including any namespace information, without us having to make assumptions.Willem Renzema

1 Answers

2
votes

PHPUnit_Framework_TestCase does not exist in PHPUnit version 8, which is your minimum specified version. As of (I think) PHPUnit version 5, it's using namespaces, so your test case should be named \PHPUnit\Framework\TestCase.

You can downgrade your PHPUnit requirement to an older version, or (preferably) update your tests to meet the new naming style.