I've got issue, and can't resolve it :(
I'm trying to set data provider for test in Laravel 5.3.
I have a model Task in app/Task.php file.
I have a factory in database/factories/TaskFactory.php:
$factory->define(App\Task::class, function(Faker\Generator $faker) {
return [
'description' => $faker->text,
];
});
I have a test in tests/TaskTest.php:
class TaskTest extends TestCase
{
public function tasksDataProvider()
{
$tasks = factory(App\Task::class, 10)->create();
// return task ids here
}
/**
* @dataProvider tasksDataProvider
*/
public function testExistingTask($id)
{
// do some assertions with $id here
}
}
When I run phpunit I've got the output:
1) Warning
The data provider specified for
TaskTest::testExistingTask is invalid.
Unable to locate factory with name [default] [App\Task].
Right now I can write:
class TaskTest extends TestCase
{
public function testExistingTask()
{
$tasks = factory(App\Task::class, 10)->create();
// do some assertions with task ids here
}
}
and everything is OK.
How can I make data provider work with factory?
Aucun commentaire:
Enregistrer un commentaire