{
  "id": "php/phpunit-dataprovider-invalid-return",
  "signature": "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.",
  "signature_zh": "PHPUnit 10.5.20 由 Sebastian Bergmann 和贡献者编写。运行时：PHP 8.2.17 配置：/var/www/app/phpunit.xml 警告 - 为 Tests\\Unit\\OrderTest::testDiscount 指定的数据提供者无效。数据提供者方法 Tests\\Unit\\OrderTest::discountProvider() 不可调用或未返回数组的数组。",
  "regex": "The data provider specified for .+ is invalid\\. Data Provider method .+ is not callable or does not return an array of arrays",
  "domain": "php",
  "category": "test_error",
  "subcategory": null,
  "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.",
  "root_cause_type": "generic",
  "root_cause_zh": "@dataProvider 注解引用的方法要么不存在，要么不是静态的（在 PHPUnit 10+ 中），要么返回非可迭代值（例如 null、字符串）而不是数组的数组。",
  "versions": [
    {
      "version": "PHPUnit 10.5.20",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "PHPUnit 11.0.1",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "PHP 8.2.17",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "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.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "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.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "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]]; }",
      "success_rate": 0.95,
      "how": "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]]; }",
      "condition": "",
      "sources": []
    },
    {
      "action": "If using PHPUnit 10+, use PHPUnit\\Framework\\Attributes\\DataProvider attribute instead of annotation: #[DataProvider('discountProvider')] public function testDiscount($price, $expected) { ... }",
      "success_rate": 0.9,
      "how": "If using PHPUnit 10+, use PHPUnit\\Framework\\Attributes\\DataProvider attribute instead of annotation: #[DataProvider('discountProvider')] public function testDiscount($price, $expected) { ... }",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "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]]; }",
    "If using PHPUnit 10+, use PHPUnit\\Framework\\Attributes\\DataProvider attribute instead of annotation: #[DataProvider('discountProvider')] public function testDiscount($price, $expected) { ... }"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://docs.phpunit.de/en/10.5/annotations.html#dataProvider",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.84,
  "fix_success_rate": 0.9,
  "resolvable": "true",
  "first_seen": "2024-04-05",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}