Files
michaelschiemer/tests/Cache/Warming/CriticalPathWarmingStrategyTest.php
Michael Schiemer fc3d7e6357 feat(Production): Complete production deployment infrastructure
- 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.
2025-10-25 19:18:37 +02:00

113 lines
3.5 KiB
PHP

<?php
declare(strict_types=1);
use App\Framework\Cache\Cache;
use App\Framework\Cache\CacheKey;
use App\Framework\Cache\Warming\Strategies\CriticalPathWarmingStrategy;
use App\Framework\Cache\Warming\ValueObjects\WarmupPriority;
use App\Framework\Core\CompiledRoutes;
use App\Framework\Config\Environment;
describe('CriticalPathWarmingStrategy', function () {
beforeEach(function () {
$this->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);
});
});