Skip to content

Unit tests - #850

Merged
alexander-b-clean merged 1 commit into
devfrom
test-refactoring.ab
Aug 6, 2026
Merged

Unit tests#850
alexander-b-clean merged 1 commit into
devfrom
test-refactoring.ab

Conversation

@alexander-b-clean

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_get response and more descriptive test names.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov

codecov Bot commented Aug 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 27.92%. Comparing base (0a8de78) to head (2346d09).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() uses if (!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);

@alexander-b-clean
alexander-b-clean merged commit 2059c1f into dev Aug 6, 2026
11 checks passed
@alexander-b-clean
alexander-b-clean deleted the test-refactoring.ab branch August 6, 2026 10:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants