Skip to content

Remove restrictions from prependMiddleware() and middleware() methods#279

Open
klsoft-web wants to merge 5 commits intoyiisoft:masterfrom
klsoft-web:improve-router
Open

Remove restrictions from prependMiddleware() and middleware() methods#279
klsoft-web wants to merge 5 commits intoyiisoft:masterfrom
klsoft-web:improve-router

Conversation

@klsoft-web
Copy link

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

@codecov
Copy link

codecov bot commented Feb 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 72.72%. Comparing base (7b4d133) to head (beab738).
⚠️ Report is 22 commits behind head on master.

Additional details and impacted files
@@              Coverage Diff              @@
##             master     #279       +/-   ##
=============================================
- Coverage     97.40%   72.72%   -24.68%     
+ Complexity      181      178        -3     
=============================================
  Files            16       16               
  Lines           577      550       -27     
=============================================
- Hits            562      400      -162     
- Misses           15      150      +135     

☔ View full report in Codecov by Sentry.
📢 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.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR removes ordering restrictions around adding middleware in Route and Group, aligning behavior with issue #277 so middleware can be added both before and after actions/routes.

Changes:

  • Allow Route::middleware() to be called after action() by inserting middleware before the action handler.
  • Allow Route::prependMiddleware() to be called before action() (always prepends).
  • Remove Group ordering restrictions so middleware can be added before/after routes() and vice versa, and update tests/changelog accordingly.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/Route.php Adjusts middleware() behavior to insert before action when action is present; removes prependMiddleware() restriction.
src/Group.php Removes state flags/exceptions that enforced ordering between routes() and middleware methods.
tests/RouteTest.php Replaces exception-based tests with assertions covering new Route middleware ordering behavior.
tests/GroupTest.php Updates tests to reflect relaxed ordering constraints in Group.
CHANGELOG.md Documents enhancement #277.

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

klsoft-web and others added 3 commits February 7, 2026 13:18
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@@ -439,10 +433,12 @@ public function testWithCorsWithNestedGroups2(): void
public function testMiddlewareAfterRoutes(): void
{
$group = Group::create()->routes(Route::get('/info')->action(static fn() => 'info'));
Copy link
Member

Choose a reason for hiding this comment

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

Add middleware before action to check the order of middlewares.

Copy link
Author

Choose a reason for hiding this comment

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

Done

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.

2 participants