Unit tests - #850
Conversation
There was a problem hiding this comment.
Pull request overview
Updates the unit tests for \Cleantalk\ApbctWP\CleantalkSettingsTemplates to be deterministic in CI by removing reliance on a real API key/network calls and validating behavior via a mocked templates cache.
Changes:
- Replace API-key/network-dependent tests with tests that mock the templates static cache via reflection.
- Add coverage for
getHtmlContent()output (import/export/reset presence, import-only mode, and no-suitable-templates scenario). - Improve test clarity with a fixture representing a real
services_templates_getresponse and more descriptive test names.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #850 +/- ##
============================================
+ Coverage 27.71% 27.92% +0.20%
Complexity 6079 6079
============================================
Files 283 283
Lines 25241 25241
============================================
+ Hits 6996 7048 +52
+ Misses 18245 18193 -52 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Suppressed comments (2)
tests/ApbctWP/TestCleantalkSettingsTemplates.php:55
- The docblock implies the templates cache always prevents API calls, but in production
getOptionsTemplate()usesif (!self::$templates), so an empty cached array would still trigger an API request. Clarify that this guarantee holds only when the cache is already populated (non-empty).
/**
* Templates are stored in the static cache, so no API request is performed
* and the API key value does not matter at all.
*/
tests/ApbctWP/TestCleantalkSettingsTemplates.php:80
assertStringNotContainsString("data-id='5678'", $html)can pass even if the template appears in the export select (or if the import markup changes quoting), because it searches the whole HTML output. Narrow the assertion to the import<select>content so the test checks the intended behavior (skipped in import list) without being brittle.
// The template with a filled options_site is available for import
$this->assertStringContainsString("data-id='1234'", $html);
// The template without options_site is skipped in the import list
$this->assertStringNotContainsString("data-id='5678'", $html);
https://app.doboard.com/1/task/39198