Issue
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
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;
}
}
Solution
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.
Answered By - Alex Howansky
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.