Skip to content

Latest commit

 

History

History
23 lines (16 loc) · 826 Bytes

use-data-providers.md

File metadata and controls

23 lines (16 loc) · 826 Bytes

Use data providers to provide variations on input

Data providers are a concise way to arrange variations on input data for a test. To use one, create a function that returns an array of data. Next, annotate a test with dataProvider and take in the data as a parameter.

// Assumes inside PHPUnit test class

public function myProvider() {
  return [1, 2, 3];
}
    
/**
* @dataProvider myProvider
*/
public function testDataAreNumbers($num) {
  $this->assertEquals(true, is_numeric($num));
}

This will run the test with each data value.

Read the documentation. Tighten has a nice blog post.