# PHPUnit 10.5.20 by Sebastian Bergmann and contributors. Runtime:       PHP 8.2.17 Configuration: /var/www/app/phpunit.xml Warning - The data provider specified for Tests\Unit\OrderTest::testDiscount is invalid. Data Provider method Tests\Unit\OrderTest::discountProvider() is not callable or does not return an array of arrays.

- **ID:** `php/phpunit-dataprovider-invalid-return`
- **Domain:** php
- **Category:** test_error
- **Verification:** ai_generated
- **Fix Rate:** 90%

## Root Cause

The @dataProvider annotation references a method that either does not exist, is not static (in PHPUnit 10+), or returns a non-iterable value (e.g., null, string) instead of an array of arrays.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| PHPUnit 10.5.20 | active | — | — |
| PHPUnit 11.0.1 | active | — | — |
| PHP 8.2.17 | active | — | — |

## Workarounds

1. **Ensure the data provider method is declared as public static and returns an array of arrays: public static function discountProvider(): array { return [[10, 5], [20, 10]]; }** (95% success)
   ```
   Ensure the data provider method is declared as public static and returns an array of arrays: public static function discountProvider(): array { return [[10, 5], [20, 10]]; }
   ```
2. **If using PHPUnit 10+, use PHPUnit\Framework\Attributes\DataProvider attribute instead of annotation: #[DataProvider('discountProvider')] public function testDiscount($price, $expected) { ... }** (90% success)
   ```
   If using PHPUnit 10+, use PHPUnit\Framework\Attributes\DataProvider attribute instead of annotation: #[DataProvider('discountProvider')] public function testDiscount($price, $expected) { ... }
   ```

## Dead Ends

- **** — Making the data provider method non-static and using @dataProvider on an instance method works in PHPUnit 9 but fails in PHPUnit 10+ which requires static data providers. (80% fail)
- **** — Returning a single associative array like ['discount' => 10] instead of an array of arrays [[10], [20]] causes PHPUnit to treat each key as a separate test case, often leading to unexpected failures. (70% fail)
