PHPUnit找不到"TestCase".班级 [英] PHPUnit can't found the "TestCase" class

查看:68
本文介绍了PHPUnit找不到"TestCase".班级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要使用项目的PHPUnit运行测试,请执行以下操作:php vendor/bin/phpunit tests/SomeClassTest.php在给出以下类声明的情况下可以正常工作:

class SomeClassTest extends PHPUnit_Framework_TestCase {
  public function test_someMethod() {}
}

但是当我这样做时它失败了:

use PHPUnit\Framework\TestCase;

class SomeClassTest extends TestCase {
  public function test_someMethod() {}
}

我得到PHP Fatal error: Class 'PHPUnit\Framework\TestCase' not found ...

解决方案

TestCase自PHPUnit 5.4起就存在.如果您设置 5.3标记(请查看ForwardCompatibility文件夹),也可以比较 5.3 和<2. Writing Tests for PHPUnit部分中的href ="https://phpunit.de/manual/5.4/en/writing-tests-for-phpunit.html" rel ="noreferrer"> 5.4 ,其中: /p>

"ClassTest(大部分时间)继承自PHPUnit_Framework_TestCase." 适用于PHPUnit 5.3

"ClassTest(大部分时间)继承自PHPUnit \ Framework \ TestCase." 适用于PHPUnit 5.4

To run my tests using the project's PHPUnit I do the following : php vendor/bin/phpunit tests/SomeClassTest.php which works fine given the following class declaration :

class SomeClassTest extends PHPUnit_Framework_TestCase {
  public function test_someMethod() {}
}

But it fails when I do this :

use PHPUnit\Framework\TestCase;

class SomeClassTest extends TestCase {
  public function test_someMethod() {}
}

I get PHP Fatal error: Class 'PHPUnit\Framework\TestCase' not found...

解决方案

Class TestCase exists since PHPUnit 5.4. You can see it on github if you set 5.3 tag (look for ForwardCompatibility folder) or you can compare doc for 5.3 and 5.4 in the 2. Writing Tests for PHPUnit section where it says:

"ClassTest inherits (most of the time) from PHPUnit_Framework_TestCase." for PHPUnit 5.3

and

"ClassTest inherits (most of the time) from PHPUnit\Framework\TestCase." for PHPUnit 5.4

这篇关于PHPUnit找不到"TestCase".班级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆