Can phpunit use multiple data provider Can phpunit use multiple data provider php php

Can phpunit use multiple data provider


Just an update to the question, a pull request was accepted and now the code:

/**  * @dataProvider provideInvalidId * @dataProvider provideFailedId */public function testGetByIdUnsuccess($id){       $this->assertNull($this->model->getById($id));}

Will work on PHPUnit 5.7, you'll be able to add as many providers as you want.


You can use a helper function as shown below. The only problem is if the total number of test cases provided by all "sub data providers" is large, it can be tedious to figure out which test case is causing a problem.

/**  * @dataProvider allIds */public function testGetByIdUnsuccess($id){       $this->assertNull($this->model->getById($id));}  public function allIds(){    return array_merge(provideInvalidId(),provideFailedId());}


You can add a comment to your dataProvider array, to provide the same functionality, while not requiring multiple dataProviders.

public static function DataProvider(){    return array(        'Invalid Id'      => array(123),        'Failed Id'       => array(321),        'Id Not Provided' => array(NULL),);}