- Add phpunit/phpunit ^13.2, symfony/browser-kit and symfony/css-selector to require-dev, plus the autoload-dev mapping for App\Tests- Add phpunit.dist.xml (strict deprecation/notice/warning failures, APP_ENV=test forced) and .env.test / bin/phpunit / tests/bootstrap.php from the PHPUnit recipe - Add tests/Support/TotpTestHelper providing a deterministic TOTP fixture, frozen clock and ConfigBag/cache-pool helpers - Add 121 unit tests covering Clock, ConfigBag, Data/Payload, Enum/Scope, MonitorCacheKeys, PersistCache, Utilities, all five Traits and the three Service managers (BackupCode, Domain, Login) - Fix LoginManagerTest nonce lookups to use makeCacheKey() so the cache key matches the one the manager actually reads/writes - Gitignore bin/.phpunit.result.cache
32 lines
970 B
PHP
32 lines
970 B
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Tests\Unit\Trait;
|
|
|
|
use App\Trait\StringTrait;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
final class StringTraitTest extends TestCase {
|
|
use StringTrait;
|
|
|
|
public function testMakeCacheKeySanitizesInvalidChars(): void {
|
|
self::assertSame('hello_world', $this->makeCacheKey('hello world'));
|
|
self::assertSame('hello_world', $this->makeCacheKey('hello!world'));
|
|
self::assertSame('a_b_c_d', $this->makeCacheKey('a/b@c#d'));
|
|
}
|
|
|
|
public function testMakeCacheKeyPreservesValidChars(): void {
|
|
self::assertSame('ABC_123.abc', $this->makeCacheKey('ABC_123.abc'));
|
|
}
|
|
|
|
public function testMakeCacheKeyTruncatesLongNames(): void {
|
|
$long = str_repeat('a', 300);
|
|
$result = $this->makeCacheKey($long);
|
|
self::assertSame(128, mb_strlen($result));
|
|
}
|
|
|
|
public function testMakeCacheKeyEmptyString(): void {
|
|
self::assertSame('', $this->makeCacheKey(''));
|
|
}
|
|
}
|