【发布时间】:2019-07-09 23:50:42
【问题描述】:
我正在更新一个旧的 PHP 项目以使用 composer,并实现 PHPUnit。不幸的是,我遇到了一些问题。运行 PHPUnit 时
致命错误:找不到类“PHPUnit_Framework_TestCase”
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>
目录结构
正在执行的命令行
$ ./vendor/bin/phpunit ./src/test/random/SampleTest.php
我正在使用 git-bash 运行它。从 Visual Studio 代码执行会得到相同的结果。我已阅读并按照Autoloading classes in PHPUnit using Composer and autoload.php
中的描述实现了该问题测试用例
<?php
class SampleTest extends \PHPUnit_Framework_TestCase {
public function testUserClassInheritance(){
global $mysqlConn;
echo "testing";
$this->assertTrue(true);
$user = new Bruger;
}
}
【问题讨论】:
-
尝试扩展 \PHPUnit\Framework\TestCase 而不是 PHPUnit_Framework_TestCase。另外,请展示您的测试类代码,这样我们就可以看到您是如何定义测试类的,包括任何命名空间信息,而无需我们做出假设。
标签: php composer-php phpunit