'Cannot return objects in @dataProvider PHPUnit
Is it allowed to return objects from @dataProviders
to test methods?
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)
{
(...)
Error:
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
is an interface, imports are correct.
Solution 1:[1]
From the 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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | abranhe |