2

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
  • 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. Commented Feb 15, 2019 at 19:57

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

3 Comments

I was following youtube.com/watch?v=cQucsmbOkpE which apparently used an older PHPUnit version. \PHPUnit\Framework\TestCase works!
Note the (probably) next-biggest change you'll have to deal with is that @expectedException is replaced with $this->expectException(). Other than that, most old tests should still run pretty cleanly.
I have no experience with PHPUnit, so I will make sure that I lookup docs for >8. My next challenge is implementing a psr-4 classpath include for my bespoke classes...

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.