mockRequest = mock(Request::class); $this->mockCompiledRoutes = mock(CompiledRoutes::class); $this->urlGenerator = new UrlGenerator($this->mockRequest, $this->mockCompiledRoutes); }); describe('route generation with enums', function () { it('generates URLs using WebRoutes enum', function () { $mockRoute = (object) ['path' => '/']; $this->mockCompiledRoutes->shouldReceive('getNamedRoute') ->once() ->with('home') ->andReturn($mockRoute); $result = $this->urlGenerator->route(WebRoutes::HOME); expect($result)->toBe('/'); }); it('generates URLs using ApiRoutes enum', function () { $mockRoute = (object) ['path' => '/api/users']; $this->mockCompiledRoutes->shouldReceive('getNamedRoute') ->once() ->with('api_users_list') ->andReturn($mockRoute); $result = $this->urlGenerator->route(ApiRoutes::USERS_LIST); expect($result)->toBe('/api/users'); }); it('generates URLs using AdminRoutes enum', function () { $mockRoute = (object) ['path' => '/admin']; $this->mockCompiledRoutes->shouldReceive('getNamedRoute') ->once() ->with('admin.dashboard') ->andReturn($mockRoute); $result = $this->urlGenerator->route(AdminRoutes::DASHBOARD); expect($result)->toBe('/admin'); }); it('generates URLs with parameters using enum', function () { $mockRoute = (object) ['path' => '/api/users/{id}']; $this->mockCompiledRoutes->shouldReceive('getNamedRoute') ->once() ->with('api_users_show') ->andReturn($mockRoute); $result = $this->urlGenerator->route(ApiRoutes::USERS_SHOW, ['id' => 123]); expect($result)->toBe('/api/users/123'); }); }); describe('backward compatibility', function () { it('still works with string route names', function () { $mockRoute = (object) ['path' => '/legacy']; $this->mockCompiledRoutes->shouldReceive('getNamedRoute') ->once() ->with('legacy_route') ->andReturn($mockRoute); $result = $this->urlGenerator->route('legacy_route'); expect($result)->toBe('/legacy'); }); }); describe('absolute URL generation', function () { it('generates absolute URLs using enums', function () { $mockRoute = (object) ['path' => '/']; $this->mockCompiledRoutes->shouldReceive('getNamedRoute') ->once() ->with('home') ->andReturn($mockRoute); $this->mockRequest->server = mock(); $this->mockRequest->server->shouldReceive('isHttps')->andReturn(true); $this->mockRequest->server->shouldReceive('getHttpHost')->andReturn('example.com'); $result = $this->urlGenerator->absoluteRoute(WebRoutes::HOME); expect($result)->toBe('https://example.com/'); }); }); describe('current route checking', function () { it('checks current route using enum', function () { $mockRoute = (object) ['path' => '/']; $this->mockCompiledRoutes->shouldReceive('getNamedRoute') ->once() ->with('home') ->andReturn($mockRoute); $this->mockRequest->path = '/'; $result = $this->urlGenerator->isCurrentRoute(WebRoutes::HOME); expect($result)->toBeTrue(); }); it('returns false for non-matching enum route', function () { $mockRoute = (object) ['path' => '/admin']; $this->mockCompiledRoutes->shouldReceive('getNamedRoute') ->once() ->with('admin.dashboard') ->andReturn($mockRoute); $this->mockRequest->path = '/'; $result = $this->urlGenerator->isCurrentRoute(AdminRoutes::DASHBOARD); expect($result)->toBeFalse(); }); }); });