Files
michaelschiemer/tests/Framework/Router/ValueObjects/PlaceholderTest.php
Michael Schiemer fc3d7e6357 feat(Production): Complete production deployment infrastructure
- 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.
2025-10-25 19:18:37 +02:00

105 lines
3.8 KiB
PHP

<?php
declare(strict_types=1);
use App\Framework\Router\ValueObjects\Placeholder;
describe('Placeholder', function () {
describe('creation', function () {
it('can be created from string', function () {
$placeholder = Placeholder::fromString('id');
expect($placeholder->getName())->toBe('id');
expect($placeholder->toString())->toBe('{id}');
expect($placeholder->isWildcard())->toBeFalse();
});
it('can be created with type', function () {
$placeholder = Placeholder::typed('id', 'int');
expect($placeholder->getName())->toBe('id');
expect($placeholder->getType())->toBe('int');
expect($placeholder->getPattern())->toBe('(\d+)');
});
it('can be created as wildcard', function () {
$placeholder = Placeholder::wildcard('path');
expect($placeholder->getName())->toBe('path');
expect($placeholder->toString())->toBe('{path*}');
expect($placeholder->isWildcard())->toBeTrue();
expect($placeholder->getPattern())->toBe('(.+?)');
});
it('validates placeholder names', function () {
expect(fn () => Placeholder::fromString(''))
->toThrow(InvalidArgumentException::class);
expect(fn () => Placeholder::fromString('123invalid'))
->toThrow(InvalidArgumentException::class);
expect(fn () => Placeholder::fromString('invalid-name'))
->toThrow(InvalidArgumentException::class);
});
it('accepts valid placeholder names', function () {
$validNames = ['id', 'userId', 'user_id', '_private', 'snake_case'];
foreach ($validNames as $name) {
$placeholder = Placeholder::fromString($name);
expect($placeholder->getName())->toBe($name);
}
});
});
describe('type patterns', function () {
it('provides correct patterns for common types', function () {
$patterns = [
'int' => '(\d+)',
'uuid' => '([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})',
'slug' => '([a-z0-9\-]+)',
'alpha' => '([a-zA-Z]+)',
'alphanumeric' => '([a-zA-Z0-9]+)',
'filename' => '([a-zA-Z0-9._\-]+)',
];
foreach ($patterns as $type => $expectedPattern) {
$placeholder = Placeholder::typed('test', $type);
expect($placeholder->getPattern())->toBe($expectedPattern);
}
});
it('falls back to default pattern for unknown types', function () {
$placeholder = Placeholder::typed('test', 'unknown');
expect($placeholder->getPattern())->toBe('([^/]+)');
});
it('allows custom patterns', function () {
$placeholder = Placeholder::typed('test', 'custom', '([a-z]{3})');
expect($placeholder->getPattern())->toBe('([a-z]{3})');
});
});
describe('string representation', function () {
it('converts to proper placeholder syntax', function () {
$regular = Placeholder::fromString('id');
$wildcard = Placeholder::wildcard('path');
expect($regular->toString())->toBe('{id}');
expect($wildcard->toString())->toBe('{path*}');
});
});
describe('pattern generation', function () {
it('returns correct regex patterns', function () {
$regular = Placeholder::fromString('id');
$wildcard = Placeholder::wildcard('path');
$typed = Placeholder::typed('id', 'int');
expect($regular->getPattern())->toBe('([^/]+)');
expect($wildcard->getPattern())->toBe('(.+?)');
expect($typed->getPattern())->toBe('(\d+)');
});
});
});