Repository navigation
Tests: Add unit test coverage for GoogleTextToSpeechConversionModel - #49
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. |
superdav42
left a comment
There was a problem hiding this comment.
Thanks for backfilling coverage for the TTS model from #31. The file location, namespace and the anonymous-subclass pattern for exposing protected methods match tests/Models/GoogleTextGenerationModelTest.php, phpcs is clean, and CI passes.
I ran the suite locally and also mutation-probed GoogleTextToSpeechConversionModel to see what the new tests actually catch. A few assertions are weaker than their names suggest, so I'm requesting a small set of changes (inline suggestions below):
@sincetags should ben.e.x.trather than1.2.0. 1.2.0 has already shipped (#46), and the release process replacesn.e.x.tplaceholders, including intests/.testParseResponseWithDefaultSampleRateFallbackomitsmimeTypeentirely, so it exercises the default MIME type inextractInlineAudioData(), not theparseSampleRate()fallback described in its docblock. Changing that fallback toreturn 0;still passes the suite.assertStringContainsString('data', $wavBytes)always passes, because the fixture PCM string'dummy-raw-pcm-audio-stream-data'itself containsdata.preparePromptText()non-text handling isn't exercised. The empty-prompt test uses a message with no parts, so if thegetText() !== nullguard is removed, everything still passes.
With all suggestions applied locally: OK (16 tests, 63 assertions), phpcs clean, and each of the three mutations above is now caught.
Non-blocking, for a possible follow-up: the four anonymous subclasses could collapse into a single createModel(?ModelConfig $config = null) helper that exposes all four protected methods.
Co-authored-by: David Stone <david@nnucomputerwhiz.com>
Co-authored-by: David Stone <david@nnucomputerwhiz.com>
Co-authored-by: David Stone <david@nnucomputerwhiz.com>
Co-authored-by: David Stone <david@nnucomputerwhiz.com>
Co-authored-by: David Stone <david@nnucomputerwhiz.com>
Co-authored-by: David Stone <david@nnucomputerwhiz.com>
|
Thanks @superdav42! Accepted all suggestions and updated in fd6f383:
All 13 CI matrix checks (PHP 7.4â8.4) and local PHPCS/PHPStan suites are passing cleanly. |
Summary
This pull request introduces dedicated unit test coverage for the
GoogleTextToSpeechConversionModelclass (src/Models/GoogleTextToSpeechConversionModel.php).While the text generation model possesses dedicated unit test coverage, the text-to-speech conversion model previously lacked isolated unit test verification. This suite verifies the full lifecycle of request parameter assembly, prompt validation, audio packaging, response parsing, and authentication wrapping.
Test Coverage Highlights
Parameter Assembly (
prepareConvertParams):AUDIOresponse modality and resolves the defaultKorevoice.Puck) properly override default voice selection.generationConfig.*parameters alongside top-level request parameters.generationConfig(e.g.responseModalities) throw anInvalidArgumentException.contents) throw anInvalidArgumentException.Prompt Processing (
preparePromptText):InvalidArgumentException.Response Parsing & Audio Container Handling (
parseResponseToGenerativeAiResult):GenerativeAiResultwith expected ID prefix (google-tts-) andstopfinish reason.audio/wavFileinstances containing valid RIFF/WAVE container headers wrapping raw PCM data.rate=16000) is parsed from MIME types and encoded into the WAV header.ResponseExceptionerrors.WAV Container Construction (
wrapPcmInWav):1, channels, sample rate, byte rate, block align, and bits per sample).Authentication Handling (
getRequestAuthentication):ApiKeyRequestAuthenticationinstances are wrapped intoGoogleApiKeyRequestAuthenticationwith matching credentials.Verification
1. Isolated PHPUnit Suite
vendor/bin/phpunit tests/Models/GoogleTextToSpeechConversionModelTest.php # OK (16 tests, 63 assertions)2. Full PHPUnit Suite
3. PHP CodeSniffer (PER / PSR-12 / WordPress Standards)
composer run-script phpcs # 14 / 14 (100%) - 0 errors, 0 warnings4. PHPStan Static Analysis (Level 8 / Max)
composer run-script phpstan # [OK] No errors