Some checks failed
🚀 Build & Deploy Image / Determine Build Necessity (push) Failing after 10m14s
🚀 Build & Deploy Image / Build Runtime Base Image (push) Has been skipped
🚀 Build & Deploy Image / Build Docker Image (push) Has been skipped
🚀 Build & Deploy Image / Run Tests & Quality Checks (push) Has been skipped
🚀 Build & Deploy Image / Auto-deploy to Staging (push) Has been skipped
🚀 Build & Deploy Image / Auto-deploy to Production (push) Has been skipped
Security Vulnerability Scan / Check for Dependency Changes (push) Failing after 11m25s
Security Vulnerability Scan / Composer Security Audit (push) Has been cancelled
- Remove middleware reference from Gitea Traefik labels (caused routing issues) - Optimize Gitea connection pool settings (MAX_IDLE_CONNS=30, authentication_timeout=180s) - Add explicit service reference in Traefik labels - Fix intermittent 504 timeouts by improving PostgreSQL connection handling Fixes Gitea unreachability via git.michaelschiemer.de
171 lines
5.0 KiB
PHP
171 lines
5.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Framework\String\ValueObjects\{
|
|
AlphanumericString,
|
|
NumericString,
|
|
HexadecimalString,
|
|
PrintableString
|
|
};
|
|
|
|
describe('AlphanumericString', function () {
|
|
it('creates from valid alphanumeric string', function () {
|
|
$str = AlphanumericString::fromString('abc123');
|
|
|
|
expect($str->value)->toBe('abc123');
|
|
});
|
|
|
|
it('rejects non-alphanumeric strings', function () {
|
|
AlphanumericString::fromString('abc-123');
|
|
})->throws(InvalidArgumentException::class, 'alphanumeric');
|
|
|
|
it('rejects empty strings', function () {
|
|
AlphanumericString::fromString('');
|
|
})->throws(InvalidArgumentException::class);
|
|
|
|
it('converts to TypedString', function () {
|
|
$str = AlphanumericString::fromString('test123');
|
|
$typed = $str->toTypedString();
|
|
|
|
expect($typed->value)->toBe('test123');
|
|
expect($typed->isAlphanumeric())->toBeTrue();
|
|
});
|
|
|
|
it('checks equality', function () {
|
|
$str1 = AlphanumericString::fromString('abc123');
|
|
$str2 = AlphanumericString::fromString('abc123');
|
|
$str3 = AlphanumericString::fromString('xyz789');
|
|
|
|
expect($str1->equals($str2))->toBeTrue();
|
|
expect($str1->equals($str3))->toBeFalse();
|
|
});
|
|
|
|
it('converts to string', function () {
|
|
$str = AlphanumericString::fromString('test123');
|
|
|
|
expect((string) $str)->toBe('test123');
|
|
});
|
|
});
|
|
|
|
describe('NumericString', function () {
|
|
it('creates from valid numeric string', function () {
|
|
$str = NumericString::fromString('12345');
|
|
|
|
expect($str->value)->toBe('12345');
|
|
});
|
|
|
|
it('rejects non-numeric strings', function () {
|
|
NumericString::fromString('12.34');
|
|
})->throws(InvalidArgumentException::class, 'digits');
|
|
|
|
it('rejects alphanumeric strings', function () {
|
|
NumericString::fromString('123abc');
|
|
})->throws(InvalidArgumentException::class);
|
|
|
|
it('rejects empty strings', function () {
|
|
NumericString::fromString('');
|
|
})->throws(InvalidArgumentException::class);
|
|
|
|
it('converts to integer', function () {
|
|
$str = NumericString::fromString('12345');
|
|
|
|
expect($str->toInt())->toBe(12345);
|
|
});
|
|
|
|
it('converts to float', function () {
|
|
$str = NumericString::fromString('12345');
|
|
|
|
expect($str->toFloat())->toBe(12345.0);
|
|
});
|
|
|
|
it('handles large numbers', function () {
|
|
$str = NumericString::fromString('999999999');
|
|
|
|
expect($str->toInt())->toBe(999999999);
|
|
});
|
|
});
|
|
|
|
describe('HexadecimalString', function () {
|
|
it('creates from valid hexadecimal string', function () {
|
|
$str = HexadecimalString::fromString('deadbeef');
|
|
|
|
expect($str->value)->toBe('deadbeef');
|
|
});
|
|
|
|
it('accepts uppercase hexadecimal', function () {
|
|
$str = HexadecimalString::fromString('DEADBEEF');
|
|
|
|
expect($str->value)->toBe('DEADBEEF');
|
|
});
|
|
|
|
it('accepts mixed case hexadecimal', function () {
|
|
$str = HexadecimalString::fromString('DeAdBeEf');
|
|
|
|
expect($str->value)->toBe('DeAdBeEf');
|
|
});
|
|
|
|
it('rejects non-hexadecimal strings', function () {
|
|
HexadecimalString::fromString('ghijk');
|
|
})->throws(InvalidArgumentException::class, 'hexadecimal');
|
|
|
|
it('rejects empty strings', function () {
|
|
HexadecimalString::fromString('');
|
|
})->throws(InvalidArgumentException::class);
|
|
|
|
it('converts to binary', function () {
|
|
$str = HexadecimalString::fromString('48656c6c6f'); // "Hello"
|
|
$binary = $str->toBinary();
|
|
|
|
expect($binary)->toBe('Hello');
|
|
});
|
|
|
|
it('converts to integer', function () {
|
|
$str = HexadecimalString::fromString('ff');
|
|
|
|
expect($str->toInt())->toBe(255);
|
|
});
|
|
|
|
it('handles long hexadecimal strings', function () {
|
|
$str = HexadecimalString::fromString('0123456789abcdef');
|
|
|
|
expect($str->toInt())->toBe(81985529216486895);
|
|
});
|
|
});
|
|
|
|
describe('PrintableString', function () {
|
|
it('creates from valid printable string', function () {
|
|
$str = PrintableString::fromString('Hello World!');
|
|
|
|
expect($str->value)->toBe('Hello World!');
|
|
});
|
|
|
|
it('accepts strings with whitespace', function () {
|
|
$str = PrintableString::fromString("Hello\nWorld\tTest");
|
|
|
|
expect($str->value)->toContain('Hello');
|
|
});
|
|
|
|
it('rejects strings with control characters', function () {
|
|
PrintableString::fromString("Hello\x00World");
|
|
})->throws(InvalidArgumentException::class, 'printable');
|
|
|
|
it('rejects empty strings', function () {
|
|
PrintableString::fromString('');
|
|
})->throws(InvalidArgumentException::class);
|
|
|
|
it('accepts special characters', function () {
|
|
$str = PrintableString::fromString('!@#$%^&*()_+-=[]{}|;:,.<>?');
|
|
|
|
expect($str->value)->toContain('!@#$');
|
|
});
|
|
|
|
it('converts to TypedString', function () {
|
|
$str = PrintableString::fromString('Test String');
|
|
$typed = $str->toTypedString();
|
|
|
|
expect($typed->value)->toBe('Test String');
|
|
expect($typed->isPrintable())->toBeTrue();
|
|
});
|
|
});
|