Add unit tests for OpenAiProvider - #53
noruzzamans wants to merge 7 commits into
Conversation
|
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. |
saarnilauri
left a comment
There was a problem hiding this comment.
Solid looking PR with a nice test addition for a class that genuinely had no direct coverage.
I added few comments that might be good additions to the PR.
Co-authored-by: Lauri Saarni <36833033+saarnilauri@users.noreply.github.com>
Co-authored-by: Lauri Saarni <36833033+saarnilauri@users.noreply.github.com>
Co-authored-by: Lauri Saarni <36833033+saarnilauri@users.noreply.github.com>
Thank you @saarnilauri for the helpful review and guidance! I have accepted all 3 suggestions and updated the tests to cover the capability-skipping and precedence paths you mentioned. All tests and linters pass cleanly. Could you please take another look when you get a chance? |
saarnilauri
left a comment
There was a problem hiding this comment.
Thanks. The first round changes landed well. See the comments for few more followup changes I suggest.
saarnilauri
left a comment
There was a problem hiding this comment.
Thank you again. Now approving.
Description
This PR introduces a dedicated unit test suite for the
OpenAiProviderclass (WordPress\OpenAiAiProvider\Provider\OpenAiProvider).OpenAiProvideris the central entry class for the AI Provider for OpenAI. It handles:url()).metadata()) including ID, name, cloud type, API key authentication, localized descriptions, and SVG logo path.modelMetadataDirectory()) and provider availability checking (availability()).OpenAiTextGenerationModel)OpenAiImageGenerationModel)OpenAiEmbeddingGenerationModel)OpenAiTextToSpeechConversionModel)RuntimeException).While individual model and directory classes had unit tests,
OpenAiProvideritself previously lacked dedicated test coverage.Test Coverage Summary
The newly added test suite (
tests/unit/Provider/OpenAiProviderTest.php) contains 10 tests and 25 assertions covering:url()resolveshttps://api.openai.com/v1and correctly formats subpaths with or without leading slashes.RuntimeExceptionis thrown with expected error messages for unknown or empty capability sets.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 for OpenAiProvider and drafting PR documentation. Code was manually reviewed, locally executed, and verified.