marbobo's avatar
Level 12

Is it possible to add dataprovider from diffirent class?

Hi.. I am wondering if its possible to write the data provider on another class instead of another method inside the test class..

0 likes
2 replies
martinbean's avatar

@kdev Why? It makes far more sense to co-locate the data provider with the test case method that actually uses it.

marbobo's avatar
marbobo
OP
Best Answer
Level 12

answering my question.. here is what I did.

/**
 * @test
 * @param array $params
 * @dataProvider \Tests\DataProviders\SampleDataProvider::createEndpointDataProvider
 */
public function test_create_endpoint(array $params)
{
    $request = $this->post('v1/endpoint', $params);

    self::assertEquals(200, $request->response->status());
    self::seeInDatabase('table_name', $params);
    self::seeJsonStructure([
        'id',
        'name',
        'user_id',
    ]);
}

Please or to participate in this conversation.