Skip to content

Add unit tests for QueryTrait#20773

Open
WarLikeLaux wants to merge 2 commits intoyiisoft:masterfrom
WarLikeLaux:test-query-trait
Open

Add unit tests for QueryTrait#20773
WarLikeLaux wants to merge 2 commits intoyiisoft:masterfrom
WarLikeLaux:test-query-trait

Conversation

@WarLikeLaux
Copy link
Contributor

Q A
Is bugfix?
New feature?
Breaks BC?
Fixed issues

What does this PR do?

Adds isolated unit tests for QueryTrait methods via Query without database connection.

Before

No dedicated unit test for QueryTrait.
Existing QueryTest extends DatabaseTestCase and requires DB connection.

After

Tests: 96, Assertions: 111
Methods: 73% (11/15), Lines: 86% (70/81)
MSI: 91% (101/111 mutants killed)

4 methods and 11 lines uncovered - QueryTrait::where(), andWhere(), orWhere() trait versions are not executed because Query overrides them with parameter binding support. Line 235 is a defensive guard (!is_array) unreachable through filterWhere() which type-hints array.

Escaped mutants (all equivalent)

QueryTrait.php (10): ProtectedVisibility ×3 - L232, L302, L365, protectedprivate always equivalent. IncrementInteger - L238, condition[0]condition[1]: hash format never has numeric keys, operator format always has both. DecrementInteger ×3 - L272, L272, L279, array_key_exists(1,...)array_key_exists(0,...): after array_shift, keys 0-2 always exist in well-formed conditions. IncrementInteger - L272, same reason. LogicalAnd - L272, &&||: both keys always present, guard is defensive. PregMatchRemoveCaret - L378, ^ redundant with non-greedy (.*?) at start.

Changelog not required, because no source files changed.

@codecov
Copy link

codecov bot commented Mar 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.13%. Comparing base (37b6e7b) to head (331dd72).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff            @@
##             master   #20773   +/-   ##
=========================================
  Coverage     80.13%   80.13%           
  Complexity    11533    11533           
=========================================
  Files           374      374           
  Lines         30206    30206           
=========================================
  Hits          24207    24207           
  Misses         5999     5999           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

1 participant