- Add comprehensive health check system with multiple endpoints - Add Prometheus metrics endpoint - Add production logging configurations (5 strategies) - Add complete deployment documentation suite: * QUICKSTART.md - 30-minute deployment guide * DEPLOYMENT_CHECKLIST.md - Printable verification checklist * DEPLOYMENT_WORKFLOW.md - Complete deployment lifecycle * PRODUCTION_DEPLOYMENT.md - Comprehensive technical reference * production-logging.md - Logging configuration guide * ANSIBLE_DEPLOYMENT.md - Infrastructure as Code automation * README.md - Navigation hub * DEPLOYMENT_SUMMARY.md - Executive summary - Add deployment scripts and automation - Add DEPLOYMENT_PLAN.md - Concrete plan for immediate deployment - Update README with production-ready features All production infrastructure is now complete and ready for deployment.
139 lines
4.5 KiB
PHP
139 lines
4.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Framework\Http\Request;
|
|
use App\Framework\Router\AdminRoutes;
|
|
use App\Framework\Router\ApiRoutes;
|
|
use App\Framework\Router\CompiledRoutes;
|
|
use App\Framework\Router\UrlGenerator;
|
|
use App\Framework\Router\WebRoutes;
|
|
|
|
describe('UrlGenerator with Route Enums', function () {
|
|
beforeEach(function () {
|
|
$this->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();
|
|
});
|
|
});
|
|
});
|