0PricingLogin
PHP Academy · Lesson

Data Providers for Parameterized Tests

Run the same test with multiple inputs using dataProvider.

What Are Data Providers?

A data provider is a method that returns a set of test inputs. PHPUnit calls the test method once per dataset, making it easy to test many input combinations without repeating code.

Basic Data Provider

The provider returns a 2D array. Each sub-array is one call to the test method.

<?php
public static function additionProvider(): array
{
    return [
        "two positives" => [2, 3, 5],
        "negative"      => [-1, 1, 0],
        "zeros"         => [0, 0, 0],
    ];
}

All lessons in this course

  1. PHPUnit Setup and First Test
  2. Assertions and Test Methods
  3. Data Providers for Parameterized Tests
  4. Mocking Dependencies with PHPUnit
← Back to PHP Academy