102 lines
3.1 KiB
PHP
102 lines
3.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Framework\Cache\Cache;
|
|
use App\Framework\Cache\CacheKey;
|
|
use App\Framework\Cache\Driver\InMemoryCache;
|
|
use App\Framework\Cache\GeneralCache;
|
|
use App\Framework\Serializer\Php\PhpSerializer;
|
|
use App\Framework\Cache\Warming\Strategies\CriticalPathWarmingStrategy;
|
|
use App\Framework\Cache\Warming\ValueObjects\WarmupPriority;
|
|
use App\Framework\Router\CompiledRoutes;
|
|
use App\Framework\Config\Environment;
|
|
|
|
describe('CriticalPathWarmingStrategy', function () {
|
|
beforeEach(function () {
|
|
// Use real instances instead of mocks (final classes can't be mocked)
|
|
$inMemoryCache = new InMemoryCache();
|
|
$serializer = new PhpSerializer();
|
|
$this->cache = new GeneralCache($inMemoryCache, $serializer);
|
|
|
|
$this->compiledRoutes = new CompiledRoutes(
|
|
staticRoutes: [
|
|
'GET' => [
|
|
'default' => [
|
|
'/home' => null,
|
|
'/about' => null,
|
|
]
|
|
]
|
|
],
|
|
dynamicPatterns: [
|
|
'GET' => [
|
|
'default' => null
|
|
]
|
|
],
|
|
namedRoutes: []
|
|
);
|
|
|
|
$this->environment = new Environment([
|
|
'APP_ENV' => 'testing',
|
|
'APP_DEBUG' => 'true',
|
|
]);
|
|
});
|
|
|
|
it('has correct name', function () {
|
|
$strategy = new CriticalPathWarmingStrategy(
|
|
cache: $this->cache,
|
|
compiledRoutes: $this->compiledRoutes,
|
|
environment: $this->environment
|
|
);
|
|
|
|
expect($strategy->getName())->toBe('critical_path');
|
|
});
|
|
|
|
it('has critical priority', function () {
|
|
$strategy = new CriticalPathWarmingStrategy(
|
|
cache: $this->cache,
|
|
compiledRoutes: $this->compiledRoutes,
|
|
environment: $this->environment
|
|
);
|
|
|
|
expect($strategy->getPriority())->toBe(WarmupPriority::CRITICAL->value);
|
|
});
|
|
|
|
it('always runs', function () {
|
|
$strategy = new CriticalPathWarmingStrategy(
|
|
cache: $this->cache,
|
|
compiledRoutes: $this->compiledRoutes,
|
|
environment: $this->environment
|
|
);
|
|
|
|
expect($strategy->shouldRun())->toBeTrue();
|
|
});
|
|
|
|
it('warms routes cache', function () {
|
|
$strategy = new CriticalPathWarmingStrategy(
|
|
cache: $this->cache,
|
|
compiledRoutes: $this->compiledRoutes,
|
|
environment: $this->environment
|
|
);
|
|
|
|
$result = $strategy->warmup();
|
|
|
|
// Strategy warms 4 items: routes_static, routes_stats, framework_config, env_variables
|
|
expect($result->itemsWarmed)->toBe(4);
|
|
expect($result->itemsFailed)->toBe(0);
|
|
});
|
|
|
|
it('estimates reasonable duration', function () {
|
|
$strategy = new CriticalPathWarmingStrategy(
|
|
cache: $this->cache,
|
|
compiledRoutes: $this->compiledRoutes,
|
|
environment: $this->environment
|
|
);
|
|
|
|
$duration = $strategy->getEstimatedDuration();
|
|
|
|
expect($duration)->toBeGreaterThan(0);
|
|
expect($duration)->toBeLessThan(30); // Should be fast (< 30 seconds)
|
|
});
|
|
});
|