找不到类“PHPUnit_Framework_TestCase" [英] Class 'PHPUnit_Framework_TestCase' not found
问题描述
此错误发生在我的公共构建项目上:https://travis-ci.org/byjg/authuser/jobs/211336643
This error occurs on my public build project: https://travis-ci.org/byjg/authuser/jobs/211336643
我在我的 Ubuntu 上使用 php 7.0 和 php 7.1 在本地运行,没有出现这个问题.
I ran locally using php 7.0 and php 7.1 on my Ubuntu and this problem does not occur.
Travis 在 PHP 5.6 上运行成功
Travis runs successful on PHP 5.6
你能帮我吗?
推荐答案
PHPUnit
<6 和 PHPUnit
6 之间的命名空间结构存在差异.
There is a difference between namespace structure between PHPUnit
<6 and PHPUnit
6.
为了向后兼容,您可以考虑以下解决方案:
You may consider the following solution for backward compatibility:
// backward compatibility
if (!class_exists('\PHPUnit\Framework\TestCase') &&
class_exists('\PHPUnit_Framework_TestCase')) {
class_alias('\PHPUnit_Framework_TestCase', '\PHPUnit\Framework\TestCase');
}
旧的 PHPUnit
版本使用 \PHPUnit_Framework_TestCase
但新版本使用 \PHPUnit\Framework\TestCase
.应用向后兼容性后,您可以使用与新版本 PHPUnit
(即 \PHPUnit\Framework\TestCase
)兼容的类名,它也可以正常工作使用旧版本.
The old PHPUnit
versions use \PHPUnit_Framework_TestCase
but the new one uses \PHPUnit\Framework\TestCase
. With the backward compatibility applied you can use the class name that is compatible with the new version of PHPUnit
(i.e. \PHPUnit\Framework\TestCase
) and it is going to work also with older versions.
更新为了涵盖对 PHP 5.3 的支持,您必须在别名类之前删除 \
字符,即
Update
In order to cover support for PHP 5.3 you have to remove a \
character before the alias class, i.e.
class_alias('\PHPUnit_Framework_TestCase', 'PHPUnit\Framework\TestCase');
这篇关于找不到类“PHPUnit_Framework_TestCase"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!