php - 无法在@dataProvider PHPUnit 中返回对象

标签 php phpunit tdd testng-dataprovider

是否允许从 @dataProviders 返回对象测试方法?

public function iOsMessages()
{
    return [
        'update available'        => [1, new UpToDateMessage(), 'pl'],
    ];
}

/**
 * @test
 * @dataProvider iOsMessages
 */
public function success_create_message_for_ios(int $appVersion, MobileMessage $message, string $locale)
{
(...)

错误:

The data provider specified for Tests\Tests\Mobile\Classes\AppVersionTest::success_create_message_for_ios is invalid. Class 'Mobile\Classes\Messages\UpToDateMessage' not found


MobileMessage是一个接口(interface),导入是正确的。

最佳答案

来自 documentation :

A data provider method must be public and either return an array of arrays or an object that implements the Iterator interface and yields an array for each iteration step.

关于php - 无法在@dataProvider PHPUnit 中返回对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48625741/

相关文章:

PHPUnit Selenium 服务器 - 更好/自定义错误处理?

javascript - 检测 console.log() 调用

php - 从url批量下载文件

php - 如何处理 Web 应用程序数据库中的评论

php - mysql 存储用户代理、推荐等的最有效方式

python - fatal error : pathspec did not match any files using git rm to remove the pyc file

unit-testing - TDD:为什么是 'Red Green Refactor' 而不是 'Green Refactor' ?

php - 如何将印地语文本转换为 UTF-8?

php - 如何使用不同的 Linux 用户运行 PHPUnit

PHPUnit 测试断言函数/var 是公有的还是 protected ?