cache = Mockery::mock(Cache::class); $this->compiledRoutes = Mockery::mock(CompiledRoutes::class); $this->environment = Mockery::mock(Environment::class); }); afterEach(function () { Mockery::close(); }); 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 () { $this->compiledRoutes->shouldReceive('getStaticRoutes') ->once() ->andReturn(['route1' => 'handler1']); $this->compiledRoutes->shouldReceive('getDynamicRoutes') ->once() ->andReturn(['route2' => 'handler2']); $this->cache->shouldReceive('set') ->atLeast(2) // routes_static + routes_dynamic + config + env ->andReturn(true); $strategy = new CriticalPathWarmingStrategy( cache: $this->cache, compiledRoutes: $this->compiledRoutes, environment: $this->environment ); $result = $strategy->warmup(); expect($result->isSuccess())->toBeTrue(); expect($result->itemsWarmed)->toBeGreaterThan(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) }); it('handles cache failures gracefully', function () { $this->compiledRoutes->shouldReceive('getStaticRoutes') ->andReturn(['route1' => 'handler1']); $this->compiledRoutes->shouldReceive('getDynamicRoutes') ->andReturn(['route2' => 'handler2']); $this->cache->shouldReceive('set') ->andReturn(false); // Simulate cache failure $strategy = new CriticalPathWarmingStrategy( cache: $this->cache, compiledRoutes: $this->compiledRoutes, environment: $this->environment ); $result = $strategy->warmup(); // Should complete even with failures expect($result->itemsFailed)->toBeGreaterThan(0); }); });