Ok - in case anyone is interested in resolving similar issue - I've changed the strategy a little and moved the check to the App\Http\Middleware\VerifyModule middleware - although routes will actually get registered, they will return 404 when someone tries to call them.
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Response;
class VerifyModule
{
public function handle($request, Closure $next, string $module)
{
if (!in_array($module, config('module.active'))) {
return abort(Response::HTTP_NOT_FOUND);
}
return $next($request);
}
}
Then, removed check from within Gallery::routes() method, leaving just route binding, but this time with the middleware
public static function routes(): void
{
app('router')->get('gallery', 'GalleryController@index')
->name('front.gallery')
->middleware('module:App\Components\Module\Gallery');
app('router')->get('gallery/{gallery_slug}', 'GalleryController@show')
->name('front.gallery.show')
->middleware('module:App\Components\Module\Gallery');
}
and my test is now changed to
/**
* @test
*/
public function routes_return_404_if_module_is_disabled()
{
config(['module.active' => []]);
$this->seed();
$this->assertDatabaseMissing('pages', ['module' => Gallery::class]);
$response = $this->get(route('front.gallery'));
$this->assertResponseNotFound($response);
}