Repository navigation
Add unit tests for ErrorMessageExtractor - #297
noruzzamans wants to merge 1 commit into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## trunk #297 +/- ##
============================================
+ Coverage 86.58% 87.03% +0.44%
Complexity 1383 1383
============================================
Files 69 69
Lines 4449 4449
============================================
+ Hits 3852 3872 +20
+ Misses 597 577 -20
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Description
This PR introduces a comprehensive PHPUnit unit test suite for the
ErrorMessageExtractorutility class (WordPress\AiClient\Providers\Http\Util\ErrorMessageExtractor).ErrorMessageExtractorcentralizes the parsing and extraction of human-readable error messages from various API response shapes returned by generative AI providers (such as OpenAI, Google Gemini, Anthropic) when HTTP errors occur (ClientExceptionandServerException).While the sibling
ResponseUtilTestexercises high-level HTTP status code handling,ErrorMessageExtractoritself previously lacked a dedicated unit test suite. This contribution fills that gap by verifying all supported response structures, format precedence, and edge-case payload validation.Test Coverage Summary
The newly added test suite (
tests/unit/Providers/Http/Util/ErrorMessageExtractorTest.php) contains 40 tests and 42 assertions covering:extractFromResponseDatasafely returnsnullwhen input is not an array (null, empty string, non-empty string, integer, float, boolean, object).[ [ 'error' => [ 'message' => '...' ] ] ](Google Gemini / batch error format).[ 'error' => [ 'message' => '...' ] ](OpenAI format).[ 'error' => '...' ].[ 'message' => '...' ].nullis safely returned for empty arrays, missing keys, non-string messages (integers, booleans, arrays, nulls), and non-array array elements.Verification & Testing
All local test suites and linters pass cleanly:
Use of AI Tools
AI assistance: Yes
Model(s): Gemini 3.8 Flash High
Used for: Authoring PHPUnit unit tests, data providers, and test documentation for ErrorMessageExtractor. Code reviewed and locally validated by human contributor.