为 Tests\Feature\BTest::testB 指定的数据提供程序无效。 PHPUnit\Util\Exception: 方法 dataProviderForB 不存在

The data provider specified for Tests\Feature\BTest::testB is invalid. PHPUnit\Util\Exception: Method dataProviderForB does not exist

/**
 * @dataProvider dataProviderForB
 */
public function testB($user, $department, $module)
{
    // ...
}

我的数据提供者是:

public function dataProviderForB()
{
    return [
        [User::first(), Department::first(), Module::first()],
    ];
}

PS C:\xampp\htdocs\w> .\vendor\bin\phpunit
PHPUnit 8.5.8 by Sebastian Bergmann and contributors.

W..                                                                 3 / 3 (100%)

Time: 661 ms, Memory: 24.00 MB

There was 1 warning:

我的错误是:

1) Warning
The data provider specified for Tests\Feature\BTest::testB is invalid.
PHPUnit\Util\Exception: Method dataProviderForB does not exist

WARNINGS!
Tests: 3, Assertions: 2, Warnings: 1.
PS C:\xampp\htdocs\w> .\vendor\bin\phpunit

app() 未在您的测试中生成

您需要像这样将参数传递给您的 testFunction:

public function dataProviderForB()
{
    return [
        [1, 1, 1],
    ];
}

这将解决错误