使用PHPUnit断言进行的Behat测试

问题描述 投票:0回答:1

我在使用PHPUnit Bridge 5.0的symfony 4.3中有一个项目,我想在功能测试中使用assert函数。在较旧的项目中,我使用了PHPUnit软件包,并通过require_once在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 'PHPUnit\Framework\Assert' not found (Behat\Testwork\Call\Exception\FatalThrowableError)

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

use PHPUnit\Framework\Assert;

但是该类存在,因为我可以手工上它。我在网上寻找一些答案,在这种情况下可能会有所帮助,但这些都不是行不通的。我曾尝试使用:

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

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

phpunit symfony4 behat
1个回答
0
投票

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

use PHPUnit\Framework\Assert as Assertions;
© www.soinside.com 2019 - 2024. All rights reserved.