使用PHPUnit断言进行Behat测试



我在symfony 4.3中有一个使用PHPUnit Bridge 5.0的项目,我想在功能测试(behat(中使用断言函数。在旧的项目中,我使用了PHPUnit包,并要求一次性将这些函数包含在behat Context类中,如下所示:

require_once __DIR__.'/../../vendor/phpunit/phpunit/src/Framework/Assert/Functions.php';

但是PHPUnit Bridge有这样一个类:

require_once __DIR__.'/../../bin/.phpunit/phpunit-7.5-0/src/Framework/Assert/Functions.php';

如果我尝试运行测试,它不会通过,而是出现以下错误:

Fatal error: Class 'PHPUnitFrameworkAssert' not found (BehatTestworkCallExceptionFatalThrowableError)

此错误是由Functions.php类中的首次使用引起的,该类为:

use PHPUnitFrameworkAssert;

但那个班是存在的,因为我可以亲手去。我在网上寻找一些答案,在这种情况下可能会有所帮助,但这些都不起作用。我曾经尝试过使用:

use PHPUnit_Framework_Assert as Assertions;
// Class which implement that what I need exist too in namespace PHPUnitFramework with name Assert 
use PHPUnitFrameworkAssert as Assertions; 

我做错了什么??谢谢你的帮助。

我找到了解决方案。如果有人有同样的问题,只需安装phpunit/phpunit组件,并忽略来自PHPUnitBridge的警告。然后通过以下方式在后台使用:

use PHPUnitFrameworkAssert as Assertions;

对我有用的东西:

use PHPUnitFrameworkAssert;
// Then later, to check that the status is equal to 7
Assert::assertEquals(7, $this->status);

最新更新