{
  "id": "php/phpunit-mock-builder-method-exists",
  "signature": "PHPUnit\\Framework\\MockObject\\RuntimeException: Trying to configure a method \"getUser\" that does not exist on mock class \"App\\Service\\UserService\"",
  "signature_zh": "PHPUnit\\Framework\\MockObject\\RuntimeException：尝试配置模拟类 \"App\\Service\\UserService\" 上不存在的方法 \"getUser\"",
  "regex": "/Trying to configure a method \"[^\"]+\" that does not exist on mock class \"[^\"]+\"/",
  "domain": "php",
  "category": "test_error",
  "subcategory": null,
  "root_cause": "PHPUnit's mock builder is trying to configure a method that does not exist on the mocked class, usually due to a typo in the method name or the method being private/final/static.",
  "root_cause_type": "generic",
  "root_cause_zh": "PHPUnit 的模拟构建器试图配置模拟类上不存在的方法，通常是由于方法名拼写错误或该方法为私有/最终/静态方法。",
  "versions": [
    {
      "version": "PHPUnit 10.5",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "PHPUnit 11.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Adding a @runInSeparateProcess annotation to the test method to isolate state",
      "why_fails": "This does not fix the method name mismatch; it just runs the test in a separate process, which may mask the error but the underlying issue persists.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "Using createMock() instead of getMockBuilder() assuming it's a builder issue",
      "why_fails": "createMock() also uses the same method existence check internally; the error will still occur if the method does not exist.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Verify the method name spelling and visibility. Run `php -r \"echo (new ReflectionMethod('App\\\\Service\\\\UserService', 'getUser'))->isPublic() ? 'public' : 'not public';\"` to check if the method exists and is public.",
      "success_rate": 0.95,
      "how": "Verify the method name spelling and visibility. Run `php -r \"echo (new ReflectionMethod('App\\\\Service\\\\UserService', 'getUser'))->isPublic() ? 'public' : 'not public';\"` to check if the method exists and is public.",
      "condition": "",
      "sources": []
    },
    {
      "action": "If the method is static or final, use `onlyMethods()` with the method name, or refactor the class to make the method non-final. Example: `$mock = $this->getMockBuilder(UserService::class)->onlyMethods(['getUser'])->getMock();`",
      "success_rate": 0.8,
      "how": "If the method is static or final, use `onlyMethods()` with the method name, or refactor the class to make the method non-final. Example: `$mock = $this->getMockBuilder(UserService::class)->onlyMethods(['getUser'])->getMock();`",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Verify the method name spelling and visibility. Run `php -r \"echo (new ReflectionMethod('App\\\\Service\\\\UserService', 'getUser'))->isPublic() ? 'public' : 'not public';\"` to check if the method exists and is public.",
    "If the method is static or final, use `onlyMethods()` with the method name, or refactor the class to make the method non-final. Example: `$mock = $this->getMockBuilder(UserService::class)->onlyMethods(['getUser'])->getMock();`"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://docs.phpunit.de/en/10.5/test-doubles.html#test-double-apis",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.88,
  "fix_success_rate": 0.9,
  "resolvable": "true",
  "first_seen": "2023-11-20",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}