- 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.
65 lines
2.2 KiB
PHP
65 lines
2.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Domain\SmartLink\Services\ShortCodeGenerator;
|
|
use App\Domain\SmartLink\ValueObjects\ShortCode;
|
|
use Tests\Support\InMemorySmartLinkRepository;
|
|
|
|
describe('ShortCodeGenerator', function () {
|
|
beforeEach(function () {
|
|
$this->repository = new InMemorySmartLinkRepository();
|
|
$this->generator = new ShortCodeGenerator($this->repository);
|
|
});
|
|
|
|
it('generates unique short code', function () {
|
|
$shortCode = $this->generator->generateUnique();
|
|
|
|
expect($shortCode)->toBeInstanceOf(ShortCode::class);
|
|
expect($shortCode->toString())->toHaveLength(6);
|
|
});
|
|
|
|
it('generates alphanumeric codes', function () {
|
|
$shortCode = $this->generator->generateUnique();
|
|
|
|
expect($shortCode->toString())->toMatch('/^[a-zA-Z0-9]{6}$/');
|
|
});
|
|
|
|
it('generates different codes on multiple calls', function () {
|
|
$codes = [];
|
|
|
|
for ($i = 0; $i < 5; $i++) {
|
|
$codes[] = $this->generator->generateUnique()->toString();
|
|
}
|
|
|
|
$uniqueCodes = array_unique($codes);
|
|
expect(count($uniqueCodes))->toBeGreaterThan(3);
|
|
});
|
|
|
|
it('generates code with custom length', function () {
|
|
$shortCode = $this->generator->generateUnique(length: 8);
|
|
|
|
expect($shortCode->toString())->toHaveLength(8);
|
|
});
|
|
|
|
it('returns different code when collision detected', function () {
|
|
// Generate a code and add it to repository
|
|
$firstCode = $this->generator->generateUnique();
|
|
|
|
// Manually add the code to repository to simulate it exists
|
|
$link = \App\Domain\SmartLink\Entities\SmartLink::create(
|
|
clock: new \App\Framework\DateTime\SystemClock(),
|
|
shortCode: $firstCode,
|
|
type: \App\Domain\SmartLink\Enums\LinkType::RELEASE,
|
|
title: \App\Domain\SmartLink\ValueObjects\LinkTitle::fromString('Test')
|
|
);
|
|
$this->repository->save($link);
|
|
|
|
// Generate another code - should be different
|
|
$secondCode = $this->generator->generateUnique();
|
|
|
|
expect($this->repository->existsShortCode($firstCode))->toBeTrue();
|
|
expect($secondCode)->toBeInstanceOf(ShortCode::class);
|
|
});
|
|
});
|