Skip to content

Add unit tests for REST classes#20783

Open
WarLikeLaux wants to merge 2 commits intoyiisoft:masterfrom
WarLikeLaux:add-rest-action-tests
Open

Add unit tests for REST classes#20783
WarLikeLaux wants to merge 2 commits intoyiisoft:masterfrom
WarLikeLaux:add-rest-action-tests

Conversation

@WarLikeLaux
Copy link
Contributor

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

What does this PR do?

Add tests for all yii\rest classes - covers Action, ActiveController, Controller, CreateAction, UpdateAction, DeleteAction, ViewAction, OptionsAction, and fills gaps in IndexAction, Serializer, UrlRule. Extract shared stubs from IndexActionTest into stubs/RestController and stubs/RestModule.

Coverage

File Tests Lines MSI
Action.php 6 15/15 (100%) 70% (12/17)
ActiveController.php 14 43/43 (100%) 77% (23/30)
Controller.php 4 23/23 (100%) 100% (13/13)
CreateAction.php 6 14/14 (100%) 93% (15/16)
UpdateAction.php 5 8/8 (100%) 100% (8/8)
DeleteAction.php 4 6/6 (100%) 100% (5/5)
ViewAction.php 4 4/4 (100%) 100% (4/4)
OptionsAction.php 5 6/6 (100%) 100% (6/6)
IndexAction.php 6 → 10 39/47 (83%) → 47/47 (100%) 77% (17/22)
Serializer.php 15 → 22 57/76 (75%) → 76/76 (100%) 83% (65/78)
UrlRule.php 11 → 12 58/60 (97%) → 59/60 (98%) 84% (69/82)

UrlRule L271 is dead code: CREATE_STATUS_PARSING_ONLY branch is unreachable because createRules() doesn't create a key in $this->rules when all actions are filtered, but createUrl() accesses $this->rules[$urlName] without isset check - crashes before reaching L271.

Changelog not required, because no source files changed.

@WarLikeLaux WarLikeLaux changed the title Add tests for REST classes Add unit tests for REST classes Mar 6, 2026
@codecov
Copy link

codecov bot commented Mar 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.03%. Comparing base (068c5a4) to head (3440f73).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@             Coverage Diff              @@
##             master   #20783      +/-   ##
============================================
+ Coverage     78.62%   79.03%   +0.41%     
  Complexity    11566    11566              
============================================
  Files           376      376              
  Lines         30748    30748              
============================================
+ Hits          24176    24303     +127     
+ Misses         6572     6445     -127     

☔ 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