[9.x] Breaking change: routes registered before service providers boot
Closed this issue · 0 comments
shengslogar commented
- Testbench Version: 9.0.4
- Laravel Version: 11.0.6
- PHP Version: 8.3.6
- Database Driver & Version: MySQL 8.3.0
Description:
Illuminate\Routing\Router
is macroable, and third-party packages may extend its functionality in the boot()
method of their service provider (e.g. https://laravel.com/docs/11.x/http-client#macros).
In 8.x, defineRoutes
was called after getPackageProviders
. In 9.x, this commit changed that order, which causes router macros to no longer be available when registering routes:
--- $app->make('Illuminate\Foundation\Bootstrap\BootProviders')->bootstrap($app);
if ($this->isRunningTestCase() && static::usesTestingConcern(HandlesRoutes::class)) {
$this->setUpApplicationRoutes($app); // @phpstan-ignore-line
}
+++ $app->make('Illuminate\Foundation\Bootstrap\BootProviders')->bootstrap($app);
Steps To Reproduce:
composer require orchestra/testbench:9
and a package that macros routes, likeglhd/gretel
- Mount the corresponding service provider in
getPackageProviders
(relevant source) defineRoutes
and try to reference the newly-defined macro (->breadcrumb
in this case)
The following error is thrown:
BadMethodCallException: Method Illuminate\Routing\Route::breadcrumb does not exist.
<?php
use Orchestra\Testbench\TestCase;
use Glhd\Gretel\Support\GretelServiceProvider;
class Repro extends TestCase
{
protected function getPackageProviders($app)
{
return [GretelServiceProvider::class];
}
public function defineRoutes($router)
{
$router->get('/profile')
->breadcrumb('Profile'); // `->breadcrumb` fails because its macro hasn't been registered
}
}